Head, Meta Tags & SEO
The <head> of a page is invisible, but it decides a lot: how your page appears in search results, whether it fits a phone screen, how it looks when someone shares the link on WhatsApp or X, and which stylesheets and icons load. This page covers the head elements every site should have and the basics of SEO (search engine optimisation).
A complete head
<head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Amani Otieno – Web Developer in Kisumu</title> <meta name="description" content="Junior web developer in Kisumu. See my projects, skills and how to contact me."> <link rel="icon" href="favicon.svg" type="image/svg+xml"> <link rel="stylesheet" href="css/style.css"> <link rel="canonical" href="https://www.example.com/"> <meta property="og:title" content="Amani Otieno – Web Developer"> <meta property="og:description" content="Projects, skills and contact details."> <meta property="og:image" content="https://www.example.com/images/share-card.jpg"> <meta property="og:url" content="https://www.example.com/"> <meta property="og:type" content="website"> </head>
Let's go through these in groups.
The essentials
Character encoding
<meta charset="utf-8"> tells the browser how the bytes of your file map to characters. Put it first. Without it, characters such as "é", "–" or "Ksh 1,000 ✓" may appear as garbled symbols.
Viewport
Phones used to pretend they were desktop screens (about 980 pixels wide) and shrink the whole page down, leaving tiny unreadable text. This line tells the phone to use its real width:
<meta name="viewport" content="width=device-width, initial-scale=1">
width=device-width matches the page width to the screen, and initial-scale=1 starts at normal zoom. Without it, responsive CSS can't work properly. Don't add user-scalable=no or maximum-scale=1: blocking zoom stops people with low vision from enlarging text.
Title
The <title> appears in the browser tab, in bookmarks and history, and usually as the clickable headline in search results. Make every page's title unique and descriptive, with the most important words first. Search engines typically show about 50–60 characters before cutting it off.
<!-- Weak --> <title>Home</title> <!-- Strong --> <title>Mama Pima Bakery – Fresh Bread in Eldoret</title>
Meta description and search results
The meta description is a one- or two-sentence summary of the page. Search engines may show it as the snippet under your title, though they sometimes write their own from the page text. It doesn't directly raise your ranking, but a clear, accurate description persuades more people to click. Aim for roughly 150–160 characters and write a different one for each page.
Links in the head
<link rel="stylesheet" href="…">loads an external CSS file. This is how you'll attach styles in the CSS series.<link rel="icon" href="…">sets the favicon, the small icon in the browser tab.<link rel="canonical" href="…">tells search engines the main address of a page that can be reached by several URLs, so they don't treat the copies as duplicate content.
Social sharing: Open Graph
When someone pastes your link into WhatsApp, Facebook, LinkedIn or Telegram, the app fetches your page and looks for Open Graph tags to build a preview card. Open Graph was created by Facebook and is now read by most social and chat apps. Note that these tags use the attribute property, not name.
| Tag | Purpose |
|---|---|
og:title | The headline of the card |
og:description | A short line of text under the headline |
og:image | The preview picture; use a full absolute URL (about 1200 × 630 pixels works well) |
og:url | The page's main address |
og:type | Usually website, or article for a blog post |
X (formerly Twitter) also reads its own tags, which use name: for example <meta name="twitter:card" content="summary_large_image"> asks for a large image card. If its own tags are missing, it falls back to Open Graph for most details.
SEO basics in your HTML
Search engines rank pages mainly on useful content and on links from other sites, but your HTML helps them understand and present what you've written:
- Write a unique
<title>and meta description for every page. - Use one clear
<h1>and a logical heading outline. - Use semantic elements such as
<main>and<article>. - Give images useful alt text and links descriptive text.
- Make the page fast and mobile-friendly: the viewport tag, sized and lazy-loaded images, and no huge files.
- Use readable URLs such as
/projects/weather-apprather than/p?id=83.
Adding <meta name="keywords"> stuffed with search terms. Google has ignored the keywords tag for years, and repeating keywords unnaturally in your text can count against you. Write for people first.
To keep a page out of search results, such as a thank-you page, add <meta name="robots" content="noindex">.
Key points
- Start every head with
<meta charset="utf-8">and the viewport tag, and never block zooming. - Each page needs a unique, descriptive
<title>and meta description. <link>loads stylesheets and icons and can declare a canonical URL.- Open Graph tags (
property="og:…") control link previews in social and chat apps.
Tip: use the ← and → keys to move between pages.
