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