Open In App

HTML <head> Tag

Improve
Improve
Like Article
Like
Save
Share
Report

The HTML <head> Tag is used to define the head portion of the document which contains information related to the document. Metadata refers to data about an HTML document. Unlike other content, metadata is not typically displayed on the page itself.

The <head> element is a container for metadata tag and contains other head elements such as:

TagDescription
<title>Defines the title of the document.
<meta>Provides metadata about the HTML document.
<link>Links external resources such as stylesheets.
<style>Defines internal CSS styles.
<link>Connects external resources like stylesheets.
<script>Embeds or links to scripts.
<noscript>Defines content if scripting is not supported.

Note:

  • In HTML 4, the <head> element was mandatory but in HTML5, the <head> element can be omitted.
  • The <head> Tag supports the Global Attribute in HTML.

Syntax:

<head>
      <title>Title of the document</title>
</head>

Example 1: The below example head containing title. Body holds a paragraph. Basic webpage structure for content presentation.

HTML
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>HTML Head Tag</title>
    </head>

    <body>
        <p>
            GeeksforGeeks is a portal for geeks.
        </p>
    </body>
</html>

Output:

Example 2 : The below example illustrates the usage of style tag inside head tag.

HTML
<!DOCTYPE html>
<html>
    <head>
        <style>
            body {
                background: skyblue;
            }

            h1 {
                color: red;
            }

            p {
                color: blue;
            }
        </style>
    </head>

    <body>
        <h1>GeeksforGeeks</h1>
        <p>It is a portal for geeks.</p>
    </body>
</html>

Output:

Example 3: The below example illustrates the usage of link tag inside head tag.

HTML
<!DOCTYPE html>

<html>
    <head>
        <link
            rel="stylesheet"
            type="text/css"
            href="mystyle.css"
        />
    </head>

    <body>
        <h1>GeeksforGeeks</h1>
        <p>It is a portal for geeks.</p>
    </body>
</html>

Output:

Supported Browsers



Last Updated : 26 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads