HTML Tags & Attributes

Discover how to give your website structure and meaning with the essential building blocks of the web.

Lesson ProgressStep 1 of 8

This is a paragraph.This is a link.

A logo
0 EXP

Welcome! Let's explore the two most fundamental parts of HTML: Tags and Attributes.

Tag vs. Element: What's the Difference?

This is a common point of confusion. Let's clear it up:

  • A Tag is the instruction, enclosed in angle brackets. You have an opening tag (like <p>) and a closing tag (like </p>).
  • An Element is the *entire structure*—the opening tag, the content inside, and the closing tag.

<p>This is the CONTENT.</p>
 ^
 |
This is the OPENING TAG

System Check

In the code `<p>Hello</p>`, what is the `Hello` part called?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🎯
Attribute Ace

Correctly use `src` and `alt` attributes on an `<img>` tag.

📦
Nesting Ninja

Correctly order a set of nested HTML elements.

💨
Void Validator

Prove your knowledge of void (self-closing) elements.

Mission: Display an Image

Write the HTML for an image. It must include the `img` tag and have valid `src` and `alt` attributes. Our AI assistant will provide real-time feedback.

A.D.A. Feedback:

> Awaiting input...

Challenge: Order the Nested Structure

Drag the elements into the correct order to create a validly nested document fragment.

<h3>A Subheading</h3>
<div>
<p>A paragraph inside the div.</p>
</div>
<h2>A Main Heading</h2>

Challenge: Complete the Void Element

Fill in the missing parts of this image element. Remember, void elements don't have closing tags.

<="logo.png"="A logo">

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Display an Image" project for feedback from other Net-Runners.

The Core of the Web: A Deep Dive into HTML Tags & Attributes

If HTML is the skeleton of a webpage, then **tags** are the bones and **attributes** are the joints that give them unique properties and connect them. Understanding the distinction between these two concepts is the single most important foundation for writing HTML.

Think of it this way: a tag tells the browser **what** something is (a car), while attributes describe **how** it should be (a *red* car with a *V8 engine* and license plate *'WEB-123'*).

1. The Anatomy of an HTML Element

People often use "tag" and "element" interchangeably, but they have precise meanings.

  • Opening Tag: The instruction that starts an element, like <p>.
  • Content: The "stuff" inside the tags, like the text "Hello world!".
  • Closing Tag: The instruction that ends an element, marked with a forward slash: </p>.
  • Element: The *entire unit*—opening tag, content, and closing tag.

<-- This whole thing is the ELEMENT -->
<p class="intro">This is the CONTENT.</p>
 ^             ^
 |             |
Opening Tag   Closing Tag
    (with an attribute)
          

2. The Power of Attributes: Configuring Your Elements

Attributes are the real workhorses. They are **always** placed inside the opening tag and provide extra information or functionality. They always come in `name="value"` pairs.

Global Attributes

These can be added to *any* HTML element.

  • id: Provides a **unique** identifier for an element (e.g., id="main-header"). Used for CSS targeting and JavaScript. You can only have *one* of each ID per page.
  • class: Provides a **reusable** identifier (e.g., class="button-primary"). You can use the same class on many elements.
  • style: Used to apply "inline CSS" directly to one element (e.g., style="color: red;"). This is generally discouraged in favor of separate CSS files.
  • title: Provides extra advisory information, which browsers typically show as a tooltip on hover (e.g., title="Click to learn more").
  • lang: Specifies the language of the element's content (e.g., lang="es" for Spanish). Important for accessibility and SEO.

Specific Attributes

These attributes only work on specific elements.

  • href (on <a>): The "hyperlink reference." This specifies the URL the link should point to (e.g., href="https://www.google.com").
  • src (on <img>): The "source." This is the path or URL to the image file (e.g., src="/images/logo.png").
  • alt (on <img>): The "alternative text." This is a description of the image for screen readers and if the image fails to load. **It is critical for accessibility.**
  • action (on <form>): The URL where the form data should be sent.
  • disabled (on <button>, <input>): A **boolean attribute**. Its presence means "true." It grays out the element.

3. Void Elements: The Exceptions to the Rule

Some elements are "void" or "empty" because they cannot have any content inside them. They represent a single "thing." Because they have no content, they **do not have a closing tag**.

Common void elements include:

  • <img src="..." alt="...">
  • <br> (line break)
  • <hr> (thematic break)
  • <input type="...">
  • <link rel="..." href="...">
  • <meta charset="...">

Note: You might see old code with a forward slash (e.g., <br />). This was required in XHTML, but in modern HTML5, it's optional.

4. Nesting: Building the Document Tree

HTML elements are "nested" inside each other to build a hierarchy. The rule is simple: **Last In, First Out (LIFO)**. The last tag you open must be the first tag you close.

✔️ Correct Nesting

<p>
  <strong>This text is bold.</strong>
</p>

<strong> was opened last, so it's closed first.

❌ Incorrect Nesting

<p>
  <strong>This text is broken.
</p></strong>

The tags "cross." This breaks the hierarchy and confuses the browser.

Key Takeaway: Mastering HTML is mastering the relationship between tags and attributes. Use tags to define the *meaning* and *structure* of your content, and use attributes to *configure* its behavior and provide essential metadata.

HTML Tags & Attributes Glossary

Attribute
A property, provided inside the opening tag, that configures an element or provides extra information. It consists of a `name` and a `value` (e.g., `href="page.html"`).
Block-level Element
An element that starts on a new line and takes up the full width available (e.g., `<div>`, `<p>`, `<h1>`).
Boolean Attribute
An attribute that does not need a value. Its presence on the tag means "true." Examples include `disabled`, `checked`, and `readonly`.
Element
The complete HTML structure, consisting of an opening tag, the content, and a closing tag. (e.g., `<p>This is an element.</p>`).
Global Attribute
An attribute that can be legally used on *any* HTML element. Examples include `id`, `class`, `style`, and `title`.
Inline Element
An element that flows within text and does not start on a new line. It only takes up as much width as its content (e.g., `<span>`, `<a>`, `<strong>`).
Nesting
The practice of placing HTML elements inside other HTML elements to create a document hierarchy.
Tag
The instruction, enclosed in angle brackets (`<` and `>`), that marks the beginning or end of an element (e.g., `<p>` or `</p>`).
Void Element
An element that cannot contain content and therefore does not have a closing tag. Also known as a self-closing or empty element (e.g., `<img>`, `<br>`, `<input>`).

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!