HTML

HTML Metadata: Syntax, Usage, and Examples

HTML metadata provides information about a web page, helping browsers, search engines, and social media platforms understand its content. Developers typically include metadata within the <head> section of an HTML document, where it remains invisible on the page itself.

How to Use HTML Metadata

To add HTML metadata, use <meta> tags and other elements inside the <head> section. Here’s an example:


<head>
    <meta charset="UTF-8">
    <meta name="description" content="Learn about HTML metadata and how it helps your website.">
    <meta name="keywords" content="HTML, metadata, SEO, web development">
    <meta name="author" content="John Doe">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Metadata Guide</title>
</head>

  • <meta charset="UTF-8"> defines the document’s character encoding.
  • <meta name="description"> provides a short summary for search engines.
  • <meta name="keywords"> lists relevant terms (though modern SEO rarely uses this).
  • <meta name="author"> specifies the content’s creator.
  • <meta name="viewport"> ensures responsiveness on different screen sizes.

When to Use HTML Metadata

Developers use metadata to structure web pages properly. It improves:

1. Search Engine Optimization (SEO)

Metadata affects how search engines display a webpage in search results. The meta description helps search engines and users understand the page content.

<meta name="description" content="A complete guide to HTML metadata for beginners and developers.">

2. Social Media Sharing

Metadata tags like Open Graph (og:) and Twitter Cards define how a webpage appears when shared on social platforms.

<meta property="og:title" content="HTML Metadata Guide">
<meta property="og:description" content="Everything you need to know about metadata in HTML.">
<meta property="og:image" content="https://example.com/metadata-guide.jpg">

3. Mobile Responsiveness

The viewport meta tag ensures proper display on mobile devices.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Examples of HTML Metadata

Example 1: Basic SEO Metadata

This example includes metadata that improves search engine visibility.

<head>
    <title>What is Metadata in HTML?</title>
    <meta name="description" content="A guide to HTML metadata, including its syntax and best practices.">
    <meta name="keywords" content="HTML metadata, metadata in HTML, what is metadata in HTML">
</head>

Example 2: Social Media Metadata

Open Graph metadata ensures that a webpage looks appealing when shared on Facebook and LinkedIn.

<meta property="og:title" content="HTML Metadata Explained">
<meta property="og:description" content="Learn how metadata in HTML affects SEO and social media previews.">
<meta property="og:image" content="https://example.com/html-metadata.jpg">
<meta property="og:url" content="https://example.com/html-metadata">

Example 3: Preventing Search Engine Indexing

To prevent search engines from indexing a page, use the robots meta tag.

<meta name="robots" content="noindex, nofollow">

Learn More About HTML Metadata

1. Metadata Keywords in HTML

Although developers once used <meta name="keywords"> for SEO, search engines now ignore it due to keyword stuffing abuses. However, it may still be useful for internal site search.

2. Metadata Tags in HTML

Metadata tags go beyond descriptions and keywords. Additional metadata tags include:

  • <meta http-equiv="refresh" content="5; URL=https://example.com"> (Redirects after 5 seconds)
  • <meta name="theme-color" content="#000000"> (Sets the browser tab color on mobile)

3. HTML Header Metadata and Performance

Metadata also improves performance. For example, cache control settings help browsers manage page loading efficiency.

<meta http-equiv="cache-control" content="no-cache">

Optimizing HTML metadata enhances SEO, performance, and user experience. By structuring metadata correctly, developers can improve a webpage’s ranking, social media visibility, and responsiveness.

Learn HTML for Free
Start learning now
button icon
To advance beyond this tutorial and learn HTML by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH