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.
- 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.
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
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