👀 Live Preview
Common meta tags using the content attribute (values live in the head, not on screen):
<meta name="description" content="HTML content attribute tutorial.">
<meta name="author" content="Mari Selvan M P">
The content attribute in HTML plays a crucial role in specifying metadata values for certain elements, especially <meta> tags in the document head. It provides a way to define machine-readable information such as page descriptions, authorship, and social sharing data.
Primary use case.
description, author.
Open Graph.
refresh, CSP hints.
meta.content
Use textContent.
contentThe primary purpose of the content attribute is to supply the value half of a metadata pair on a <meta> element. The other half is defined by name, property, or http-equiv. Browsers, search engines, and social platforms read these values from the head — they are not displayed as normal page content.
content does not set button labels or paragraph text. For visible content, write text inside elements or use JavaScript textContent / innerHTML.
Add content to a <meta> element with a text value:
<meta name="description" content="Page summary for search engines.">
<meta property="og:title" content="My Page Title">
<meta http-equiv="refresh" content="30"><meta> elements in the <head>.name, property, or http-equiv.The content attribute accepts various values depending on the type of metadata it describes. Here are some common patterns:
content holds plain text such as a page description, author name, or keywords list.property="og:...", content supplies titles, descriptions, and image URLs for link previews.http-equiv, content may be a refresh interval, charset hint, or policy directive string.<!-- name + content -->
<meta name="description" content="Learn HTML meta tags.">
<!-- property + content (Open Graph) -->
<meta property="og:description" content="Share preview text.">
<!-- http-equiv + content -->
<meta http-equiv="refresh" content="5; url=/home">| Meta Type | Example | Purpose |
|---|---|---|
| Description | name="description" content="..." | Search snippet text |
| Author | name="author" content="..." | Page author |
| Open Graph | property="og:title" content="..." | Social sharing |
| Viewport | name="viewport" content="width=device-width" | Responsive layout |
| Robots | name="robots" content="index, follow" | Crawler hints |
| JavaScript | meta.content = "..." | Update at runtime |
| Element | Supported? | Notes |
|---|---|---|
<meta> | Yes | Primary and standard use |
<link itemprop> | Sometimes | Microdata value on link elements |
<div>, <p> | No | Not a valid HTML attribute |
<button> | No | Put label text inside the button |
CSS ::before | Different | CSS content property is unrelated |
Meta description, Open Graph property, author metadata, and dynamic JavaScript updates.
Common meta tags using the content attribute (values live in the head, not on screen):
<meta name="description" content="HTML content attribute tutorial.">
<meta name="author" content="Mari Selvan M P">For many meta tags, the content attribute allows you to set plain text metadata directly:
<meta name="description" content="A beginner-friendly guide to the HTML content attribute.">Social platforms read property and content pairs for link preview text:
<meta property="og:description" content="Learn how the content attribute sets metadata values.">Let’s explore a simple example of how the content attribute can be used:
<meta name="author" content="Mari Selvan M P">The name attribute identifies what the metadata is (author), and content provides its value. Together they form a complete meta declaration in the document head.
The content attribute can be manipulated dynamically using JavaScript. This enables developers to update metadata based on user interactions or application state. Here’s an example:
<meta name="description" content="Original description.">
<script>
// Dynamically set content for a meta tag
var meta = document.querySelector('meta[name="description"]');
if (meta) meta.content = "New dynamic content!";
</script>In this script, the content of a meta tag with name="description" is dynamically set to New dynamic content! Use this pattern sparingly — search engines primarily read metadata present in the initial HTML response.
name="description" content="..." text helps users choose relevant search results.content to prevent injection issues.Pair name, property, or http-equiv with a content value in the head.
The user agent stores key/value metadata from meta tags.
Search engines, browsers, and social crawlers read content values.
Accurate metadata improves discovery, previews, and crawler understanding.
The content attribute on <meta> is supported in all modern browsers and is fundamental to HTML document metadata.
Every browser parses content on meta elements in the document head.
Bottom line: Use content confidently on meta tags for SEO, viewport, and social metadata.
content on <meta> for descriptions, authors, and OG tagscontent on div, p, or button for visible textcontent with CSS contentcontent attribute when you need to declare or update metadata on meta elements.content values to prevent security vulnerabilities like cross-site scripting (XSS) in other contexts.content is defined for meta tags, not for general body elements.The content attribute provides a powerful way to supply metadata values on HTML <meta> elements. By understanding its usage and incorporating it into your projects, you can improve SEO, social sharing, and document-level configuration.
Remember that content is for metadata — not for visible page copy. Write user-facing text inside your HTML body and reserve content for the head.
contentBookmark these before writing your next meta tags.
Metadata values.
Scopedescription, robots.
SEOOpen Graph.
SocialJS updates.
ScriptUse textContent.
Clarityname, property, or http-equiv.textContent in JavaScript.content is a meta attribute. CSS content inserts generated text in ::before / ::after pseudo-elements.document.querySelector('meta[name=description]').content = '...' or setAttribute('content', '...').Practice the content attribute with meta description, Open Graph, and JavaScript examples in the Try It editor.
4 people found this page helpful