What is the use of title attribute in HTML?

Overview

We use the title attribute in HTML to specify the extra information about the element. The additional information appears whenever the mouse hovers over the element.

Note: All HTML tags support this attribute.

Syntax

We'll use the syntax below to add the title attribute to an HTML element:


<element title='text'>


Here element can be any sort of HTML tag , for example, <p>,<a> and <img>, and others.

Example 1

The following code snippet illustrates the use of the title attribute in the h3 tag of HTML:

Use of title attribute in <h3> tag

Explanation

  • Line 5: This line uses the title attribute in a <h3> tag. The result is shown in the output tab of the widget above.
  • The example above shows that the additional information appears when we hover the mouse over the <h3> tag.

Example 2

Similarly, we can make use of the title attribute on <img> tag as well. This is depicted by the code snippet below:

Use of title attribute in <img> tag

Explanation

  • Line 5: This line depicts the use of title attribute in an <img> tag and sets it to the value of Educative Inc.

This answer summarizes the primary use of the title attribute along with code snippets to demonstrate its functionality.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved