Meta tags in HTML provide metadata about the HTML document. They are placed within the <head>
element of an HTML document and are not displayed on the web page itself but provide information to browsers, search engines, and other web services. Here's a detailed explanation of common HTML meta tags:
charset:
- Specifies the character encoding for the HTML document.
- Example:
<meta charset="utf-8">
viewport:
- Controls the viewport behavior on mobile devices.
- Example:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
description:
- Provides a brief summary or description of the content.
- Used by search engines for indexing and displaying search results.
- Example:
<meta name="description" content="Description of the page">
keywords:
- Specifies keywords related to the content of the page.
- Deprecated by major search engines but still used by some.
- Example:
<meta name="keywords" content="keyword1, keyword2, keyword3">
author:
- Specifies the author of the document.
- Example:
<meta name="author" content="Author Name">
robots:
- Controls the behavior of search engine crawlers.
- Directives include
index
(allow indexing),noindex
(prevent indexing),follow
(allow following links),nofollow
(prevent following links), etc. - Example:
<meta name="robots" content="index, follow">
viewport:
- Adjusts the viewport properties for better rendering on mobile devices.
- Example:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
canonical:
- Specifies the preferred URL for duplicate or similar content.
- Helps search engines identify the original source of content.
- Example:
<link rel="canonical" href="https://example.com/canonical-url">
referrer:
- Controls how much information is passed along with the referrer when a user clicks on a link.
- Values include
no-referrer
,no-referrer-when-downgrade
,origin
,origin-when-cross-origin
,same-origin
,strict-origin
,strict-origin-when-cross-origin
, andunsafe-url
. - Example:
<meta name="referrer" content="no-referrer">
content security policy (CSP):
- Defines a policy to prevent XSS (cross-site scripting) attacks by specifying approved sources for content.
- Example:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
apple-mobile-web-app-capable:
- Defines whether the web application runs in full-screen mode on iOS devices.
- Example:
<meta name="apple-mobile-web-app-capable" content="yes">
apple-touch-icon:
- Specifies the icon displayed when a user adds a web page to the home screen on iOS devices.
- Example:
<link rel="apple-touch-icon" href="icon.png">
These meta tags provide important information to browsers, search engines, and other web services, helping to improve the accessibility, visibility, and security of your web pages.
Here's an example of how you can use meta tags in an HTML document:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="This is an example webpage demonstrating the usage of meta tags."> <meta name="keywords" content="HTML, meta tags, example"> <meta name="author" content="John Doe"> <meta name="robots" content="index, follow"> <meta name="referrer" content="no-referrer"> <meta http-equiv="Content-Security-Policy" content="default-src 'self'"> <title>Example Page</title> </head> <body> <h1>Welcome to Example Page</h1> <p>This is a simple example webpage.</p> <a href="https://www.example.com">Visit Example Website</a> </body> </html>
In this example:
- The
<meta charset="UTF-8">
tag specifies the character encoding. - The
<meta name="viewport" content="width=device-width, initial-scale=1.0">
tag sets the viewport to adjust for different device widths. - The
<meta name="description" content="...">
and<meta name="keywords" content="...">
tags provide a description and keywords for search engines. - The
<meta name="author" content="...">
tag specifies the author of the page. - The
<meta name="robots" content="index, follow">
tag instructs search engine crawlers to index and follow links on the page. - The
<meta name="referrer" content="no-referrer">
tag specifies that no referrer information should be sent when a user clicks on links. - The
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
tag sets a content security policy to restrict content sources.
These meta tags help provide essential information about the webpage to browsers, search engines, and other web services.
0 Comments