HTML head Tag: How to Include Metadata and Links in head

html head tag

The HTML head tag contains information and loads tools for the web page.

What Is the <head> Tag in HTML?

The <head> tag is placed above the <body>. It tells the browser how to process the page and does not display on the screen.

It contains these tags:

  • The page title
  • The metadata
  • Scripts,
  • Styles

This data loads before the browser shows any content.

Here is the main tag:

<head><!-- This is the hidden part--></head>

All elements inside define how the page loads and works.

The page may lose its styles or scripts without a <head> and it can also show incorrect symbols.

You can place it before the <body> so the browser reads the rules first.

Here is an example:

<head>
  <title>My Page</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="/path/css/style.css">
  <script src="/file/path/js/main.js"></script>
</head>

Start with the title. Then use meta tags for encoding and layout. After that, link styles or scripts.

Elements Inside <head> Tag in HTML

The <title> Element

The title shows on the browser tab. It also tells search engines what the page covers. It appears inside the <head> tag.

Here is an example:

<head>
  <title>The web page title</title>
</head>

The <meta> Element

Meta tags set the text format and page description. Some control how bots read the site. You can also tell browsers what not to show.

Here is an example of how you can write them inside the <head> tag:

<head>
    <!-- Sets the character encoding (text format) -->
    <meta charset="UTF-8">
    
    <!-- Provides the page description -->
    <meta name="description" content="This is a tutorial on HTML.">
    
    <!-- Controls how search engines index the page -->
    <meta name="robots" content="noindex, nofollow">
    
    <!-- Prevents browsers from displaying the page in a frame -->
    <meta http-equiv="X-Frame-Options" content="deny">
</head>

This tag loads styles from an outside file. You can keep your CSS rules in a separate file and call it here.

Here is an example:

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

The <style> Element

Write CSS rules inside the head with this tag in HTML. This helps when the page only needs a few small rules.

For example:

<head>
  <style>
    body {
      background-color: #f0f0f0;
    }
    p {
      color: #333;
    }
  </style>
</head>

The <script> Element

Use this to load a JavaScript file or write one in the head. You can control when it runs with async or defer.

Load external script with defer:

<script src="/js/script.js" defer></script>

Write script inline:

<script>
  console.log('Hello, world!');
</script>

Viewport Meta Tag for Responsive Design

Phones and tablets need the page to fit their screens. You can add a viewport tag to control this.

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

This tag tells the browser to match the screen size. It also sets the zoom. The mobile users may see the full site zoomed out without it.

Examples

Simple Head with Title and Charset

<head>
  <title>Start Page</title>
  <meta charset="UTF-8">
</head>

This sets the page title and tells the browser to read text with UTF-8. You need both lines in almost every page.

Full Setup with Style and Script

<head>
  <title>Site Page</title>
  <link rel="stylesheet" href="style.css">
  <script src="/main/path/site.js" defer></script>
</head>

This head loads an outside style and a script. The script runs after the page loads so nothing breaks.

Head with SEO Tags and Icon

<head>
  <title>Head Guide</title>
  <meta name="description" content="This page shows the HTML head tag.">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" href="/icons/icon.png" type="image/png">
  <link rel="stylesheet" href="/css/layout.css">
</head>

This example shows a full head with the following:

  • Title
  • A short page description
  • Mobile screen rules
  • A tab icon
  • Style rules.

Each line helps the browser read and show the page the right way.

Wrapping Up

This guide showed how the <head> tag works. It helps browsers load styles and set the page name. You also saw how meta tags control layout and search. The viewport and icon help on phones and tabs.

Here is a quick recap:

  • Use <head> to set up the page
  • Add <title> to label the browser tab
  • Use <meta> to give the layout and SEO rules
  • Load CSS with <link> or write it inside <style>

FAQs

What is the purpose of the <head> tag in HTML?

The <head> tag contains metadata and settings for the HTML document. It includes elements like <title>, <meta>, <link>, and <script>. These elements help define the document’s title, character encoding, linked CSS or JS files, and viewport settings for responsive design.

<head>
  <title>My Page</title>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="style.css">
</head>

What tags should go inside the <head> section?

The <head> section includes non-visible elements like:
  • <title> – Sets the page title
  • <meta> – Defines metadata like description and viewport
  • <link> – Links external stylesheets or icons
  • <style> – Adds internal CSS
  • <script> – Loads scripts (optionally with defer or async)

How does the <meta viewport> tag affect mobile design?

The <meta viewport> tag tells browsers how to adjust the page’s layout on mobile devices. Without it, pages appear zoomed out. It improves responsiveness.

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

Can you add CSS inside the <head> tag?

Yes, you can add internal CSS using the <style> tag or link an external file with <link>.

<style>
  body { background: #f0f0f0; }
</style>

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

Similar Reads

How to Use HTML div Tag – Examples & Group Content

In this article, you will cover how to use div tag in HTML layout. It offers beginner to advanced code…

HTML Header Tag: The Complete Guide with Examples

The header tag defines the top part of a page or a section in HTML. It usually holds a heading…

HTML List Tag: Understand the ul, ol, and dl Lists

HTML has three main list tags: <ul>, <ol>, and <dl>. Each one shows a different kind of group. In this…

HTML Document Structure Guide for Beginners

A web page must follow a clear structure so browsers can read and show it correctly. This guide helps you…

HTML audio Tag: How to Embed and Control Sound in Pages

The audio tag adds sound to web pages without plugins. It gives you control to play, pause, loop, or mute…

HTML Breadcrumb Navigation Guide for Beginners

The breadcrumb in HTML shows a path through a site and marks the place of a page inside it. It…

HTML Legend Tag: How it Works in Fieldset Tag with Examples

In this article, you will learn how HTML legend works in the fieldset tag with examples. HTML fieldset and legend…

HTML5 New Elements with Examples

HTML5 gave the web new elements that describe content with more meaning. Developers now use these elements to build pages…

The hidden Attribute in HTML: How it Works with Examples

The HTML hidden attribute hides elements from users but keeps them in the code. You can use it when you…

HTML ins Tag: How to Mark Inserted Text in a Document

The <ins> tag in HTML shows text that the author added after the original content. This helps readers know what…

Previous Article

HTML title Attribute: How it Works with Examples

Next Article

HTML Form novalidate Attribute: How it Works with Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.