0
0
HtmlConceptBeginner · 3 min read

What is Title Attribute in HTML: Definition and Usage

The title attribute in HTML adds extra information to an element that appears as a tooltip when you hover over it with a mouse. It helps provide helpful hints or descriptions without cluttering the page visually.
⚙️

How It Works

The title attribute works like a small note attached to an HTML element. When you move your mouse pointer over that element, a small box with the note's text appears. This is similar to how a sticky note on a book page gives you extra info without changing the main text.

This tooltip helps users understand more about the element, such as explaining a link's destination or describing an image. It is supported by all modern browsers and works automatically without extra code.

💻

Example

This example shows a link with a title attribute. When you hover over the link, the tooltip text appears.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Title Attribute Example</title>
</head>
<body>
  <a href="https://www.example.com" title="Visit Example website">Example Link</a>
</body>
</html>
Output
A webpage with a clickable link labeled 'Example Link'. When hovered, a small tooltip shows 'Visit Example website'.
🎯

When to Use

Use the title attribute to give extra helpful information about an element without adding visible text. It is great for:

  • Explaining links, especially if the link text is short or unclear.
  • Describing images or icons for better understanding.
  • Providing hints for buttons or form fields.

However, do not rely on it for important information because some users may not see tooltips, especially on touch devices or screen readers.

Key Points

  • The title attribute shows a tooltip on mouse hover.
  • It adds extra info without cluttering the page.
  • Not all users or devices display tooltips.
  • Use it for helpful hints, not critical content.

Key Takeaways

The title attribute adds a tooltip with extra info on hover.
It helps explain elements like links and images without visible text.
Tooltips may not show on all devices, so avoid critical info in title.
Use title for helpful hints to improve user experience.