HTML & CSSEasy
What is the <title> tag?
<title> sets the document's title, which appears in the browser tab, bookmarks and history, is announced by screen readers when the page loads, and is usually used as the clickable headline in search results. It goes in <head>, is required for a valid document, and should be unique and descriptive for every page.
Writing good titles
- Put the most specific information first:
"Edit profile | Settings | DevQnA". - Keep it concise; search engines typically show about 50 to 60 characters.
- Make each page's title unique, matching the page's main heading.
- Avoid keyword stuffing.
Accessibility
Screen reader users hear the title first; in single-page apps, update it on every route change so users know the page changed (WCAG 2.4.2 Page Titled).
Dynamic titles
- JavaScript:
document.title = "3 new messages | Inbox". - React 19: render
<title>anywhere in a component and React hoists it into<head>. - Next.js: the Metadata API (
export const metadata = { title },title.template). - React Router:
metaexports in framework mode.
Details
- Only one
<title>per document; it contains text only (no markup). - It is different from the
titleattribute, which creates a tooltip on any element and is not reliable for accessibility.
SEO
Search engines may rewrite titles that are missing, duplicated or unhelpful, so it pays to write them deliberately.
Code example
html
1<!doctype html>2<html lang="en">3<head>4 <meta charset="utf-8">5 <title>Order #1042 | Orders | Acme Store</title>6</head>7<body>8 <h1>Order #1042</h1>9 <p>Unread notifications: <output id="count">0</output></p>10 <button id="ping">Simulate new message</button>11 <script>12 const base = "Order #1042 | Orders | Acme Store";13 let unread = 0;14 document.getElementById("ping").addEventListener("click", () => {15 unread++;16 document.getElementById("count").textContent = unread;17 // Dynamic titles help users notice updates in background tabs18 document.title = `(${unread}) ${base}`;19 });20 </script>21</body>22</html>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.