Favorites

The Head Element - HTML Tutorial

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Visitors never see the head of your page directly, but it does important work behind the scenes. It tells browsers how to read and display your page, tells search engines what the page is about and links in files such as style sheets.

Here's a head with everything a typical page needs:

Example: A Complete Head
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Pancake Recipes - Corner Cafe</title>
    <meta name="description" content="Three easy pancake recipes from the Corner Cafe kitchen, with step-by-step instructions.">
    <link rel="icon" href="favicon.png">
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    ...
  </body>
</html>

Let's look at each line.

Character Encoding

<meta charset="utf-8">

You met this in Structure. It tells the browser that your file uses UTF-8, so every letter and symbol displays correctly. Put it first in the head, because the browser needs to know the encoding before it reads the rest of the page.

The Viewport

<meta name="viewport" content="width=device-width, initial-scale=1">

Without this line, phones pretend to have a wide desktop screen and shrink your page down to fit, leaving tiny, hard-to-read text. The viewport tag tells mobile browsers to use the real width of the device instead. Include it on every page. You'll see why it matters in Responsive Design Basics.

The Title

<title>Pancake Recipes - Corner Cafe</title>

The title appears in the browser tab, in bookmarks and as the headline in search results. A good title:

  • describes what's on this particular page
  • is different on every page of your site
  • puts the most important words first, often followed by the site name
  • is short enough to read at a glance, roughly 60 characters or fewer

The Description

<meta name="description" content="Three easy pancake recipes from the Corner Cafe kitchen, with step-by-step instructions.">

Search engines often show this text under your title in search results. Write a sentence or two, about 150 characters, that summarizes the page and makes people want to click. Like the title, it should be different on every page.

The Icon

<link rel="icon" href="favicon.png">

This sets the small icon, called a favicon, that appears in the browser tab next to your title. A square PNG image works well. SVG icons are also widely supported.

Style Sheets

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

This links a separate CSS file to your page. You'll learn all about it in Style Sheets. For now, just remember that style sheet links belong in the head.

Your Starter Template

From now on, use this as the starting point for every new page you create. Save it as template.html in your practice folder and make a copy whenever you start something new:

Example: Starter Template
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Page title</title>
  </head>
  <body>

  </body>
</html>
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee