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.
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.
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.
Always include this as the first meta tag in your head. Without it, special characters may display as garbled text (called "mojibake").
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.
Always include the viewport meta tag. Here's what each part means:
width=device-widthโ Sets the width to the device's screen widthinitial-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.
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.
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.
Key Open Graph tags:
og:titleโ The headline when shared (keep it catchy, under 70 characters)og:descriptionโ The description shown below the titleog: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 <link> element and other head tags
The <link> element connects external resources like stylesheets, fonts, and favicons to your page.
Common link types:
rel="stylesheet"โ External CSS filerel="icon"โ Favicon (the small icon in the tab)rel="preconnect"โ Pre-connect to a domain for faster loading (especially fonts)rel="canonical"โ The preferred version of a page (for SEO when you have duplicates)
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.
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:
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.
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
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 โ