<title>
The document title shown on the browser tab, in bookmarks, and as the headline of a search result.
- Display
- none
- Closing tag
- Required
- Permitted content
- Text only (tags are not interpreted)
Example
#<head>
<meta charset="utf-8">
<title>HTML Tables: A Step-by-Step Course | CodeWorlds</title>
</head>Definition and usage
#The <title> element gives the page a title. It isn’t visible in the content, but it appears in many other places: on the browser tab, in the history, as the default bookmark name, and usually as the clickable headline of a Google result. A screen reader reads it out as the first piece of information after the page opens.
Every HTML document must have exactly one <title>, placed in <head>. Only text can go inside. Tags, such as <b>, won’t work and will be displayed literally. Character entities such as &, on the other hand, are converted into the matching characters.
A good title is short, unique for each subpage, and starts with what matters most. Add the site name at the end, e.g. “HTML Tables: A Step-by-Step Course | CodeWorlds”. Search engines truncate titles that are too long, so key words shouldn’t wait at the end.
The page title and the <h1> heading don’t have to be identical. <title> describes the page to the outside world, for example in search results, while <h1> greets the user who has already arrived.
Syntax
#<title>Page title</title>Attributes
#This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.
More examples
#<script>
const unread = 3;
document.title = '(' + unread + ') Messages | CodeWorlds';
</script>This is how apps show the number of unread messages on the tab. In single-page applications (SPAs), update the title on every view change.
Default CSS
#Most browsers display this element with these default styles:
title {
display: none;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Every subpage should have its own descriptive title. Ten tabs named “Home page” are a pain for anyone who has many open at once.
- Don’t stuff the title with a list of keywords. Write for people, and search engines will appreciate it.
- If the page shows an error or the result of an action, e.g. “Page not found” or “The form contains errors”, reflect that in the title.
Related entries
#- <head>The invisible part of the document holding metadata: the title, character encoding, description, styles, and scripts.
- <meta>Page metadata: character encoding, mobile viewport settings, a description for search engines, and a link preview on social networks.
- <html>The root of an HTML document. Every other element on the page lives inside it.
- <h1>-<h6>Headings at six levels, from the most important h1 to the least important h6. Together they form the page’s outline.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.