ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

HTML5 Tutorial• 5 min read

HTML Elements & Attributes

Nested elements, empty elements, and HTML attributes

An HTML element usually consists of a start tag, content, and an end tag. All HTML elements can have attributes that provide additional information about the element.

Nested HTML Elements

HTML elements can be nested (elements can contain other elements).

All HTML documents consist of nested HTML elements. For example, <body> contains <h1>, which can contain <span> or text.

Nested Elements in Action
<div style="background-color: #f1f5f9; padding: 20px; border-radius: 8px;">
  <h2 style="color: #0f172a;">Coding Bootcamp</h2>
  <p>Learn <strong>web development</strong> from scratch.</p>
  <ul>
    <li>HTML5 Structure</li>
    <li>CSS3 Styling</li>
    <li>Modern JavaScript</li>
  </ul>
</div>

Common HTML Attributes

Attributes provide additional information about HTML elements.

All HTML elements can have attributes, and they are always specified in the start tag.

Attributes usually come in name/value pairs like name="value".

AttributeApplies toPurpose
classGlobalSpecifies one or more class names for CSS styling and JS selection
idGlobalSpecifies a unique id for an element across the entire document
styleGlobalSpecifies an inline CSS style for an element
titleGlobalSpecifies extra information about an element (displayed as tooltip)
src<img>, <script>, <iframe>Specifies the path to the resource to display or load
href<a>, <link>Specifies the hyperlink target URL
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which global HTML attribute assigns a UNIQUE identifier to an element?