šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

HTML Tags & Attributes: Elements of the DOM

Master the foundational syntax of HTML. Understand opening and closing tags, structural nesting, global identity attributes like ID and Class, and required data attributes for void elements.

Narrated Video Summary
data-composition-id="html-html-tags"1280Ɨ720 @ 30fps11 clips5:27 total

Introduction to HTML Elements

Welcome to the Tag Registry. HTML elements are the structural nouns of the web. While tags define the basic skeleton of the content, attributes provide additional identity, behavior, and data properties to those elements. They allow you to attach CSS styles, create interactive links, define image sources, and ensure your site is accessible to assistive technologies. Let's explore how to supercharge your HTML tags.

Anatomy of an Attribute

Every tag can be expanded with attributes, but they follow strict anatomical rules. First, attributes must always be placed inside the opening tag (never the closing tag). Second, they usually come in a 'name="value"' pairing, separated by an equals sign. The value should always be wrapped in quotation marks to prevent the browser from misinterpreting spaces or special characters. Notice how the attribute sits comfortably inside the angle brackets, separated from the tag name by a single space.


<div class="container">
  This is a container
</div>

The Class Attribute

The 'class' attribute is one of the most powerful and commonly used global attributes in web development. It is a 'team player'. You can assign the exact same class name to multiple different elements across your page. This allows CSS to group them together and apply a unified visual style simultaneously. It's incredibly useful for creating consistent UI patterns, like a group of identical warning messages, layout cards, or primary buttons.

The ID Attribute

In stark contrast to the class attribute, the 'id' attribute is a lone wolf. It must be absolutely unique across the entire HTML document. Think of it as a specific, non-replicable fingerprint for a single element. Because it is unique, it is highly prioritized by the browser. Developers use IDs to hook specific elements with JavaScript, to link users directly to a specific section of a webpage via anchor links, or to apply a highly specific, one-off CSS style.

The Title Attribute

The 'title' attribute is another global attribute that works on virtually any HTML element. When you apply it, it provides supplementary, non-critical advisory information. Visually, the browser natively renders this as a tooltip when the user hovers their mouse over the element for a few seconds. Try hovering over the bold text in the preview panel below to see the browser reveal the tooltip text natively without any CSS or JavaScript required.

Element-Specific Attributes: Links

While attributes like 'class', 'id', and 'title' are global (meaning they work on any tag), many attributes are exclusively tied to specific elements to provide necessary functional data. The most famous is the 'href' (Hypertext Reference) attribute, which is required on anchor `<a>` tags. It dictates the specific URL destination the browser will navigate to when the user clicks the element. Without the 'href' attribute, an anchor tag is functionally broken and visually appears as standard text.

Element-Specific Attributes: Images

Void elements (which lack closing tags and inner content) rely entirely on attributes to function. The `<img>` tag absolutely requires the 'src' (source) attribute to tell the browser exactly where to download the visual asset from. If you omit the 'src' attribute, the image element exists in the DOM but displays absolutely nothing on the screen, because the browser has no file path to resolve.

The Alt Attribute

Alongside 'src', images strongly require the 'alt' (alternative text) attribute. Visually, if the image file fails to load due to a broken link or a network error, the browser displays this 'alt' text as a fallback. More critically, screen readers use this exact attribute to verbally describe the image to visually impaired users. Failing to include descriptive alt text on meaningful images is considered a severe violation of web accessibility standards.

Boolean Attributes

Most attributes require a defined value, but 'Boolean' attributes are an exception. They do not need a value because their mere presence inside the tag implies 'true', and their total absence implies 'false'. A classic example is the 'disabled' attribute used on form buttons. By simply appending the word 'disabled' inside the opening tag, the browser instantly applies native visual graying and structurally prevents the user from clicking or interacting with the element.

<div style="font-family: sans-serif; padding: 20px;">
  <button style="padding: 10px 20px; background: #2563eb; color: white; border: none; border-radius: 4px; cursor: pointer;">
    Active Button
  </button>
  
  
  <button disabled style="padding: 10px 20px; background: #94a3b8; color: white; border: none; border-radius: 4px; cursor: not-allowed; margin-left: 10px;">
    Disabled Button
  </button>
</div>

Attribute Mastery Complete

You have successfully mastered the attribute layer of HTML! You understand how to properly structure name-value pairs, utilize classes for CSS grouping, apply IDs for unique JavaScript hooks, deploy Boolean flags to alter states, and integrate core accessibility using element-specific data. Armed with HTML elements as your nouns and attributes as your functional adjectives, you are now fully equipped to construct rich, accessible, and highly customized web documents.

0:00 / 5:27
Scene 1 / 11 — Introduction to HTML Elements
⚔ Total XP: 0|šŸ’» html XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Tags Node

DOM Identity.


šŸš€ LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
šŸŽ“ COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

HTML elements are the structural nouns of the web. While tags define the basic skeleton of the content, attributes provide additional identity, behavior, and data properties to those elements. They allow you to attach CSS styles, create interactive links, define image sources, and ensure your site is accessible.

1Anatomy of an Attribute

Every tag can be expanded with attributes, but they follow strict anatomical rules.

First, attributes must always be placed inside the opening tag (never the closing tag). Second, they usually come in a name="value" pairing, separated by an equals sign. The value should always be wrapped in quotation marks to prevent the browser from misinterpreting spaces or special characters.

āœ•
āˆ’
+
<!-- Correct Attribute Syntax -->
<div class="container">
  Valid Syntax
</div>

<!-- Invalid: Attribute in closing tag -->
<!-- <div>Invalid</div class="container"> -->
localhost:3000
Rule 1: Always in the opening tag.
Rule 2: Values wrapped in quotes.

2The Identity Conflict: Class vs. ID

This is a fundamental distinction in web architecture:

The class attribute is a 'team player'. You assign the exact same class name to multiple elements. This allows CSS to group them together and apply a unified visual style simultaneously (e.g., all buttons with .btn-primary).

The id attribute is a lone wolf. It must be absolutely unique across the entire HTML document. Because it is unique, developers use IDs to hook specific elements with JavaScript or apply highly specific, one-off CSS styles.

āœ•
āˆ’
+
<!-- Reusable Classes -->
<div class="card">User 1</div>
<div class="card">User 2</div>

<!-- Unique Identifier -->
<nav id="main-menu">
  Navigation
</nav>
localhost:3000
.class
Many Elements
#id
One Element

3Required Element Attributes

While attributes like 'class' and 'id' are global, many attributes are exclusively tied to specific elements to provide necessary functional data.

The <a> tag absolutely requires the href attribute to dictate the specific URL destination. The <img> tag absolutely requires the src attribute to tell the browser where to download the visual asset. Void elements (which lack closing tags) rely entirely on these required attributes to function.

āœ•
āˆ’
+
<!-- Mandatory Anchor Data -->
<a href="https://google.com">
  Search Here
</a>

<!-- Mandatory Image Data (Void) -->
<img src="/assets/logo.png" alt="Brand">
localhost:3000
<a> relies on href for routing.
<img> relies on src for media.

4Step-by-Step Breakdown

Introduction to HTML Elements. Welcome to the Tag Registry. HTML elements are the structural nouns of the web. While tags define the basic skeleton of the content, attributes provide additional identity, behavior, and data properties to those elements. They allow you to attach CSS styles, create interactive links, define image sources, and ensure your site is accessible to assistive technologies. Let's explore how to supercharge your HTML tags.

Anatomy of an Attribute. Every tag can be expanded with attributes, but they follow strict anatomical rules. First, attributes must always be placed inside the opening tag (never the closing tag). Second, they usually come in a 'name="value"' pairing, separated by an equals sign. The value should always be wrapped in quotation marks to prevent the browser from misinterpreting spaces or special characters. Notice how the attribute sits comfortably inside the angle brackets, separated from the tag name by a single space.

Checkpoint: HTML parsing rules are incredibly strict regarding where configuration data can be placed. In which specific part of an HTML element must attributes always be located?

  • →Inside the Opening Tag
  • →Inside the Closing Tag
  • →Between the tags

The Class Attribute. The 'class' attribute is one of the most powerful and commonly used global attributes in web development. It is a 'team player'. You can assign the exact same class name to multiple different elements across your page. This allows CSS to group them together and apply a unified visual style simultaneously. It's incredibly useful for creating consistent UI patterns, like a group of identical warning messages, layout cards, or primary buttons.

The ID Attribute. In stark contrast to the class attribute, the 'id' attribute is a lone wolf. It must be absolutely unique across the entire HTML document. Think of it as a specific, non-replicable fingerprint for a single element. Because it is unique, it is highly prioritized by the browser. Developers use IDs to hook specific elements with JavaScript, to link users directly to a specific section of a webpage via anchor links, or to apply a highly specific, one-off CSS style.

Checkpoint: While classes are used to group elements together, which attribute serves as a unique fingerprint and must never be repeated on the same HTML page?

  • →class
  • →id
  • →name
  • →key

The Title Attribute. The 'title' attribute is another global attribute that works on virtually any HTML element. When you apply it, it provides supplementary, non-critical advisory information. Visually, the browser natively renders this as a tooltip when the user hovers their mouse over the element for a few seconds. Try hovering over the bold text in the preview panel below to see the browser reveal the tooltip text natively without any CSS or JavaScript required.

Element-Specific Attributes: Links. While attributes like 'class', 'id', and 'title' are global (meaning they work on any tag), many attributes are exclusively tied to specific elements to provide necessary functional data. The most famous is the 'href' (Hypertext Reference) attribute, which is required on anchor <a> tags. It dictates the specific URL destination the browser will navigate to when the user clicks the element. Without the 'href' attribute, an anchor tag is functionally broken and visually appears as standard text.

Element-Specific Attributes: Images. Void elements (which lack closing tags and inner content) rely entirely on attributes to function. The <img> tag absolutely requires the 'src' (source) attribute to tell the browser exactly where to download the visual asset from. If you omit the 'src' attribute, the image element exists in the DOM but displays absolutely nothing on the screen, because the browser has no file path to resolve.

The Alt Attribute. Alongside 'src', images strongly require the 'alt' (alternative text) attribute. Visually, if the image file fails to load due to a broken link or a network error, the browser displays this 'alt' text as a fallback. More critically, screen readers use this exact attribute to verbally describe the image to visually impaired users. Failing to include descriptive alt text on meaningful images is considered a severe violation of web accessibility standards.

Checkpoint: Inclusivity and accessibility are non-negotiable in modern web development. Which specific attribute is absolutely mandatory for <img> tags to ensure their visual content can be described by screen readers?

  • →src
  • →title
  • →alt
  • →desc

Boolean Attributes. Most attributes require a defined value, but 'Boolean' attributes are an exception. They do not need a value because their mere presence inside the tag implies 'true', and their total absence implies 'false'. A classic example is the 'disabled' attribute used on form buttons. By simply appending the word 'disabled' inside the opening tag, the browser instantly applies native visual graying and structurally prevents the user from clicking or interacting with the element.

Attribute Mastery Complete. You have successfully mastered the attribute layer of HTML! You understand how to properly structure name-value pairs, utilize classes for CSS grouping, apply IDs for unique JavaScript hooks, deploy Boolean flags to alter states, and integrate core accessibility using element-specific data. Armed with HTML elements as your nouns and attributes as your functional adjectives, you are now fully equipped to construct rich, accessible, and highly customized web documents.

Combine The Basic Tags. A minimal real page mixes a heading, a paragraph, and a link.

Level Up šŸš€

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1Alt Text Is Not Optional Metadata

The `alt` attribute on `<img>` is announced by screen readers as the image's entire content. Omit it and assistive tech falls back to reading the raw filename (like 'IMG_4821.jpg'), which is meaningless. Purely decorative images should use `alt=""` so screen readers skip them entirely instead of announcing noise.

<img src="chart.png" alt="Quarterly revenue chart, up 24% year over year">

2Duplicate IDs Silently Break Assistive Tech

The `id` attribute must be unique document-wide. When it isn't, `label[for]` bindings and `aria-labelledby`/`aria-describedby` references resolve to only the first matching element in the DOM, disconnecting every later duplicate from its accessible name without any visible error.

SEO Implications

  • 1

    Alt Attributes Drive Image Search Ranking

    Google Images indexes the `alt` attribute as the primary textual description of an image's content. Missing alt text makes an image effectively unrankable in image search, while keyword-stuffed alt text (e.g. 'buy cheap shoes shoes discount shoes') is treated as spam and can suppress the whole page.

  • 2

    The title Attribute Is Not the <title> Tag

    Developers frequently confuse the element-level `title` attribute (a hover tooltip with near-zero SEO weight) with the document `<title>` tag, which is one of the strongest on-page ranking signals. Spending effort writing rich `title="..."` tooltips on every link does nothing for rankings.

Best Practices

Always Quote Attribute Values

An unquoted value breaks the instant it contains a space: `<div class=nav bar>` parses `bar` as a second, bogus attribute rather than part of the class value. Wrap every attribute value in double quotes even for single-word values.

<div class="nav-bar">

Use data-* for Custom Data, Not Invented Attributes

Don't invent non-standard attributes like `active="true"` on a `<div>` — HTML validators flag them and browsers ignore them for anything but styling hooks via `[active]`. The reserved `data-*` prefix is guaranteed to never collide with a future spec attribute.

<div data-user-id="482" data-status="active"></div>

Frequent Bugs

THE BUG

Setting `disabled="false"` on a button still disables it.

THE FIX

Boolean attributes in HTML are true by mere presence — the string value is ignored entirely. To conditionally enable an element, omit the attribute completely (e.g. via template logic) rather than assigning it the string 'false'.

THE BUG

`document.getElementById('nav')` returns the wrong element after a component was duplicated.

THE FIX

Two elements share the same `id`. `getElementById` and CSS `#id` selectors always resolve to the first match in document order — rename the duplicate to a unique id, and use `class` for anything meant to repeat.

Real-World Examples

Product Grid with Shared Class and Unique Anchor

An e-commerce grid applies the same `.product-card` class to hundreds of repeating items for shared styling, while a single `id` anchors a 'jump to featured item' deep link, and `alt` makes each product image both accessible and indexable.

<section id="featured-product" class="product-card">
  <img src="/img/sneaker-01.jpg" alt="Red running sneaker, side profile">
  <h3 class="product-card__title">Trail Runner X</h3>
</section>
<section class="product-card">
  <img src="/img/sneaker-02.jpg" alt="Blue trail sneaker, side profile">
</section>

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Missing closing tags

<!-- Wrong --> <div> <p>Some text </div> <!-- Correct --> <div> <p>Some text</p> </div>

The Solution //

Always ensure that every opening tag has a corresponding closing tag, unless it is a self-closing element like <img> or <br>.

The Error //

Using unquoted attributes

<!-- Wrong --> <div class=container id=main> <!-- Correct --> <div class="container" id="main">

The Solution //

While HTML5 permits unquoted attributes in some cases, it's a best practice to always wrap attribute values in double quotes.

Lesson Glossary

[01]Attribute

Special words used inside the opening tag to control the element's behavior or identity.

Code Preview
key='value'

[02]Class

An attribute used to group multiple elements together for styling.

Code Preview
class='shared'

[03]ID

An attribute that must be unique to a single element on a page.

Code Preview
id='unique'

[04]src

Source. Specifies the URL of the media file (image, video, etc.).

Code Preview
src='path/to/file'

[05]alt

Alternative text. Describes an image for screen readers or if the image fails to load.

Code Preview
alt='description'

[06]Global Attribute

Attributes that can be used on any HTML element (e.g., id, class, title, lang).

Code Preview
title='tooltip'

Continue Learning