The <head> is the control room of a page: nothing in it is displayed as content, yet it decides how the page is titled, encoded, scaled, found and shared.
The title element#
<title>Menu | Brew and Byte Cafe</title>The title appears in the browser tab, in bookmarks, in history and as the clickable headline in search results. Make it:
- unique for every page,
- descriptive, with the page topic first and the site name after,
- short, ideally under about 60 characters so search engines do not cut it.
Screen readers announce the title first when a page loads, so it is also your first accessibility message.
The meta element#
<meta> is a void element that provides metadata, using different attributes.
Character encoding#
<meta charset="utf-8">Use UTF-8 and place it first in the head (within the first 1024 bytes). It lets you use accented letters, Devanagari script and symbols correctly.
Viewport#
<meta name="viewport" content="width=device-width, initial-scale=1">Without this line, phones pretend to be a wide desktop screen and shrink your page. This one line is the first step of responsive design. Do not disable zoom with user-scalable=no, as that harms people with low vision.
Description#
<meta name="description" content="Fresh coffee, home-baked bread and free Wi-Fi in Pokhara. See our menu and opening hours.">Search engines often show this text beneath the title. Write a natural summary of 120 to 160 characters, and give each page its own.
Other useful meta tags#
<meta name="author" content="Brew and Byte team">
<meta name="theme-color" content="#3b2314">
<meta name="robots" content="noindex">theme-colortints the browser toolbar on some phones.robotswithnoindexasks search engines not to list the page. Use it for private or thank-you pages.
A well-formed head#
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Menu | Brew and Byte Cafe</title>
<meta name="description" content="Coffee, cakes and light lunches. Prices and allergy information.">
</head>Open Graph basics#
When someone shares your link in a chat or social network, the app builds a preview card. It looks for Open Graph tags, which use a property attribute.
<meta property="og:title" content="Brew and Byte Cafe">
<meta property="og:description" content="Coffee and co-working in Pokhara.">
<meta property="og:image" content="https://example.com/images/share-card.jpg">
<meta property="og:url" content="https://example.com/">
<meta property="og:type" content="website">Use an absolute URL for the image, and a picture of roughly 1200 by 630 pixels. Preview rules vary between platforms, so test with the sharing tools they provide.
Common mistakes#
- Giving every page the same title.
- Forgetting the viewport tag, so mobile pages look tiny.
- Leaving the charset until late in the head.
- Stuffing the description with keywords.
- Using relative image URLs in Open Graph tags.
Try it yourself#
Write the head for three pages of your site (home, menu, contact) with unique titles and descriptions. Add Open Graph tags to the home page. Open each in the browser and look at the tab text, then use the tab list and bookmarks to see how titles are displayed.
Recap#
Always set a unique title, charset, viewport and description. Add Open Graph tags for friendly link previews, and use robots for pages that should not be indexed.
Check your understanding
Lesson quiz
OptionalA short quiz to check what you just learned.
- Questions
- 4
- Time limit
- 5 min
- Pass mark
- 70%
- Best score
- -