<meta> Tag in HTML
The <meta> tag in HTML is used to provide metadata about an HTML document. Metadata is information about the document that is not displayed on the page itself but is used by browsers and search engines. The <meta>
tag is placed inside the <head>
section of the document.
Key Points on <meta> Tag:
- The
<meta>
tag is primarily used for defining the document's character set, author, keywords, and description. - It can also define viewport settings, refresh times, and various HTTP headers for better control over the page's behavior and appearance.
- The
name
attribute specifies the type of metadata, such as "description," "keywords," or "author." - The
content
attribute provides the actual value for the metadata specified in thename
attribute.
Syntax of <meta> Tag:
Syntax Example
<meta name="name" content="value">
Example of <meta> Tag in HTML:
This example demonstrates how the <meta>
tag can be used to define metadata such as the description and keywords for a web page.
Code Example
<head>
<meta charset="UTF-8">
<meta name="author" content="John Doe">
<meta name="description" content="A sample webpage for learning HTML">
<meta name="keywords" content="HTML, Meta tag, Example">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
Output
Attributes of <meta> Tag:
- charset: Specifies the character encoding for the HTML document (e.g.,
UTF-8
). - name: Specifies the metadata name, such as "description," "keywords," "author," etc.
- content: Provides the value for the
name
attribute. For example, a description or keywords. - http-equiv: Provides HTTP headers like "refresh" or "content-type."
- viewport: Helps control the layout on mobile devices by specifying the viewport's width and scale factor.
The <meta>
tag plays a crucial role in search engine optimization (SEO) by defining the page's metadata, which can influence how search engines rank the page. It's also important for controlling page behavior and appearance on different devices, especially with the viewport
attribute.
The <meta>
tag is essential for web development, aiding in SEO optimization, defining responsive design properties, and specifying document encoding.