Skip to content
Guest
Learn HTML · Course Syllabus Show lessons
Foundations · 8 min read · Beginner

Global Attributes, Classes & IDs

Master global HTML attributes available on every element: id, class, data-*, hidden, inert, title, and boolean attributes.

What you'll learn

  • Use id for unique anchors/labels and class for reusable styling
  • Store custom metadata cleanly using data-* attributes
  • Understand boolean attributes like hidden, disabled, and inert

Global attributes can be placed on any HTML element. Mastering them gives you clean hooks for CSS styling, JavaScript interactivity, and accessibility.

AttributePurposeExample
idUnique identifier on the page (links #anchor, <label for>)id="pricing"
classSpace-separated reusable names for CSS / JSclass="btn primary"
data-*Custom app metadata readable via el.datasetdata-course="html"
hiddenHides the element from view and assistive tech<div hidden>
inertDisables clicks, focus, and screen-reader access for an entire subtree<section inert>
langOverrides language for a specific word or quote<span lang="es">Hola</span>

Boolean Attributes

Attributes like disabled, required, hidden, and inert are boolean attributes. Their presence means true, even writing disabled="false" still disables the button!

✓ Clean Boolean Attributes
<button disabled>Saving...</button>
<input type="checkbox" checked />
✕ Misleading Boolean Values
<!-- Still disabled! -->
<button disabled="false">Click me</button>

Fill-in-the-Blank Exercise

Global Attributes Practice

Give the card a unique id of 'hero', a class of 'featured', and a custom data attribute for track='html'.

<section ="hero" ="featured" ="html">
<h2>Learn HTML</h2>
</section>

Try It Yourself

Toggle the inert attribute on the panel below and try clicking or tabbing into its button!

Explore data-* and inert
Live Result
Console Output

No console output yet. Try calling console.log(...) in JS.

Check Your Understanding

Score: 0 / 1

1. What happens if you write <button disabled="false">Submit</button> in HTML?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind