Lesson 25 +10 XP

Document Metadata

The <head> is the page's brain. Let's learn everything it can hold!

meta: information about the page

<meta> gives the browser extra info. Common uses:

Code

html
<meta charset="utf-8">
<meta name="description" content="A short description of the page">
<meta name="viewport" content="width=device-width, initial-scale=1">
  • charset=&quot;utf-8&quot;: makes sure all characters (like emoji!) display correctly.
  • description: the little text shown under your page in search results.
  • viewport: makes the page fit phones properly.

More meta names

  • theme-color: the color of the browser tab bar on phones.
  • robots: tells search engines what to index (e.g. noindex).
  • color-scheme: says the page supports light/dark.
  • referrer: what info gets sent with links to other sites.
  • text-scale: controls automatic text resizing (new).
  • responsive-embedded-sizing: extra info for embedded content (new).
Code

html
<meta name="theme-color" content="#4caf50">
<meta name="robots" content="noindex">

meta http-equiv

The http-equiv meta is a way to fake some HTTP response headers inside the page. The most common one:

Code

html
<meta http-equiv="refresh" content="5; url=https://example.com">

That redirects to example.com after 5 seconds. (Use with care: redirects annoy people!)

title: the tab text

&lt;title&gt; shows on the browser tab and in search results. One per page!

Code

html
<title>My Awesome Page</title>

link: connections to other files

&lt;link&gt; links your page to other files. Most often, a stylesheet:

Code

html
<link rel="stylesheet" href="styles.css">

Other rel values:

  • rel=&quot;icon&quot;: the little icon in the tab.
  • rel=&quot;preconnect&quot;: warm up a connection (faster loading).
  • rel=&quot;preload&quot;: load an important file early.
  • rel=&quot;prefetch&quot;: fetch a file you'll need soon (like the next page).
  • rel=&quot;prerender&quot;: even pre-build the next page in the background.
  • rel=&quot;modulepreload&quot;: preload a JavaScript module.
  • rel=&quot;dns-prefetch&quot;: look up a domain early.
  • rel=&quot;manifest&quot;: the web app manifest for installing as an app.
  • rel=&quot;alternate stylesheet&quot;: a different style sheet you can switch to.
Code

html
<link rel="icon" href="favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preload" href="hero.jpg" as="image">

style: CSS right in the page

&lt;style&gt; holds CSS directly inside the document (instead of a separate file).

Code

html
<style>
  body { font-family: sans-serif; }
</style>

base: a home base for links

&lt;base&gt; sets a default base URL for all relative links on the page.

Code

html
<base href="https://example.com/">

Now &lt;a href=&quot;about.html&quot;&gt; points to https://example.com/about.html.

TL;DR

  • &lt;meta&gt; holds page info: charset, description, viewport, and more.
  • &lt;title&gt; is the tab/search title.
  • &lt;link&gt; connects stylesheets, icons, and preloads.
  • &lt;style&gt; holds inline CSS.
  • &lt;base&gt; sets a base URL for relative links.
  • All of these live in &lt;head&gt;.