The HTML title attribute specifies additional information about an element.
Definition and Usage
➔ When the user hovers the mouse over the element, most browsers typically display a small, temporary message box (tooltip).
Syntax
//In HTML
<p title="Tutorials for beginners" id="sample">
Visit w3context.com to learn HTML
</p>
<img src="myimage.png" alt="Description of the image." title="Provide some specific information about this">
//In Javascript
//let element = document.querySelector("#sample");
//element.title= "Tutorials for beginners";
//element.setAttribute('title', 'Tutorials for beginners');
Applies to
This attribute can be used on the following element.
| Attribute | Element |
|---|---|
| title | Global Attributes |
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML title attribute Example</title>
</head>
<body>
<h3>HTML title attribute Example</h3>
<p>title attribute display a small, temporary message box (tooltip),
when the user hovers the mouse over the element</p>
<p title="Tutorials for beginners" id="sample">
Visit w3context.com to learn HTML
</p>
</body>
<script>
//let element = document.querySelector("#sample");
//element.title= "Tutorials for beginners.";
//element.setAttribute('title', 'Tutorials for beginners.');
</script>
</html>
Click on the "Try it Now" button to see how it works.