Head Elements & Meta
The <head> section of an HTML document is where metadata lives. While invisible to users, the head contains critical information that controls how a page appears in search results, how it is shared on social media, what resources it loads, and how browsers render it.
A well-structured head section is essential for SEO, performance, accessibility, and responsive design. This page covers every element that belongs in the head and how to use them effectively.
The <title> element defines the document title that appears in the browser tab, search engine results pages (SERPs), and bookmarks. It is the single most important SEO element in the head.
| 1 | <head> |
| 2 | <title>Blueprint Documentation — HTML Reference Guide</title> |
| 3 | </head> |
Title best practices:
The charset meta tag declares the character encoding of the document. UTF-8 is the universal standard that supports every character in the Unicode standard:
| 1 | <meta charset="UTF-8"> |
This meta tag should be the first element inside <head> after the opening tag. Browsers use a lookahead algorithm to detect the encoding, so placing it early ensures correct parsing of all subsequent content. Without it, browsers may misinterpret special characters, leading to mojibake (garbled text).
| 1 | <!-- Recommended order: charset first --> |
| 2 | <head> |
| 3 | <meta charset="UTF-8"> |
| 4 | <title>Page Title</title> |
| 5 | <!-- other meta tags follow --> |
| 6 | </head> |
info
The viewport meta tag controls how the page is displayed on mobile devices. It tells the browser to use the device's actual width rather than scaling down a desktop layout:
| 1 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
The content attribute accepts several directives:
| Directive | Value | Description |
|---|---|---|
| width | device-width or pixels | Sets the viewport width. device-width matches the device screen width. |
| initial-scale | 1.0 | Initial zoom level when the page loads. |
| minimum-scale | 0.5 – 10.0 | Minimum allowed zoom level. |
| maximum-scale | 0.5 – 10.0 | Maximum allowed zoom level. |
| user-scalable | yes / no | Whether the user can zoom the page. Avoid no for accessibility. |
| interactive-widget | resizes-visual / resizes-content | Controls how the viewport behaves when the virtual keyboard appears. |
best practice
The description meta tag provides a summary of the page that search engines often display as the snippet in search results. The keywords meta tag has little to no SEO value today but is included for completeness:
| 1 | <meta name="description" content="Learn HTML document structure, head elements, and semantic markup with practical examples. A beginner-friendly guide to writing valid HTML5."> |
| 2 | |
| 3 | <meta name="keywords" content="HTML, HTML5, web development, frontend, web design, semantic HTML"> |
| 4 | |
| 5 | <meta name="author" content="Blueprint Engineering"> |
Description best practices:
Open Graph (OG) meta tags control how your page appears when shared on social platforms like Facebook, LinkedIn, and Discord. Twitter uses its own twitter: prefix but falls back to OG tags:
| 1 | <!-- Open Graph --> |
| 2 | <meta property="og:title" content="HTML Document Structure Guide"> |
| 3 | <meta property="og:description" content="Learn how to structure HTML documents correctly with semantic elements and best practices."> |
| 4 | <meta property="og:image" content="https://example.com/images/html-guide.png"> |
| 5 | <meta property="og:url" content="https://example.com/docs/html/structure"> |
| 6 | <meta property="og:type" content="article"> |
| 7 | <meta property="og:site_name" content="Blueprint Engineering"> |
| 8 | <meta property="og:locale" content="en_US"> |
| 9 | |
| 10 | <!-- Twitter Card --> |
| 11 | <meta name="twitter:card" content="summary_large_image"> |
| 12 | <meta name="twitter:title" content="HTML Document Structure Guide"> |
| 13 | <meta name="twitter:description" content="Learn how to structure HTML documents correctly with semantic elements and best practices."> |
| 14 | <meta name="twitter:image" content="https://example.com/images/html-guide.png"> |
| 15 | <meta name="twitter:site" content="@blueprinteng"> |
Required OG properties:
| Property | Description | Required |
|---|---|---|
| og:title | The title of the content as it appears in the share card | Yes |
| og:description | A brief description shown below the title | No |
| og:image | The image displayed in the share card (1200×630 recommended) | Yes |
| og:url | The canonical URL of the content | Yes |
| og:type | The type of content (website, article, video, etc.) | Yes |
The <link> element connects external resources to the document. It is most commonly used for stylesheets and favicons, but also supports preloading, prefetching, and alternate formats:
| 1 | <!-- Stylesheet --> |
| 2 | <link rel="stylesheet" href="styles.css" media="screen"> |
| 3 | <link rel="stylesheet" href="print.css" media="print"> |
| 4 | |
| 5 | <!-- Favicon --> |
| 6 | <link rel="icon" href="favicon.ico" type="image/x-icon" sizes="16x16"> |
| 7 | <link rel="icon" href="favicon.svg" type="image/svg+xml"> |
| 8 | <link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180"> |
| 9 | |
| 10 | <!-- Preload critical resources --> |
| 11 | <link rel="preload" href="fonts/inter.woff2" as="font" type="font/woff2" crossorigin> |
| 12 | <link rel="preload" href="hero.webp" as="image"> |
| 13 | |
| 14 | <!-- Prefetch for future navigation --> |
| 15 | <link rel="prefetch" href="/about" as="document"> |
| 16 | <link rel="prefetch" href="/about/styles.css" as="style"> |
| 17 | |
| 18 | <!-- Preconnect to third-party origins --> |
| 19 | <link rel="preconnect" href="https://fonts.googleapis.com"> |
| 20 | <link rel="dns-prefetch" href="https://analytics.example.com"> |
| 21 | |
| 22 | <!-- Alternate versions --> |
| 23 | <link rel="alternate" href="/feed.xml" type="application/rss+xml" title="RSS Feed"> |
| 24 | <link rel="canonical" href="https://example.com/page"> |
| 25 | <link rel="alternate" href="https://example.com/es/page" hreflang="es"> |
Performance-related rel values:
| rel | Purpose | When to Use |
|---|---|---|
| preload | Loads a resource early with high priority | Critical fonts, hero images, above-the-fold CSS |
| prefetch | Loads a resource for a future navigation with low priority | Next page resources when user is likely to navigate |
| preconnect | Establishes an early connection to an origin | Third-party origins (CDNs, font services) |
| dns-prefetch | Resolves DNS early for an origin | Fallback for browsers that don't support preconnect |
| modulepreload | Preloads an ES module and its dependencies | Critical JavaScript modules |
The <script> element is used to embed or reference JavaScript code. Its placement and attributes significantly impact page load performance:
| 1 | <!-- External script (blocking) --> |
| 2 | <script src="app.js"></script> |
| 3 | |
| 4 | <!-- External script with defer (recommended for head) --> |
| 5 | <script src="app.js" defer></script> |
| 6 | |
| 7 | <!-- External script with async --> |
| 8 | <script src="analytics.js" async></script> |
| 9 | |
| 10 | <!-- Inline script --> |
| 11 | <script> |
| 12 | console.log('Hello from inline script!'); |
| 13 | </script> |
| 14 | |
| 15 | <!-- Module script (ES modules) --> |
| 16 | <script type="module"> |
| 17 | import { greet } from './utils.js'; |
| 18 | greet(); |
| 19 | </script> |
| 20 | |
| 21 | <!-- Script with integrity (SRI) --> |
| 22 | <script src="https://cdn.example.com/lib.js" |
| 23 | integrity="sha384-abc123..." |
| 24 | crossorigin="anonymous"></script> |
| 25 | |
| 26 | <!-- NoScript fallback --> |
| 27 | <noscript> |
| 28 | <p>JavaScript is required for this feature.</p> |
| 29 | </noscript> |
The defer attribute tells the browser to download the script in parallel with parsing and execute it only after the document is fully parsed. The async attribute downloads in parallel but executes as soon as it is available, blocking the parser momentarily.
| Attribute | Download | Execution | Order |
|---|---|---|---|
| (none) | Blocks parser | Immediately when downloaded | In document order |
| defer | Parallel (non-blocking) | After parser finishes, before DOMContentLoaded | In document order |
| async | Parallel (non-blocking) | As soon as downloaded | Unpredictable |
| type="module" | Parallel (non-blocking) | After module dependencies resolve | In document order |
The <base> element sets the base URL for all relative URLs in the document. There can be only one <base> element per document, and it must appear before any element that uses relative URLs:
| 1 | <head> |
| 2 | <base href="https://example.com/docs/"> |
| 3 | <base target="_blank"> |
| 4 | </head> |
| 5 | <!-- Then relative URLs resolve against the base --> |
| 6 | <a href="html/structure">HTML Structure</a> |
| 7 | <!-- resolves to: https://example.com/docs/html/structure --> |
warning
The <style> element allows embedding CSS directly in the document. While external stylesheets are preferred for production, inline styles are useful for critical CSS, quick prototypes, and email templates:
| 1 | <head> |
| 2 | <style> |
| 3 | :root { |
| 4 | --primary: #00FF41; |
| 5 | --bg: #0A0A0A; |
| 6 | --text: #E0E0E0; |
| 7 | } |
| 8 | |
| 9 | * { |
| 10 | margin: 0; |
| 11 | padding: 0; |
| 12 | box-sizing: border-box; |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | font-family: system-ui, -apple-system, sans-serif; |
| 17 | background: var(--bg); |
| 18 | color: var(--text); |
| 19 | line-height: 1.6; |
| 20 | padding: 2rem; |
| 21 | } |
| 22 | |
| 23 | h1 { |
| 24 | color: var(--primary); |
| 25 | font-size: 2rem; |
| 26 | } |
| 27 | </style> |
| 28 | </head> |
The scoped attribute for styles was proposed but never widely implemented. Use CSS Modules, Shadow DOM, or BEM naming conventions for scoping styles instead.
Here is how head-influenced rendering affects the page appearance. The viewport meta and stylesheet control how this content is displayed:
Use this checklist to ensure your head section is fully optimized for search engines:
pro tip
All head elements covered in this guide are supported in every modern browser. The table below covers the resource hints (preload, prefetch, preconnect):
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| Title / Meta / Link | ✓ | ✓ | ✓ | ✓ |
| OG / Twitter meta | ✓ | ✓ | ✓ | ✓ |
| preload | ✓ | ✓ | ✓ | ✓ |
| prefetch | ✓ | ✓ | ✓ | ✓ |
| preconnect | ✓ | ✓ | ✓ | ✓ |
| modulepreload | ✓ | ✓ | — | ✓ |