- HTML Tag
- Syntax
- Example of the HTML tag:
- title
- Try it
- Multiline titles
- HTML
- JavaScript
- Result
- Title attribute inheritance
- HTML
- Result
- Accessibility concerns
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- A Step-by-Step Gide to Setting a Title in HTML
- Creating the HTML Layout
- Adding the Title Tag
- Testing the Code
- Community Q&A
HTML Tag
The tag defines a title of an HTML document. A title tag must be the precise description of a page’s content. The title is displayed in the browser toolbar and on search engine results pages (SERPs) as a clickable headline.
The content of the title is an important component that search engine algorithms use to determine the order of list pages’ appearance in search results.
An optimized title tag increases the rank on SERPs and the click-through rate.
- the short title and description of a page which is displayed at the top of the browser window,
- the ranking of search engines,
- the default name for bookmarks created by the user,
- the link headline when it is shared on social media,
- the clickable headline.
There should be only one element in an HTML document located inside the section.
Here are some tips to create good titles:
- Avoid the use of titles with one or two words. Instead, you can use a descriptive phrase.
- If possible, avoid special characters as they can be displayed by browsers differently.
- In general, search engines display about 55-60 characters of a title. When using a longer title, ensure that the important parts are at the beginning.
- Avoid the use of a list of words as a title.
- Ensure that the title is unique in your site.
Syntax
The ) tags.
Example of the HTML tag:
html> html> head> title>W3Docs - learn HTML, CSS, PHP, JavaScript online. title> head> body> p>The main content of the page. p> body> html>
title
The title global attribute contains text representing advisory information related to the element it belongs to.
Try it
The main use of the title attribute is to label elements for assistive technology.
The title attribute may also be used to label controls in data tables.
While title can be used to provide a programmatically associated label for an element, this is not good practice. Use a instead.
Multiline titles
The title attribute may contain several lines. Each U+000A LINE FEED ( LF ) character represents a line break. Some caution must be taken, as this means the following renders across two lines:
HTML
p> Newlines in code>titlecode> should be taken into account. This span title="This is a multiline title"> example span span> has a title a attribute with a newline. p> hr /> pre id="output">pre>
JavaScript
We can query the title attribute and display it in the empty element as follows:
const span = document.querySelector("span"); const output = document.querySelector("#output"); output.textContent = span.title;
Result
Title attribute inheritance
If an element has no title attribute, then it inherits it from its parent node, which in turn may inherit it from its parent, and so on.
If this attribute is set to the empty string, it means its ancestors’ title s are irrelevant and shouldn’t be used in the tooltip for this element.
HTML
div title="CoolTip"> p>Hovering here will show "CoolTip".p> p title="">Hovering here will show nothing.p> div>
Result
Accessibility concerns
Use of the title attribute is highly problematic for:
- People using touch-only devices
- People navigating with keyboards
- People navigating with assistive technology such as screen readers or magnifiers
- People experiencing fine motor control impairment
- People with cognitive concerns
This is due to inconsistent browser support, compounded by the additional assistive technology parsing of the browser-rendered page. If a tooltip effect is desired, it is better to use a more accessible technique that can be accessed with the above browsing methods.
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jun 13, 2023 by MDN contributors.
Your blueprint for a better internet.
A Step-by-Step Gide to Setting a Title in HTML
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
The wikiHow Tech Team also followed the article’s instructions and verified that they work.
This article has been viewed 59,876 times.
Every web page needs a title. Why doesn’t yours? One of the major tag pairs in HTML is the tags; the title tag affects several functions of websites, from the default bookmark titles through to flashing words drawing your attention back to the site, even when in a different tab.
- Create your HTML in a program like Atom, Brackets, TextEdit, or Notepad++.
- Add the Title Tag to your code.
- Change «Something» to the title you want and save the file.
Creating the HTML Layout
Create the body. Using the tags, create a .html file with either tag on a new line. Make sure to close the tag with .
Add the section. Placing the
tags in between the tags, define the head (metadata section) section. Make sure to close the tag with .- Optionally, add some ‘test’ code in the body (or content) section to make sure that you’ve coded it correctly. If the content shows, it means that the code is parsing (loading). If not, it means that you may have made a typo or some other thing that is not letting it load.
Adding the Title Tag
- Make sure to close the tag with . These two tags can be on the same line. In between the starting and closing title tags, write what you want your title to say.
Testing the Code
Save your file to an easily accessible location. Name your file as something.html , replacing something with what you wish. Remember that the index.html file is the ‘home’ or ‘landing’ page of your website.
Open your page in your preferred browser. Browsers like Google Chrome, or Mozilla Firefox are good for front-end website development. Go ahead and open your .html file. You can use short keys like ⌘ Cmd + O or Ctrl + O to open the file in most browsers.
Look at the top of the tab for your title. If your desired title shows, the code has loaded and worked! If not, and it shows your filename instead (something.html), you may have made a mistake; check your code for typos then try again.
Community Q&A
Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow