HTML elements with attributes


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 below, we add this attribute to an <h1> element with the value as “This is the title”.