HTML Attribute

An attribute is extra information added to an HTML tag to configure an element, written as name="value" inside the opening tag. Examples include href on a link and src on an image.

Web

Attributes change how an element behaves or appears — for instance, the href attribute tells a link where to go, and the alt attribute gives an image a text description.

Some common global attributes like id, class, and style can be used on almost any element.

Examples

HTML

<img src="cat.jpg" alt="A sleeping cat" width="200">

Output:

Renders the image cat.jpg at 200px wide, with alt text 'A sleeping cat'.

Learn it in a lesson

See also

Back to the Dictionary