Skip to main content

Command Palette

Search for a command to run...

Understanding HTML Tags and Elements

Published
5 min read
Understanding HTML Tags and Elements

Understanding HTML, the Skeleton of the Internet

Every webpage you’ve ever visited started with HTML. Let’s learn the fundamentals of the language that structures the web.

Imagine building a house before you choose the paint colors (CSS) or install the smart home features (JavaScript), you need a solid frame. You need studs, beams, and a foundation to define where the rooms are, where the doors go, and where the roof sits.

In the world of web development, HTML (HyperText Markup Language) is that frame.

HTML is not a programming language it doesn't have logic or do math. It is a markup language. Its entire job is to give structure and meaning to the content on a webpage. It tells the web browser, "This text here is a major heading," "This block is a paragraph," and "This part is a button."

Without HTML, a browser wouldn't know how to display anything; it would just be a giant, unreadable blob of plain text.

The Building Blocks: Tags

So, how do we tell the browser what’s what? We use tags.

Think of HTML tags like labels on moving boxes. If you write "KITCHEN" on a box, movers know exactly where that box belongs.

In HTML, tags act as those labels, wrapping around content to tell the browser how to handle it. Tags almost always come in pairs and are enclosed in angle brackets < >.

The Anatomy of an HTML Tag

Most items on a page are constructed with three parts:

  1. The Opening Tag: Used to start defining the element (e.g., <p>).

  2. The Content: The actual text or media that goes inside.

  3. The Closing Tag: Used to stop defining the element. It looks just like the opening tag but includes a forward slash (e.g., </p>).

Here is a simple example using the paragraph tag:

HTML

<p>This is a sentence that will appear as a paragraph on a webpage.</p>

The Crucial Distinction: Tags vs. Elements

Beginners often use the words "tag" and "element" interchangeably. While related, they mean different things.

  • Tags are just the bits in the brackets (<p> and </p>).

  • an Element is the entire package: the opening tag, the content inside, and the closing tag combined.

Here is a visual breakdown:

      [ Opening Tag ]      [    Content    ]      [ Closing Tag ]
            ↓                    ↓                    ↓
           <h1>           Welcome to My Blog!        </h1>

      └──────────────────────────────────────────────────────┘
                              ↓
                    THIS WHOLE THING IS THE "ELEMENT"

The Exceptions: Self-Closing (Void) Elements

Most elements have content inside them, so they need an opening and closing tag to sandwich that content.

However, some elements don't hold text. For example, an image tag doesn't contain paragraphs; it just points to a picture file. These are called empty elements or self-closing (void) elements.

Because they don't wrap around content, they don't need a closing tag.

Common examples:

  • <img>: Embeds an image.

  • <br>: Creates a line break (like hitting "Enter" on your keyboard).

  • <hr>: Creates a horizontal thematic break (a line across the page).

How Elements Sit: Block-level vs. Inline

Once you start putting elements on a page, you'll notice they behave differently in terms of layout. Understanding this is key to structuring your page correctly. HTML elements generally fall into two categories:

1. Block-level Elements

These elements are "greedy."

  • They always start on a new line.

  • They take up the full width available to them (stretching all the way from left to right across their container).

Think of them as big cardboard boxes stacked on top of each other in a narrow hallway.

Common block elements: <h1> (headings), <p> (paragraphs), <div> (divisions/sections).

2. Inline Elements

These elements are "humble."

  • They do not start on a new line.

  • They only take up as much width as necessary.

Think of them like individual words in a sentence; they sit comfortably next to each other until they run out of space.

Common inline elements: <span> (used to target small bits of text), <a> (links), <b> (bold text).

Visual Layout Diagram:

[ BLOCK ELEMENT (e.g., <h1>) - Takes full width, forces new line ]
-----------------------------------------------------------------

[ BLOCK ELEMENT (e.g., <p>) - Takes full width, forces new line ]
-----------------------------------------------------------------
[Inline (<span>)] [Inline (<a>)] [Inline (<b>)]  <- Sits side-by-side
-----------------------------------------------------------------

Your Starter Toolkit: Common Tags

You can build a surprising amount of a webpage with just a handful of tags. Here are the essentials to get started:

  • <h1> to <h6> (Headings): <h1> is the most important main heading, <h6> is the least important sub-heading.

  • <p> (Paragraph): Used for standard blocks of text.

  • <a href="..."> (Anchor): Used to create links to other pages.

  • <img> (Image): Used to embed pictures.

  • <ul> and <li> (Unordered List): Used to create bullet-point lists.

  • <div> (Division): A generic container used to group other block elements together (crucial later for layout with CSS).

  • <span>: A generic container used to wrap small pieces of text inside a line (useful for styling just one word in a sentence).

Tip: Peek Behind the Curtain

The best way to learn HTML is to see how others use it.

Open any webpage (including this one!), right-click on any part of the page, and select "Inspect" or "Inspect Element." A panel will open at the bottom or side of your browser showing you the actual HTML code that makes up that specific part of the page. Don't worry if it looks complex right now—you're looking at the raw skeleton of the web!

Conclusion

HTML is the foundation of your web development journey. By understanding tags, elements, and how they sit on a page, you have taken the first real step toward building your own corner of the internet. Next up, we'll explore how to make this skeleton look beautiful with CSS!