The <head> is invisible to visitors but vital to machines — browsers, search engines and social platforms all read it. A few meta tags here decide whether your page renders correctly on phones and whether a shared link looks like a rich preview card or an ugly bare URL.
1The must-have meta tags
Three meta tags belong in essentially every page's <head>:
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<meta name="description" content="…">charset="UTF-8"— tells the browser how to read your text. Without it, accents and other languages can turn into garbled symbols. It should be the first thing in the head.viewport— the single most important tag for mobile. It makes the page fit the device width instead of showing a tiny zoomed-out desktop layout. Leave it out and your responsive CSS won't work on phones.description— the search snippet from the last lesson.
viewport tag, your site will look broken and tiny on every phone — and most of your visitors are on phones. It's not optional.<meta charset="UTF-8">ensures text and accents display correctly — put it first.<meta name="viewport">makes the page fit mobile screens — without it, responsive CSS won't work.<meta name="description">supplies the search-result snippet.
2Open Graph — control your share preview
When someone pastes your link into WhatsApp, Facebook, LinkedIn or X, those platforms look for Open Graph (og:) meta tags to build the preview card — the image, title and description you see:
<meta property="og:title" content="Free HTML & CSS Course"> <meta property="og:description" content="Learn web design, free."> <meta property="og:image" content="https://site.com/cover.jpg"> <meta property="og:url" content="https://site.com/">
X (Twitter) adds a couple of its own: <meta name="twitter:card" content="summary_large_image"> for a big-image card. The playground below shows what these values produce — a share card:
- Open Graph (
og:) meta tags control the preview card shown when your link is shared. - Key ones:
og:title,og:description,og:image,og:url. - Add
twitter:cardfor X's preview style (e.g.summary_large_image).
★ Practical: a complete, share-ready head
Write the <code><head></code> meta tags for a page about your project:
<meta charset="UTF-8">and the mobileviewporttag.- A
<meta name="description">. - Open Graph tags:
og:title,og:description,og:image,og:url. - A
twitter:cardtag set tosummary_large_image.
Ready to test yourself?
Take the short quiz. Score 60% or more to mark this lesson complete.
Start the quiz →💡 Log in to save your progress and earn the certificate.