Published Aug 4, 2021Updated Mar 17, 2023
Contribute to Docs
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
So for example, the
<img> image element has a mandatory
src attribute that contains the image file path/URL:
<img src="codecademy_logo.png" />
srcis the attribute name.
codecademy_logo.pngis 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 more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn HTML on Codecademy
Front-End EngineerFront-end engineers work closely with designers to make websites beautiful, functional, and fast.
Includes 34 Courses
With Professional Certification