Attributes can be added to the opening tag of an HTML element to change its default behavior or provide additional data about it.

Attributes consist of a name and a value in the format name="value":

<tag name="value"></tag>

So for example, the <img> image element has a mandatory src attribute that contains the image file path/URL:

<img src="codecademy_logo.png" />
  • src is the attribute name.
  • codecademy_logo.png is the attribute value.

HTML elements can have any number of attributes.

The example below displays an image element with three attributes:

<img src="nyan_cat.gif" width="500" height="600" />

These declare its source, width, and height.

Note: Attribute names are not case-sensitive, but it is good practice to write HTML markup in lowercase.


An HTML attribute used to select one or more elements for the application of styling or logic.
Sets the direction of the text of an HTML element.
Used to specify a unique id for an HTML element, which cannot be shared across multiple elements within the same HTML document.
Specifies how an element will be rendered in a web browser.
Contains and can display the specified information about the element it belongs to.
Looking to contribute?

Learn HTML on Codecademy