The <head> element is a container for metadata (data about data) and is placed between the opening <html> tag and the <body> tag. Metadata is not rendered directly on the browser viewport; instead, it defines critical document characteristics such as character encoding, title for search engines, links to stylesheets, viewport configurations for mobile responsiveness, and Open Graph social sharing previews.
The HTML <head> can house the following primary elements:
<title>: Defines the title of the document shown on browser tabs and search engine result pages (SERPs).<meta>: Provides structured machine-readable metadata (charset, description, viewport, robots).<link>: Establishes relationships with external resources (CSS stylesheets, favicons, canonical URLs).<style>: Contains internal Cascading Style Sheets (CSS).<script>: Links or embeds client-side JavaScript code.<base>: Defines a base URL for all relative links in the document.The <title> element is mandatory in every valid HTML document. It serves three vital purposes: it displays as the browser tab name, forms the headline clickable link in Google Search results, and provides the default name when a user bookmarks the page.
<title>BCA Web Programming Tutorial » Veewom</title>
The <meta> tag is an empty (void) element that conveys instructions to web browsers and search engine crawlers. Common meta declarations include:
| Meta Directive | Example Syntax | Purpose & Best Practice |
|---|---|---|
| Character Encoding | <meta charset="UTF-8"> |
Specifies UTF-8 encoding. Covers nearly all human languages and prevents garbled character display (mojibake). |
| Responsive Viewport | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
Mandatory for Mobile SEO: Ensures the webpage scales correctly to the device screen width instead of zooming out. |
| SEO Description | <meta name="description" content="..."> |
Provides an editorial summary (150-160 characters) shown as the search snippet on Google. |
| Robots Directives | <meta name="robots" content="index, follow"> |
Instructs search engine bots whether to index the page and follow its outbound links. |
| Author | <meta name="author" content="Veewom Learning"> |
Credits the author or publishing organization. |
The <link> element connects the current document to external stylesheets, icons, and canonical URLs:
<!-- Linking an external CSS stylesheet -->
<link rel="stylesheet" href="css/theme.css" type="text/css">
<!-- Website Favicon -->
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<!-- Canonical Link (Prevents duplicate content SEO penalties) -->
<link rel="canonical" href="https://veewom.com/html/head.htm">
The <style> tag embeds internal CSS styling applied directly to the document:
<style>
body { font-family: Arial, sans-serif; background-color: #fdfdfd; }
.state { background-color: #5b2c6f; color: white; padding: 15px; border-radius: 4px; }
</style>
Used to link or embed client-side JavaScript. Modern best practice utilizes the defer attribute when placed in the head to avoid blocking DOM parsing:
<script src="js/main.js" defer></script>
The <base> element defines the default target URL and target window for all relative URLs in the document:
<base href="https://veewom.com/" target="_blank">
<!-- If you later write <a href="courses.htm">, it resolves to https://veewom.com/courses.htm and opens in a new tab -->
When users share your blog post or website on WhatsApp, Facebook, LinkedIn, or Twitter/X, social platforms crawl your <head> tags for Open Graph metadata to build attractive rich link preview cards:
<!-- Facebook / WhatsApp / LinkedIn Open Graph -->
<meta property="og:title" content="HTML Head Tutorial & Meta Tags Guide">
<meta property="og:description" content="Master the HTML head tag, viewport, charset, and SEO metadata.">
<meta property="og:image" content="https://veewom.com/images/html-head-banner.jpg">
<meta property="og:url" content="https://veewom.com/html/head.htm">
<meta property="og:type" content="article">
<!-- Twitter / X Card Meta -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="HTML Head Tutorial & Meta Tags Guide">
<meta name="twitter:description" content="Learn viewport, charset, and SEO tags with practical examples.">
<meta name="twitter:image" content="https://veewom.com/images/html-head-banner.jpg">
Assignment Scenario: Construct a complete, modern HTML5 <head> block meeting all current web standards: UTF-8 encoding, responsive viewport, SEO description, canonical URL, Google Fonts preconnect, and Open Graph cards.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 1. Character Encoding: Must be within first 1024 bytes -->
<meta charset="UTF-8">
<!-- 2. Mobile Responsive Viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 3. Primary Document Title & SEO Meta -->
<title>BCA Semester 1 Web Design Tutorial » Veewom</title>
<meta name="description" content="Complete university syllabus notes and practical lab code for BCA students learning HTML5.">
<meta name="author" content="Veewom Academy">
<meta name="robots" content="index, follow">
<!-- 4. Canonical Link -->
<link rel="canonical" href="https://veewom.com/bca/web-design.htm">
<!-- 5. Favicon -->
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<!-- 6. Performance Optimization: Preconnect Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<!-- 7. Stylesheet and Deferred Script -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/main.js" defer></script>
</head>
<body>
<h1>Production-Ready Head Template Loaded Successfully!</h1>
</body>
</html>
<head> element acts as the metadata container of the HTML document. It contains instructions and definitions intended for the browser engine, web crawlers, and external systems rather than visible body content. It holds the title, character encoding, linked stylesheets, scripts, and responsive viewport settings.
<meta name="viewport" content="width=device-width, initial-scale=1.0">, mobile browsers assume the page was built for desktop (980px width) and render it zoomed out with microscopic text. The viewport tag instructs mobile screens to match the screen's physical pixel width (device-width) and set initial zoom to 100% (initial-scale=1.0).
<base> tag sets an explicit base URL (and target window) for all subsequent relative URLs on the webpage. Precaution: There can be at most one <base> tag per document, and it must precede any tags that refer to external sources (like stylesheets or scripts); otherwise, relative paths might resolve to the wrong domain.
<meta> tag contains information purely through its attributes (such as name, content, and charset). It has no inner text or nested HTML children, so it does not possess a closing </meta> tag in HTML5.
?ref=twitter), the canonical tag declares the master authoritative URL to search engines, preventing duplicate content SEO penalties.
<title> is omitted, the HTML document fails W3C validation. The browser will fall back to displaying the raw file name (e.g., index.html) or server URL in the tab, and search engines like Google will generate an automated guess for the title, severely reducing click-through rates.
<head> ensures the browser identifies the text encoding before processing non-ASCII characters in the <title> or metadata.
<head> is invalid HTML syntax. Most modern browsers will prematurely terminate the <head> and forcefully open the <body>, which can break CSS stylesheet and script execution order.