Attributes

Attributes add extra information to an element, written inside the opening tag as name/value pairs.

Attribute syntax

</> attribute syntax
<a href="https://example.com">Visit site</a>
    ↑attribute name  ↑attribute value

The attribute value is wrapped in quotation marks. Most elements can take several attributes at once, each separated by a space.

Attributes you'll see often

  • id — gives one specific element a unique name on the page.
  • class — labels an element as belonging to a group, often used for styling.
  • src — points to a file, like an image, that an element should load.
  • href — the destination a link points to.
  • alt — a text description of an image, read by screen readers.

Try changing the alt text below, or resizing the image with different width/height values:

Try it yourself
Result
Note: attribute order doesn't matter to the browser — write them in whatever order is easiest to read.