3.html-attributes.md
Quiz
~/ hackweb.dev
...

HTML Attributes

beginner · updated Sun Aug 09 2026Contribute

How attributes work — src, href, alt, class, id, and boolean attributes.

HTML Attributes

Attributes are extra information attached to an element. They live inside the opening tag and follow name="value".

Anatomy of an attribute

<a href="https://example.com" target="_blank">Visit</a>

Every attribute has a name and a value. The value is usually wrapped in double quotes.

Common attributes

  • href — link destination on <a>
  • src — image or script source
  • alt — descriptive text for images
  • class — a CSS hook (many elements can share it)
  • id — a unique identifier
<img src="cat.png" alt="A cat sleeping" class="photo" id="hero-cat" />

Boolean attributes

Some attributes have no value — their presence alone is the value.

<input type="text" disabled />
<button disabled>Not clickable</button>
<input type="checkbox" checked />
  • disabled — element is not interactive
  • checked — checkbox starts selected
  • required — field must be filled

data-* attributes

Any attribute prefixed with data- is available to JavaScript and never affects rendering.

<button data-tooltip="Save your work">Save</button>