Understanding HTML Tags: The Building Blocks of the Web
Note:
This page is part of the
Complete HTML Guide for Beginners.
Consult the main index for an overview of all topics.
HTML Tags:
NAMING THINGS: HTML TAGS
On our journey to learn HTML, one of the very first things to understand is "tags." It might sound technical, but you'll see the basic idea is quite simple. They are literally the foundation upon which every web page is built.
WHAT IS AN HTML TAG?
Imagine you have to organize a box full of different items. You'd use labels to quickly know what's in each compartment, right? Well, HTML tags do something very similar for the browser (the program you use to browse the internet, like Chrome, Firefox, etc.).
An HTML tag is like a special label written between angle brackets: < and >. These "labels" are instructions that tell the browser: "Hey, this piece of text coming up is a main heading!" or "This is an image," or even "This block of text is a paragraph."
Basically, tags give meaning and structure to the raw content of your page.
ANATOMY OF A TAG: HOW ARE THEY MADE?
Understanding how a tag is structured is crucial. There are two main types:
- Opening and Closing Tags (Most Common):
The vast majority of HTML tags work in pairs:
- An opening tag: Marks the beginning of the content you want to "label."
Example:
<p>(stands for "paragraph"). - A closing tag: Marks the end of that content. It's almost identical to the opening one,
but it has a forward slash / before the name. Example:
</p>.
Everything you write *between* the opening and closing tag is considered part of that element.
<p>This is the text inside a paragraph.</p>Here,
<p>says "start a paragraph,"</p>says "end the paragraph," and the text in the middle is, precisely, the paragraph's content. - An opening tag: Marks the beginning of the content you want to "label."
Example:
- Self-Closing Tags:
Some tags are "single." They don't need to enclose content because they represent elements that
stand on their own. These tags don't have a separate closing tag, but instead "close" themselves, often
by inserting a forward slash
/before the final angle bracket (though in modern HTML5, the trailing slash is often optional for some of them).Common examples are:
<img>: Used to insert images. It doesn't make sense to put "content" inside an image, right? The image *is* the element.<br>: Used to force a line break.
Their typical syntax is:
<img src="images/logo.png" alt="My site logo"> <br>Notice how
<img>doesn't have an</img>. The same goes for<br>.
A USEFUL ANALOGY: LABELED BOXES
We can think of HTML tags like different types of boxes in a warehouse:
- There are large boxes for main content (like an
<h1>for the title). - Medium boxes for paragraphs of text (
<p>). - Special containers for lists (
<ul>or<ol>). - Flat labels for images (
<img>).
Tags are the labels on these boxes, telling the browser (and search engines, screen readers, etc.) what's inside and how it should be semantically interpreted. Attributes are like additional notes written on the label ("This image is located here," "This link goes there").
IMPORTANT: STRUCTURE, NOT APPEARANCE!
This is a fundamental concept to grasp right away: HTML tags define the **structure** and **meaning** of your content. They say *what* a piece of information is (a heading, a list, an image, important text).
They do **NOT** define how that content should look visually (colors, text sizes, margins, fonts, etc.). Sure, browsers have default styles (for example, headings are usually larger and bold), but that's just a starting point.
The "aesthetic" part, the visual appearance, will be handled by another language we'll learn later: the **CSS** (Cascading Style Sheets). For now, let's focus on the correct structure using the right HTML tags for their intended purpose.
A CONCRETE EXAMPLE
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>My Main Title</h1>
<p>This is my first paragraph of text. I'm starting to understand tags!</p>
<p>I can add a <a href="about.html">link</a> to another page.</p>
<img src="sample_photo.jpg" alt="A descriptive photo">
</body>
</html>
Quick explanation:
<!DOCTYPE html>,<html>,<head>,<title>,<body>: Define the basic page structure.<h1>: Labels the text as the main heading.<p>: Labels blocks of text as paragraphs.<a>: Inside a paragraph, labels the word "link" as a hyperlink, and thehrefattribute specifies where it goes.<img>: Inserts an image,srcsays which image to load, andaltdescribes it.
I hope this introduction to tags is helpful! They truly are the fundamental building blocks, and understanding what they are and how they work is the first essential step. See you next time!
Comments
Post a Comment