πŸ“Œ What is the HTML <head> Tag ?

πŸ”Ή 1. General Definition

The <head> tag contains background information (metadata) about an HTML page.

  1. πŸ‘‰ This information is usually not visible to users, but it is used by:

  2. browsers
  3. search engines
  4. social media platforms
  1. πŸ“Œ Important points:

  2. The <head> tag is located between <html> and <body>
  3. There is only one <head> tag in an HTML document

πŸ”Ή 2. Tags Used Inside <head>

Below are the most commonly used tags inside <head>:

🏷️<title>

Defines the title of the page and appears in the browser tab.

HTML
<title>My Page</title>

🏷️<link>

Used to connect external files (usually CSS).

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

🏷️<style>

Used to write CSS directly within the page.

HTML

<style>
    h1 {
        color: red;
    }
</style>
                

🏷️<script>

Used to add JavaScript code or link external JS files.

HTML
<script src="app.js"></script>

or

HTML

<script>
    console.log("Hello");
</script>
                

🏷️<base>

Specifies a base URL for all relative links.

HTML
<base href="https://www.example.com/" target="_blank">

πŸ”Ή 3. Example HTML Document

Below are the most commonly used tags inside <head>:

HTML

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="description" content="This is my sample page">
        <meta name="keywords" content="HTML, head, meta">
        <meta name="author" content="Ahmet Yazar">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Sample Page</title>
        <link rel="stylesheet" href="style.css">
        <style>
            body {
                background-color: lightyellow;
            }
            h1 {
                color: darkblue;
            }
        </style>
        <script>
            console.log("The page is loading...");
        </script>
        <base href="https://www.example.com/" target="_blank">
    </head>
    <body>
        <h1>Hello!</h1>
        <p>This is a test page.</p>
    </body>
</html>
                

πŸ”Ή 4. Explanation of the Example

  1. Basic Features :

  2. <meta charset="UTF-8"> β†’ sets the character encoding
  3. <meta> tags β†’ provide description, keywords, and author information
  4. viewport β†’ ensures the page is responsive on mobile devices
  5. <link> β†’ connects an external CSS file
  6. style β†’ defines internal styles
  7. script β†’ runs JavaScript
  8. base β†’ defines the base URL for relative links

πŸ”Ή 5. Why is <head> Important?

πŸ” Important for SEO

  1. The page title and description appear in search results

🎨 Essential for design and appearance

  1. CSS files are defined here

βš™οΈ Controls page behavior

  1. JavaScript is loaded here

πŸ“± Ensures mobile compatibility

  1. The viewport setting makes the page responsive
  • 🎯 Quick Note

  • <head> β†’ contains the background information of the page
  • Not visible to users but critical for how the page works
  • CSS, JavaScript, metadata, and the page title are defined here