Skip to main content
Albero Academy

Attributes

Add information to elements with attributes.

Foundations7 min

Attributes provide extra information about an element, written in the opening tag as name="value" pairs. They configure how an element behaves or where it points.

Common attributes

attributes in action
<a href="https://example.com">A link</a> <!-- href = destination -->
<img src="cat.jpg" alt="A cat" width="300" /> <!-- src, alt, width -->
<p id="intro" class="lead">Intro text</p> <!-- id and class -->
<input type="email" required placeholder="you@example.com" />

id, class & global attributes

Key takeaways

  1. 01Attributes add information to elements as name="value" pairs in the opening tag.
  2. 02Common: href (link target), src/alt (images), type (inputs).
  3. 03Global attributes work anywhere: id (unique), class (reusable, the CSS/JS hook), data-*.
  4. 04Always quote attribute values.

Finished this chapter?

Mark it complete to track your progress through HTML.