The <meta> tag provides metadata about the HTML document - information about the page that is not displayed to users but is used by browsers, search engines, and other web services.
Key Characteristics:
- Always placed inside the <head> section
- Self-closing tag (no closing tag required)
- Does not display any content on the page
- Multiple meta tags can be used in one document
- Essential for SEO, responsive design, and browser behavior
Character Encoding:
<!-- Specify character encoding (ALWAYS include this) -->
<meta charset="UTF-8">
<!-- Older syntax (HTML4) -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Viewport (Responsive Design):
<!-- Essential for mobile-responsive websites -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- With additional options -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
SEO Meta Tags:
<!-- Page description (shown in search results) -->
<meta name="description" content="Learn HTML meta tags and their purposes. Complete guide with examples for SEO, responsive design, and browser configuration.">
<!-- Keywords (less important now, but still used) -->
<meta name="keywords" content="HTML, meta tags, SEO, web development, responsive design">
<!-- Author information -->
<meta name="author" content="John Doe">
<!-- Robots (search engine crawling instructions) -->
<meta name="robots" content="index, follow">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="index, follow">
Social Media Meta Tags (Open Graph):
<!-- Facebook Open Graph -->
<meta property="og:title" content="Amazing Article Title">
<meta property="og:description" content="This article will change your life">
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:url" content="https://example.com/article">
<meta property="og:type" content="article">
<meta property="og:site_name" content="My Website">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Amazing Article Title">
<meta name="twitter:description" content="This article will change your life">
<meta name="twitter:image" content="https://example.com/image.jpg">
<meta name="twitter:site" content="@username">
HTTP Equivalent Meta Tags:
<!-- Refresh page after 30 seconds -->
<meta http-equiv="refresh" content="30">
<!-- Redirect after 5 seconds -->
<meta http-equiv="refresh" content="5; url=https://example.com">
<!-- Cache control -->
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
<!-- Content language -->
<meta http-equiv="content-language" content="en-US">
<!-- X-UA-Compatible (IE compatibility) -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Mobile and App Meta Tags:
<!-- iOS Web App -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="App Name">
<!-- Android -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="theme-color" content="#4285f4">
<!-- Microsoft Tiles -->
<meta name="msapplication-TileColor" content="#2b5797">
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
Security Meta Tags:
<!-- Content Security Policy -->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' https://trusted.com">
<!-- Referrer Policy -->
<meta name="referrer" content="no-referrer">
<meta name="referrer" content="origin">
<meta name="referrer" content="strict-origin-when-cross-origin">
Complete HTML Head Example:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Essential Meta Tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- SEO Meta Tags -->
<meta name="description" content="Learn web development with our comprehensive tutorials">
<meta name="keywords" content="web development, HTML, CSS, JavaScript, tutorials">
<meta name="author" content="Tech Academy">
<meta name="robots" content="index, follow">
<!-- Open Graph / Social Media -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://example.com/">
<meta property="og:title" content="Learn Web Development">
<meta property="og:description" content="Master HTML, CSS, and JavaScript">
<meta property="og:image" content="https://example.com/og-image.jpg">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:url" content="https://example.com/">
<meta name="twitter:title" content="Learn Web Development">
<meta name="twitter:description" content="Master HTML, CSS, and JavaScript">
<meta name="twitter:image" content="https://example.com/twitter-image.jpg">
<!-- Mobile -->
<meta name="theme-color" content="#4285f4">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Learn Web Development - Complete Guide</title>
</head>
<body>
<!-- Page content -->
</body>
</html>
Best Practices:
- Always include: charset and viewport meta tags
- SEO: Write unique descriptions (150-160 characters) for each page
- Mobile: Always include viewport meta tag for responsive design
- Social Media: Include Open Graph tags for better link previews
- Keep descriptions relevant: Search engines may penalize misleading metadata
- Update regularly: Keep meta descriptions current with page content
Common Mistakes to Avoid:
<!-- WRONG - Missing viewport -->
<head>
<meta charset="UTF-8">
<title>My Site</title>
</head>
<!-- CORRECT - Include viewport for mobile -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Site</title>
</head>
<!-- WRONG - Description too long -->
<meta name="description" content="This is a very long description that goes on and on with way too much text that search engines will truncate anyway and users won't read the entire thing because it's just too verbose and doesn't get to the point quickly enough.">
<!-- CORRECT - Concise description -->
<meta name="description" content="Learn web development with hands-on tutorials covering HTML, CSS, JavaScript, and modern frameworks.">