
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Element title Property
The HTML DOM Element title property is used to set and get the title property of any element in the HTML document. It also updates the existing title attribute value with a new one.
In HTML, the title property allows elements to display additional information as tooltips when the elements are hovered over.
Syntax
Following is the syntax of the HTML DOM Element title (to set the property) property −
element.title = New_title;
Where, the New_title is a new value you want to set (assign) for the title property.
Use the following syntax to get the title property value −
element.title;
Parameters
Since this is a property, it will not accept any parameter.
Return Value
This property returns the value of the title attribute of that element.
Example 1: Setting "title" Property to <p> Element
The following is the basic example of an HTML DOM Element title property −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element title</title> </head> <body> <h3>HTML DOM Element title Property</h3> <h4>Hover over the below paragraph to see the title.</h4> <p id="demo">This is a paragraph.</p> <script> let my_ele = document.getElementById('demo'); my_ele.title = "You set the title"; </script> </body> </html>
The above program will dynamically set the title property of the p element.
Example 2: Retrieving "title" Property Value
Here is another example of using the HTML DOM Element title property. This property retrieves the value of the title property of an <a> element in the document −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element title</title> </head> <body> <h3>HTML DOM Element title property</h3> <p>Hover over on the below link</p> <a href="/html/index.htm" title="Click here to learn more" id="my_link"> Learn More </a> <br><br> <button onclick="get_prop()">Get the title proerty value</button> <p id="res"></p> <script> function get_prop(){ let link = document.getElementById('my_link'); document.getElementById('res').innerHTML = link.title; } </script> </body> </html>
The above program displays the title property value of the "a" element when the button is clicked.
Example 3: Updating the "title" Property Value
In the example below, we use the title property to update the old title with a new one for the <div> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element title</title> </head> <body> <h3>HTML DOM Element title property</h3> <p>Hover over on the below content</p> <div id="my_div" title="Inside div">Hey! how are you?</div> <br> <button onclick="update()">Update title value</button> <p id="res"></p> <script> function update(){ let my_div = document.getElementById('my_div'); my_div.title = "Title updated"; document.getElementById('res').innerHTML = "Title updated..."; } </script> </body> </html>
When the button is clicked, the title property will be updated to "Title updated."
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
title | Yes | Yes | Yes | Yes | Yes |