Skip to main content

Advanced HTML

HTML Head Element Tags

Written by Updated HTML Head Element Tags exercises

The head of an HTML page holds information about the page rather than content on it: its title, the character set, the mobile viewport, the description for Google, the CSS and scripts to load. None of it appears on the page itself, but all of it matters.

The <head> goes right after <html> and before <body>. The tag itself is described in the head tag.

Basic Syntax

html

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My Web Page</title>
  <meta charset="UTF-8">
  <meta name="description" content="Learn HTML Head Elements">
  <meta name="keywords" content="HTML, CSS, JavaScript">
  <meta name="author" content="Your Name">
  <link rel="stylesheet" href="/samples/example.css">
  <script src="/samples/script.js"></script>
</head>
<body>
  <h1>Welcome to My Web Page</h1>
</body>
</html>

This page has a title, a character set and a viewport line in its head, and a heading in its body. Only the heading shows on the page; the title appears in the browser tab.

Tags that go in the head

TagWhat it is forExample
<title>The page name in the tab and in search results<title>HTML Tutorial</title>
<meta>Information such as character set, viewport and description<meta name="description" content="...">
<link>Connects a stylesheet, icon or other file<link rel="stylesheet" href="style.css">
<style>CSS written in the page<style>body { margin: 0; }</style>
<script>JavaScript, written in or loaded from a file<script src="main.js" defer></script>
<base>The base address for all relative links<base href="https://example.com/">
<noscript>Content for browsers with JavaScript turned off<noscript>...</noscript>

Important Meta Tags

Character Encoding

html

<meta charset="UTF-8">

Put it first in the head, so every character, from accented letters to emojis, displays correctly.

Viewport (for mobile responsiveness)

html

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

Without it, phones show the page zoomed out as if on a desktop. Every page needs it.

SEO Metadata

html

<meta name="description" content="Learn HTML Head Tags with examples">
<meta name="keywords" content="HTML, Head, Meta Tags, Tutorial">
<meta name="author" content="HTML5 & CSS3">

The description may appear under your title in Google. The keywords line is ignored by Google and Bing. Details are in HTML Meta Tags for SEO.

Social Media Sharing (Open Graph Tags)

html

<meta property="og:title" content="HTML Head Tags Tutorial">
<meta property="og:description" content="Learn how to use HTML head elements effectively">
<meta property="og:image" content="thumbnail.jpg">
<meta property="og:url" content="https://html5andcss3.org/html-head-tags">

These control the title, text and image shown when someone shares your link on social media or in chat apps.

Example: Complete Head Section

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Learn all HTML Head Tags with examples">
  <meta name="keywords" content="HTML, Head, Meta, SEO, CSS">
  <meta name="author" content="HTML5 & CSS3">
  <title>HTML Head Tags Tutorial</title>
  <link rel="stylesheet" href="/samples/example.css">
  <link rel="icon" href="favicon.ico">
  <script src="/samples/script.js"></script>
</head>
<body>
  <h1>Welcome to the HTML Head Tags Tutorial</h1>
</body>
</html>

Good to know

  • The order matters a little: charset first, then viewport and the title, then everything else.
  • Load CSS in the head, so the page does not appear unstyled for a moment. Scripts can go there too, with defer.
  • Anything you put in the head that belongs in the body, like a paragraph, is moved into the body by the browser.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML Head Element Tags exercises

Name on the tab

Write a head with the title Garden Club, the name on the browser tab.

Result

Check your answer to see it here.