Command Palette

Search for a command to run...

Hectal
PHASE 6Intermediate ~20 min· topic 2 of 7

Topic 6.2

Titles and Meta Descriptions

In one line

The <title> names the page on tabs, bookmarks and search results, and the meta description is your suggested summary under it; both should be unique, specific and short enough not to be cut off.

Think of it like this

A book on a library shelf. Only the spine shows: a few words that must tell you what the book is so you pull it out. The back cover gives a short blurb that convinces you to read it. In search results, the <title> is the spine and the meta description is the back cover.

Words you'll meet

New words in this topic, in plain English. Come back here whenever one feels fuzzy.

title
The element with the page's name. It shows on the tab and as the headline in search results.
Meta description
A short summary in <meta name="description">. Not shown on the page, often shown in search results.
SERP
Search engine results page: the list of results you see after searching.
Snippet
The short text under a search result's title, describing the page.
Title link
The clickable headline of a search result, usually built from your <title>.
Truncation
Cutting text that is too long and adding ... at the end.
Keyword
A word or phrase people type into a search engine.
Single-page app
A site that swaps content with JavaScript instead of loading a new page for each view.

Step by step

01Say what the page is

Start from the reader's question. Someone searching "egg free pancakes" should see those words early in your title.

Bad: Home. Bad: Asha's Kitchen | Recipes | Food | Cooking | Pancakes | Best. Good: Egg-Free Pancakes in 20 Minutes — Asha's Kitchen.

02Add the brand at the end

A separator (—, | or -) followed by the site name helps people recognise the source. Put it last, because the end is what gets cut off. The home page can lead with the brand.

pancakes.htmlwhole filehtml
<title>Egg-Free Pancakes in 20 Minutes — Asha's Kitchen</title>

03Write the description for a human

One or two sentences: what's on the page and why it's worth the click. Mention specifics (time, price, count, version). Avoid double quotes inside it (they would end the content attribute; write &quot; if you must), and never repeat the title word for word.

pancakes.htmlwhole filehtml
<meta name="description" content="Soft, fluffy pancakes without eggs, ready in 20 minutes. Includes a gluten-free swap and tips for cooking a big batch.">

04Match the title and the h1

The <h1> is the visible headline on the page. It doesn't need to be identical to the title, but they should say the same thing. When they disagree, Google is more likely to rewrite your title link.

pancakes.htmlwhole filehtml
<h1>Egg-free pancakes in 20 minutes</h1>

05Check how it will look

The live example below draws a search result from the page's own head and warns about lengths. Real tools: Google Search Console shows which queries bring people, and searching site:yourdomain.com shows your live results.

Check how it will lookdiagram
Rendering diagram…

Try it yourself

  1. 1

    Make the title too long

    In the first example, change the title to The Best Ever Easy Egg-Free Fluffy Vegan Breakfast Pancakes Recipe for Families — Asha's Kitchen. Predict what the console says and where the preview cuts it. Run and check.

  2. 2

    Remove the description

    Delete the <meta name="description"> line and run. The script crashes: read the error and explain it. Then change the script to use document.querySelector('meta[name="description"]')?.content ?? "(Google would pick text from the page)".

  3. 3

    Look at real results

    Search for something you know well. For three results, compare the title link with the page's real <title> (open the page and look at the tab). Did any get rewritten?

Code & diagrams

A search result preview built from the head New tab

Real engines cut by pixel width, not by character count; 60 and 160 characters are good rules of thumb.

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Title length: 48 ok
Description length: 118 ok
Changing the title from JavaScript New tab

The getter trimmed and collapsed the messy whitespace. Click the button to see the title change again; in a real tab, the tab text would update.

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Tidied title: Inbox — Mailo
After update: (2) Inbox — Mailo

Break it on purpose

Errors are the best teachers. Make each change, read the error, guess what went wrong, then reveal the answer.

Break #1

The same title on every page

Give every page of a site <title>Asha's Kitchen</title>.

terminal
$ Search Console / search results
── what you'll see ──
Many results with identical title links; Google rewrites some from the page's h1, others show only the site name.

Break #2

A missing description crashes the script

In the first example, delete the description meta tag.

terminal
$ Console
── what you'll see ──
Uncaught TypeError: Cannot read properties of null (reading 'content')

Myth vs fact

Myth

The meta description boosts your ranking.

Fact

It doesn't affect ranking directly. It affects how many people click your result, which is why it is still worth writing well.

Myth

<meta name="keywords"> helps SEO.

Fact

Google ignores it. Put the words people search for in your title, headings and text instead.

Myth

Google always shows exactly my title and description.

Fact

Google may rewrite the title link and often picks a snippet from your page text to match the search. Accurate, specific tags get kept more often.

Pro corner

Extra depth for experienced readers. New to this? Skip it for now and come back later.

  • ▸

    Google's title-link system (changed in 2021) can use the <title>, the main visible heading, other prominent headings, anchor text from links pointing to the page, and og:title. Mismatched or boilerplate titles are the usual cause of rewrites.

  • ▸

    Truncation is by pixel width: WWWW is much wider than iiii. Mobile and desktop SERPs differ, and so do Bing and DuckDuckGo. Treat 60 and 160 characters as guides, not limits; nothing breaks if you go over, the end is just hidden.

  • ▸

    Accessibility: WCAG 2.4.2 (Page Titled) requires titles that describe the topic or purpose. For single-page apps, update document.title on every route change and move focus to the new <h1> so screen-reader users notice the change.

  • ▸

    max-snippet:[n], nosnippet and data-nosnippet control snippets for Google. Note that data-nosnippet only works on span, div and section elements.

Remember this

  1. 1

    The <title> element is required in every page and there must be only one. It shows in the browser tab, in bookmarks and history, as the headline of a search result, as the fallback headline when a link is shared, and it is the first thing a screen reader announces when the page opens. A search result is one entry in the list a search engine shows; the page of results is called the SERP (search engine results page).

  2. 2

    A good title says what this page is, most important words first, then the site name: Pancake Recipes: Fluffy, Easy and Egg-Free — Asha's Kitchen. Google cuts titles that are wider than about 600 pixels, roughly 50–60 characters, and adds .... Put the words people search for at the start so they survive the cut. Every page needs its own title: a site where every page is titled Home is impossible to tell apart in tabs or results.

  3. 3

    <meta name="description" content="..."> is a one- or two-sentence summary of the page. It is not shown on the page itself. Search engines often use it as the snippet, the grey text under the title. Aim for roughly 120–160 characters, written for a human: say what the reader gets, include the main words they'd search, and make each page's description unique.

  4. 4

    Search engines may rewrite both. Google builds the title link from your <title>, but may use the main heading, link text or other text if your title is missing, too long, stuffed with keywords or the same on many pages. The snippet is often chosen from the page's text to match the person's search. You control them best by writing an accurate title that matches your <h1> and a description that truly summarises the page.

  5. 5

    The description has no direct effect on ranking; it affects whether people click. The old <meta name="keywords"> tag is ignored by Google and has been for years; don't spend time on it. Robots directives can also limit snippets: <meta name="robots" content="max-snippet:50"> or the data-nosnippet attribute on an element (more in Topic 6.7).

  6. 6

    JavaScript can change the title with document.title = "(3) Inbox". Single-page apps (sites that change content without loading a new page) must do this on every view change, otherwise the tab and screen reader announcements show a stale name. The document.title getter also tidies the text: it trims spaces at both ends and collapses runs of whitespace into one space.

Explain it without notes

01

Name five places where a page's <title> is used.

02

What makes a good title for a recipe page, and why does word order matter?

03

Does the meta description affect ranking? Why write one anyway?

04

Why might Google show a different title than the one you wrote?

Practice

01

Write a title and a meta description for a page that sells a blue cotton school bag for ₹899 on a shop called BagBazaar.

02

Write a JavaScript function setUnread(n) that sets the title to Inbox — Mailo when n is 0 and to (n) Inbox — Mailo otherwise. Call it with 0 and 5 and log the title.

Trade-offs

  • ↔

    Including the brand in every title builds recognition but uses up the 60 characters; on long titles, drop the brand (Hectal's own pageMeta() does exactly this).

  • ↔

    A hand-written description per page is the best quality but doesn't scale to thousands of pages; generate them from structured data (price, rating, summary) and hand-write the most important pages.

Done when you can

  • I can write a unique, specific title with the brand at the end.

  • I can write a 120–160 character description for a human reader.

  • I know the description doesn't affect ranking but does affect clicks.

  • I know why Google rewrites titles and how to avoid it.

  • I can update document.title from JavaScript.