HTML attributes can be added to the opening tag of an HTML element to change the element’s default behavior or provide additional information about the element.
They consist of a name and a value using the following syntax:
So for example, the
<img> image element has a mandatory
src attribute that contains the image file path/URL:
srcis the attribute name.
codecademy_logo.pngis the attribute value.
All HTML elements can have attributes. Multiple of them, too!
Note: Attribute names are case insensitive, but it is a good practice to keep HTML markup lowercase.
Unique ID Attributes
In HTML, specific and unique
id attributes can be assigned to different elements in order to differentiate between them.
When needed, the
id attributes should begin with a letter and should only contain letters (
a-Z), digits (
0-9), hyphens (
-), underscores (
_), and periods (
In the provided example, we are giving the
<p> paragraph element an unique identifier using the
id attribute and changing the color of the default text using the