HTML - Meta Tags
Examples and Code Snippets
Basic Meta Tags Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="John Doe">
<meta name="description" content="A sample webpage showing meta tags in HTML.">
<meta name="keywords" content="HTML, meta tags, example">
<title>Meta Tags Example</title>
</head>
<body>
<h1>Welcome to my webpage!</h1>
<p>This is an example of how to use meta tags in an HTML document.</p>
</body>
</html>
This shows a basic HTML structure with the charset
, viewport
, author
, description
, and keywords
meta tags in the <head>
section.
Social Media Meta Tags Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Social Media Meta Tags Example</title>
<!-- Open Graph Meta Tags -->
<meta property="og:title" content="My Webpage Title">
<meta property="og:description" content="A brief description of my webpage.">
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:url" content="https://example.com">
<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="My Webpage Title">
<meta name="twitter:description" content="A brief description of my webpage.">
<meta name="twitter:image" content="https://example.com/image.jpg">
</head>
<body>
<h1>Social Media Meta Tags Example</h1>
<p>This webpage is optimized for sharing on social media platforms.</p>
</body>
</html>
This shows how to use Open Graph and Twitter Card meta tags to optimize a webpage for social media sharing. The meta tags provide information about the webpage's title, description, image, and URL, which will be displayed when the webpage is shared on platforms like Facebook and Twitter.
HTTP Headers and Robots Meta Tags Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTTP Headers and Robots Meta Tags Example</title>
<!-- HTTP Header Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="expires" content="Wed, 21 Oct 2025 07:28:00 GMT">
<!-- Robots Meta Tag -->
<meta name="robots" content="index, follow">
</head>
<body>
<h1>HTTP Headers and Robots Meta Tags Example</h1>
<p>This webpage uses HTTP header meta tags to control content type and expiration, and the robots meta tag to allow search engine indexing and link following.</p>
</body>
</html>
This shows how to use HTTP header meta tags to control the content type, character encoding, and expiration of a webpage. The Content-Type
meta tag specifies the content type and character encoding, while the expires
meta tag sets an expiration date for the webpage. The robots
meta tag is also used to allow search engines to index the webpage and follow its links.
These code snippets show how to use various types of meta tags in an HTML document to give information about the webpage, control its behavior, and optimize it for search engines and social media sharing.
Social Media
Meta tags can also be used to optimize webpages for social media sharing. These tags control how the webpage appears when shared on platforms like Facebook and Twitter.
Open Graph (OG) tags are used by Facebook and other social media platforms to grab information about the webpage. Some examples of OG tags are:
<meta property="og:title" content="My Webpage Title">
<meta property="og:description" content="A brief description of my webpage.">
<meta property="og:image" content="https://example.com/image.jpg">
Twitter Card tags are similar to Open Graph tags but are specific to Twitter. They allow you to control how your webpage appears in tweet snippets. Some examples of Twitter Card tags are:
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="My Webpage Title">
<meta name="twitter:description" content="A brief description of my webpage.">