← Back to HTML
08

Global Attributes in HTML: `id`, `class`, `title`, `hidden` and `data-*`

Use global attributes with better judgment so your markup stays clearer, scales more cleanly and connects more safely with styling, scripts and testing.

📘 Theory

Why Global Attributes Matter

They are part of the glue between structure, style and behavior.

1

`id` helps with unique references and in-page anchors. `class` helps reuse styles and behavior across several elements.

2

`data-*` lets you store small bits of domain context near the element that needs them without breaking HTML meaning.

`id` vs `class` Without Confusion

A practical rule works well here: `id` for one, `class` for many.

  • Do not reuse the same `id` on two different elements.
  • Prefer `class` for repeatable styling and shared patterns.
  • Use clear names such as `course-card` or `primary-button`.

🧪 Learn by doing

Example Guided Example: A Reusable Course Block Combine `id`, `class` and `data-*` in one small component.

🏁 Challenges

Challenge Challenge: Fix `id` and `class` Usage Make repeated blocks share a class instead of repeating the same id.

🧰 Resources

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com