HTML
π What is the HTML <head> Tag ?
πΉ 1. General Definition
The <head> tag contains background information (metadata) about an HTML page.
π This information is usually not visible to users, but it is used by:
- browsers
- search engines
- social media platforms
π Important points:
- The
<head>tag is located between<html>and<body> - 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
Basic Features :
-
<meta charset="UTF-8">β sets the character encoding -
<meta>tags β provide description, keywords, and author information - viewport β ensures the page is responsive on mobile devices
-
<link>β connects an external CSS file - style β defines internal styles
- script β runs JavaScript
- base β defines the base URL for relative links
πΉ 5. Why is <head> Important?
π Important for SEO
- The page title and description appear in search results
π¨ Essential for design and appearance
- CSS files are defined here
βοΈ Controls page behavior
- JavaScript is loaded here
π± Ensures mobile compatibility
- 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
