HTML Attributes: Add Information to Elements
Learn HTML attribute syntax with examples of href, src, alt, id, class and boolean attributes.
Write an attribute
Attributes provide additional information about an element. They are written in the opening tag as a name and, for many attributes, a value.
<a href="https://example.com/">Visit the example site</a>
Quote attribute values, especially when they contain spaces. Quoted values are consistent and easy to read.
Common attributes
hrefgives a link its destination.srcidentifies a resource such as an image file.altprovides alternative text for an image. Use an empty value for decorative images.idgives an element a unique identifier in the document.classassigns one or more reusable class names.
<img src="images/flower.jpg" alt="Pink flower in a garden">
<button type="button" disabled>Unavailable</button>
Boolean attributes
A boolean attribute is true when it is present. For example, adding disabled disables a form control; leaving it out means the control is not disabled by that attribute.
Attributes have element-specific rules. Check that an attribute is supported on the element where you use it.