The HTML title attribute provides additional information about an HTML element. Browsers commonly display this information as a tooltip when a user hovers the mouse pointer over the element.
You can use the title attribute with headings, paragraphs, links, buttons, images, and many other HTML elements. In this tutorial, you will learn how the title attribute works and how to use it with practical examples.
What Is the HTML Title Attribute?
The title attribute is a global HTML attribute that adds advisory information to an element.
For example:
<p title="This is additional information">
Hover over this paragraph.
</p>
When a user hovers over the paragraph, the browser may display the title text as a tooltip.
The title attribute does not change the visible text of the paragraph. Instead, it provides extra information that may help users understand the element.
You can learn about other attributes that work across HTML elements in our guide to HTML global attributes.
HTML Title Attribute Syntax
The basic syntax is:
<tagname title="Additional information">Content</tagname>
The title attribute contains a text value describing the element.
For example:
<h2 title="Introduction to HyperText Markup Language">
HTML Tutorial
</h2>
When a user hovers over the heading, the browser may show the additional information.
Using the Title Attribute with Links
You can use the title attribute to provide extra context about a link.
<a href="https://web4learners.com/"
title="Visit the Web4Learners website">
Web4Learners
</a>
The link directs users to the website, while the title provides additional information that may appear when hovering over it.
However, do not rely on the title attribute as the only way to explain an important link. Some users may not be able to see or access hover tooltips.
Using the Title Attribute with Images
The title attribute can add extra information to an image.
<img src="computer.jpg"
alt="Laptop on a desk"
title="A laptop used for web development"
width="400">
Here, alt provides alternative text for the image, while title supplies additional advisory information that may appear as a tooltip.
Important: The title attribute is not a replacement for the alt attribute. Alternative text is important for accessibility and for cases where an image cannot be displayed.
Using the Title Attribute with Buttons
You can add a title to a button to provide extra context about its purpose.
<button type="button"
title="Save your changes">
Save
</button>
The browser may display the tooltip when the user hovers over the button.
For important instructions, use visible text or an accessible label rather than depending only on a tooltip.
Difference Between the Title Element and Title Attribute
The HTML title element and the title attribute have different purposes.
| Feature | Title Element | Title Attribute |
|---|---|---|
| Syntax | <title> | title="..." |
| Purpose | Sets the document’s title | Adds advisory information to an element |
| Location | Inside the <head> element | Inside an HTML opening tag |
| Example | <title>HTML Tutorial</title> | <p title="Extra details">Text</p> |
The title element typically supplies the page title shown in the browser tab. The title attribute provides additional information about a particular element.
You can also explore the HTML style attribute to learn how to apply inline CSS to elements.
Important Things to Remember
- The
titleattribute provides additional information about an HTML element. - Browsers commonly display its value as a tooltip on hover, but the exact behavior can vary.
- It is a global attribute and works with many HTML elements.
- It should not replace visible instructions, accessible labels, or image alternative text.
- Use short, meaningful descriptions that help users understand the element.
Frequently Asked Questions
Is the HTML title attribute required?
No. It is optional. Use it when additional information is helpful.
Does the title attribute work on all HTML elements?
It is a global attribute supported by most HTML elements, although how the information is presented depends on the browser and the element.
Is the title attribute important for SEO?
The title attribute is not a substitute for meaningful page titles, descriptive content, or useful link text. Use it primarily when it provides genuine value to users.
Can I use the title and class attributes together?
Yes. You can combine multiple HTML attributes in one opening tag.
<p class="highlight" title="Additional information">
Learn HTML with Web4Learners.
</p>
The class attribute identifies a group of elements for styling or scripting, while title provides additional advisory information.