This lesson provides an overview of HTML attributes. You’ll take a look at some common HTML attributes such as classes and ids. Additionally, this lesson contains examples of setting HTML attributes.
Now that you’re familiar with HTML basics it’s time to dive a bit further in and start working with Attributes. Attributes are additional values that each HTML tag contain. These additional properties add additional configuration to the HTML elements or alter their behavior. Often, attributes are used to provide additional information about an element.
Attributes are defined within the opening tag of an element. An attribute consists of a name and a value. The attribute name is followed by an equals sign (=), then opening quotes (“), then the attribute’s value, and finally closing quotes (“).
Look at the following example of an anchor
Code language: HTML, XML (xml)
<a href="https://digitalharbor.org/">Link to the Digital Harbor Foundation Website</a>
The display text “Link to the Digital Harbor Foundation Website” is placed between the opening
<a> and closing
</a> anchor tags.
There are lots of HTML attributes, but there are some that are far more commonly used than others.
Here is a list of the most commonly used attributes and their purpose:
The class of an element can be set in the following way:
The id of an element can be set in the following way:
Id attributes are even more precise than class attributes, as they target only one unique element at a time. Regardless of which type of element they appear on, id attribute values can only be used once per page.