What is the head element?

The <head> element contains metadata about your page โ€” information that tells the browser and search engines what your page is about, how to display it, and how to handle it. Nothing inside <head> appears visually on the page.

Think of it as the passport for your web page. It doesn't show your face, but it tells everyone who you are, where you're from, and all the important details about you.

Key point:
The head section is critical for SEO, mobile responsiveness, and social media sharing. It's one of the most important parts of your HTML.

Common elements inside <head> include:

  • <title> โ€” The page title (shown in browser tab and search results)
  • <meta> โ€” Metadata like charset, viewport, description, keywords
  • <link> โ€” Links to external resources like CSS files, favicons, fonts
  • <style> โ€” Inline CSS (less common, usually in separate CSS files)
  • <script> โ€” JavaScript files or inline code
  • <base> โ€” Sets a base URL for relative links

The <title> element

The <title> tag sets the text that appears in the browser tab. It's also the headline that search engines display in results. Make it clear, descriptive, and under 60 characters for best results.

title.html Browser tab title

Good title examples:

  • "Build Your First Website | Learn HTML & CSS"
  • "Best Web Development Bootcamp in Nairobi"
  • "React Tutorial for Beginners | Free Course"

Bad title examples:

  • "Home" โ€” Too vague, doesn't describe the page
  • "Welcome to our website!!!" โ€” Uses too many exclamation marks
  • "Page 1 of 500 pages of technical documentation..." โ€” Way too long

Meta charset โ€” Character encoding

The <meta charset="UTF-8"> tag tells the browser how to interpret characters. UTF-8 is the global standard โ€” it supports emojis, Hindi, Swahili, Arabic, and any other script.

charset.html Always declare charset

Always include this as the first meta tag in your head. Without it, special characters may display as garbled text (called "mojibake").

Example:
Without UTF-8, "Hello ๐ŸŒ" might display as "Hello ?" and "Nairobi" might show as scrambled symbols.

Meta viewport โ€” Mobile responsiveness

The <meta name="viewport"> tag tells mobile browsers how to display your page. Without it, pages look tiny and unusable on phones.

viewport.html Make pages mobile-friendly

Always include the viewport meta tag. Here's what each part means:

  • width=device-width โ€” Sets the width to the device's screen width
  • initial-scale=1.0 โ€” Starts at 100% zoom (not zoomed in or out)

Without this tag, your page will be zoomed out on mobile devices, making text tiny and hard to read. Google also uses this as a ranking factor โ€” mobile-friendly pages rank higher.

Meta description and keywords

The <meta name="description"> tag summarizes your page in 150โ€“160 characters. Search engines display this text under your page title in results.

seo-meta.html SEO meta tags for search engines

Meta tags explained:

  • name="description" โ€” 150โ€“160 characters summarizing your page. Google uses this in search results.
  • name="keywords" โ€” Comma-separated keywords. Less important now, but still useful.
  • name="author" โ€” Who created the page.
  • name="robots" โ€” Instructions for search engine bots. index, follow = index this page and follow links.
Pro tip:
Write your description as if it's an ad. Make it compelling and click-worthy โ€” people read descriptions before deciding whether to click your link.

Open Graph tags โ€” Social media sharing

When someone shares your page on Facebook, Twitter, WhatsApp, or LinkedIn, these platforms use Open Graph (OG) meta tags to display a nice preview: a title, description, image, and link.

Without OG tags, the preview looks ugly and incomplete. With them, your page looks professional and shareable.

โœ๏ธ Try It Yourself โ€” Open Graph Tags
Preview

Key Open Graph tags:

  • og:title โ€” The headline when shared (keep it catchy, under 70 characters)
  • og:description โ€” The description shown below the title
  • og:image โ€” The thumbnail image (use 1200x630px for best results)
  • og:type โ€” The content type: website, article, video, etc.
  • og:url โ€” The canonical URL of your page

Twitter Card tags: Twitter uses separate tags for better control over how your page appears on Twitter.

  • twitter:card โ€” summary (small), summary_large_image (big with image)
  • twitter:title, twitter:description, twitter:image โ€” Self-explanatory

The <base> element

The <base> element sets a base URL for all relative links on your page. It's rarely used, but useful when your HTML is in a subdirectory.

base.html Setting a base URL

In this example, without the <base> tag, the link would be relative to the root of the domain. With it, all relative URLs are resolved from the base URL.

Try it yourself โ€” Complete head section

Here's a complete, production-ready head section for a portfolio website. Copy this as your template:

โœ๏ธ Try It Yourself โ€” Complete Head Section
Preview

Key takeaways

  • The head element contains invisible metadata that controls SEO, mobile display, and social sharing.
  • <title> appears in browser tabs and search results โ€” keep it under 60 characters and descriptive.
  • <meta charset="UTF-8"> enables support for emojis, Hindi, Arabic, and any script โ€” always include it.
  • <meta name="viewport"> makes your page mobile-friendly. Without it, pages look broken on phones.
  • <meta name="description"> (150โ€“160 chars) shows under your title in Google results โ€” write it like an ad.
  • Open Graph tags control how your page looks when shared on Facebook, LinkedIn, WhatsApp, etc.
  • <link rel="stylesheet"> connects your CSS file. rel="icon" sets your favicon.
  • <base> sets a base URL for all relative links โ€” rarely used but handy for certain setups.
Challenge: Perfect Portfolio Head Section

Task: Build a complete head section for your own portfolio website with:

  • A descriptive <title> (under 60 characters)
  • All essential meta tags: charset, viewport, description, keywords, author
  • Open Graph tags (og:title, og:description, og:image, og:type)
  • Twitter Card tags (twitter:card, twitter:title, twitter:description)
  • A favicon link
  • A Google Fonts link with preconnect
  • A stylesheet link
  • A canonical URL

Paste your head section in the editor above and run it to see the title display!

Hint: Use the "Complete head section" example above as your template. Replace the values with your own name, description, and image URLs. The preview will show your page title at the top!

Test your knowledge

Question 1 of 5
Which element sets the text in the browser tab?
Question 2 of 5
What does <meta charset="UTF-8"> enable?
Question 3 of 5
Which meta tag controls how search engines index your page?
Question 4 of 5
What are Open Graph tags used for?
Question 5 of 5
Which element links an external CSS file to your HTML?
0
/5
Great job! You're mastering the head section.
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

Your pages are now
SEO-ready and shareable.

Join the Best AI Programs โ€” three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses โ†’