- HTML Tutorial
- HTML Introduction
- HTML Editors
- HTML Basic
- HTML Comments
- HTML Elements
- HTML Attributes
- HTML Id & Classes
- HTML Skeletal Tags
- HTML Heading Tags
- HTML Paragraph Tag
- HTML Line Break Tag
- HTML Pre Tag
- HTML Anchor Tag
- HTML Image Tag
- HTML Horizontal Line Tag
- HTML Inline & Block
- HTML Inline
- HTML Block
- HTML LInks
- HTML Images
- HTML Formatting
- HTML Head
- HTML Head
- HTML Title
- HTML Meta Elements
- HTML Favicon
- HTML Style
- HTML List
- HTML Lists
- HTML Unordered List
- HTML Ordered List
- HTML Description List
- HTML Table
- HTML Tables
- HTML Table Headers
- HTML Table Styling
- HTML Table Colgroup
- HTML Form
- HTML Forms
- HTML Form Elements
- HTML Form Attributes
- HTML Input Types
- HTML Input Attributes
- HTML Form Actions
- HTML Semantic
- HTML Semantics
- HTML Graphics & Media
- HTML Canvas
- HTML SVG
- HTML Video & Audio
- HTML Plug-ins
- iFrames in HTML
- HTML Miscellaneous Tags
- HTML Code Tag
- HTML Entities
- HTML Quotation
- HTML Global Attributes
- HTML Obsolete Tags
- HTML Emojis
- HTML Symbols
- HTML Events
- HTML Colors
HTML Head
In HTML, the <head> element serves as the "brain" of your web page. While the <body> contains everything your visitors see (like text, images, and buttons), the <head> contains metadata information about the document that helps browsers, search engines, and social media platforms understand and display your site correctly.
Think of the <head> as the behind-the-scenes configuration for your project. Without it, your site wouldn't know which font to use, how to scale on a mobile phone, or what title to show in a Google search result.
<head> tag is invisible to the user on the actual page, with the exception of the <title> and the favicon in the browser tab.
Here is a breakdown of a standard, production-ready <head> section:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 1. Character Encoding -->
<meta charset="UTF-8">
<!-- 2. Mobile Responsiveness -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 3. SEO Metadata -->
<meta name="description" content="This is a description of my web page for search engines.">
<meta name="keywords" content="HTML, CSS, JavaScript, Web Development">
<!-- 4. Page Title -->
<title>My Portfolio | Professional Web Developer</title>
<!-- 5. External Resources -->
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<!-- Content of the HTML document goes here -->
</body>
</html>
Key Elements Explained
To write modern, professional HTML, you need to understand exactly what these tags are doing under the hood:
- <meta charset="UTF-8">: This tells the browser which character set to use. UTF-8 is the industry standard because it supports almost all characters and symbols in the world, preventing "weird" symbols from appearing where your text should be.
- <title>: This is one of the most important tags for SEO (Search Engine Optimization). It appears as the name of the tab in your browser and is the primary link text shown in search results.
- <meta name="viewport">: Without this, your website will look like a tiny, zoomed-out version of a desktop site on a smartphone. This tag ensures your site scales properly on mobile devices.
- <link rel="stylesheet">: This is how you connect your CSS file to your HTML. It tells the browser, "Go find this file and use it to style this page."
<meta charset="UTF-8"> tag as the very first element inside the <head>. This ensures the browser knows how to read the rest of your code immediately.
<h1> or <p> tags, inside the <head>. This is syntactically incorrect; all visible content must live inside the <body>.
Real-World Example: Social Media Preview
Ever wonder how a link on Twitter or Slack shows a nice preview image and a summary? This is done using "Open Graph" meta tags inside the <head>. If you are building a professional site, you will likely add tags like this:
<meta property="og:title" content="My Amazing Project">
<meta property="og:image" content="https://example.com/preview-image.jpg">
<meta property="og:url" content="https://example.com">
viewport meta tag, Google may penalize your site's search ranking because it won't be considered "mobile-friendly."
By mastering the <head> section, you ensure your website is fast, searchable, and works perfectly across all devices. It is the foundation upon which the rest of your front-end code is built.