An HTML element can have optional attributes. An attribute is used to set the behaviour of an HTML element. It has two parts, a name and a value, and is added within the opening tag of an element.
For example, let us look at the title attribute. The title attribute is used to set the text which is displayed when the mouse is hovered over an HTML element.
In the code example given below, we add this attribute to an <h1>
element with the value as The web loves HTML. So, take your mouse cursor over the heading text in the result and within a second, you'll see the title attribute in action.
The img
element uses the src
attribute to find where the image is located.
Similarly, the a
element uses the href
attribute to point to the destination link.
As we learn about more elements, we'll see more of these attributes and understand their usage.