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.
| Attribute | Purpose | Example |
|---|---|---|
id | Unique identifier on the page (links #anchor, <label for>) | id="pricing" |
class | Space-separated reusable names for CSS / JS | class="btn primary" |
data-* | Custom app metadata readable via el.dataset | data-course="html" |
hidden | Hides the element from view and assistive tech | <div hidden> |
inert | Disables clicks, focus, and screen-reader access for an entire subtree | <section inert> |
lang | Overrides 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!
<button disabled>Saving...</button>
<input type="checkbox" checked /> <!-- 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!
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
1. What happens if you write <button disabled="false">Submit</button> in HTML?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.