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

HTML Span Tag: Inline Container Explained

The HTML span tag acts as a simple container for inline text or other inline elements. It groups text and…

HTML Select Tag: How Combo Box & Option Work with Examples

HTML select tag and option tags let users pick values in a form. You use them to create dropdowns. The…

HTML Document Structure: How to Create DOCTYPE in HTML

The DOCTYPE ensures that your HTML is readable by browsers and ensures that pages follow modern standards. Understand the DOCTYPE…

HTML time Tag: Representing Dates and Times

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…

HTML hr Tag: Horizontal Rules

The <hr> tag in HTML gives you a fast way to split content with a clean horizontal line. You may…

HTML Form Validation Attributes

HTML form validation attributes help you check the form data before it reaches the server. What Are HTML Form Validation…

HTML samp Tag: How to Show Sample Program Output

The HTML samp tag shows the result of a computer program or command. It helps readers know which text came…

HTML Textarea Tag: How it Works with Examples

The HTML textarea tag gives users space to enter longer messages. This element helps build forms that accept feedback, comments,…

HTML Element: Everything You Need To Know with Examples

An HTML element builds every part of a web page. It holds the text or block you want the browser…

HTML Input Tag: How It Works, Types & Examples

The HTML input tag lets you add fields for user data in forms. You use this tag to collect text,…

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.