Elements, Tags & Attributes

๐ŸŒ HTML5 ๐ŸŸข Chapter 3 of 37 ๐Ÿ“‚ Phase 02: Syntax & Text ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Opening/Closing Tags ยท Nested Elements ยท Void (Self-Closing) Elements ยท Attribute Syntax ยท Boolean Attributes ยท Universal Global Attributes (id, class, style)
Welcome to Phase 2 (Chapter 3): Elements, Tags & Attributes! In this lesson, we dissect HTML building blocks: opening and closing tags, nested element hierarchies, void (self-closing) elements, attribute key-value formatting, boolean flags, and universal global attributes used across all HTML tags.
1HTML Element Anatomy

An HTML element is formed by an opening tag, attributes, inner content, and a closing tag:

HTML โ€” Element Structure Anatomy โ–ถ Run in HTML Editor
<!-- 
  Opening Tag:  <p class="intro" id="first-para">
  Attributes:   class="intro", id="first-para"
  Inner Text:   Welcome to HTML5 Masterclass
  Closing Tag:  </p>
-->
<p class="intro" id="first-para">Welcome to HTML5 Masterclass</p>
2Void (Self-Closing) Elements

Most HTML elements contain text or nested child nodes. However, Void Elements cannot contain inner text or child nodes, and therefore do not have closing tags:

Void TagFunctionExample Syntax
<img>Embeds an image graphic.<img src="logo.png" alt="Logo">
<input>Renders an interactive form input control.<input type="text" name="user">
<br>Inserts a visual line break inside text.Line 1<br>Line 2
<hr>Inserts a thematic horizontal rule divider.<hr>
<meta>Defines document metadata.<meta charset="UTF-8">
<link>Links external CSS stylesheets or icons.<link rel="stylesheet" href="style.css">
3Standard & Boolean Attributes

Standard Attributes: Key-value pairs written as name="value" (e.g. href="https://example.com" or type="password").

Boolean Attributes: Attributes whose presence implies a true value. You do not need to specify attribute="true":

HTML โ€” Boolean Attributes Syntax โ–ถ Run in HTML Editor
<!-- Correct Boolean Attribute Examples -->
<input type="text" required disabled>
<option value="in" selected>India</option>
<audio controls autoplay muted></audio>
4Universal Global Attributes Reference

Global attributes can be applied to ANY valid HTML5 element:

Global AttributePurposeExample
idUnique identifier for single element targeted by CSS or JS.id="header"
classSpace-separated list of CSS styling classes.class="btn primary"
styleInline CSS style rules.style="color: red;"
titleAdvisory tooltip text shown on mouse hover.title="Click to submit"
hiddenHides element from visual display and screen readers.hidden
tabindexControls keyboard focus tab order.tabindex="0"
langSets element content language.lang="en"
โ“ Frequently Asked Questions (FAQ)

Q1: Can I reuse the same id attribute on multiple elements?

No! An id must be unique within a single HTML document. If you need to target multiple elements with the same styles or JS, use class attributes instead.

Q2: Should I write trailing slashes on void tags like <img />?

In HTML5, trailing slashes like <img /> are optional and ignored by browser parsers. Writing clean <img> is standard HTML5 convention.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on HTML5 Standards ยท Last updated August 2026