HTML lets you specify metadata information about a document rather than document content in a variety of ways. The best way is “HTML meta tags”
The META element can be used to include name/value pairs describing properties of the HTML document, such as author, Expiry Date, a list of key words, author etc.
The <meta> tag is an empty element and so does not have a closing tag, rather, <meta> tags carry information within attributes, so you need a forward slash character at the end of the element.
Metadata provided by using meta tag is a very important part of the web. It can assist search engines in finding the best match when a user performs a search. Search engines will often look at any metadata attached to a page especially keywords and rank it higher than another page with less relevant metadata, or with no metadata at all.
Adding Meta Tags to Your Documents:
You can add metadata to your web pages by placing <meta> tags between the <head> and </head> tags. This can include the following attributes:
Attribute | Description |
---|---|
Name | Name for the property. Can be anything. Examples include, keywords, description, author, revised, generator etc. |
Content | Specifies the property’s value. |
Scheme | Specifies a scheme to use to interpret the property’s value (as declared in the content attribute). |
http-equiv | Used for http response message headers. For example http-equiv can be used to refresh the page or to set a cookie. Values include content-type, expires, refresh and set-cookie. |
Meta Tag Examples:
Let’s see few important usage of Meta Tags.
- Specifying Keywords.
- Document Description.
- Document Revision date.
- Document Refreshing.
- Page Redirection.
- Setting Author Name.
Explanation:
1. Specifying Keywords -Â HTML meta tags
1 2 3 4 5 6 7 | <html> <head> <meta name="keywords" content="HTML, meta tags, metadata" /> </head> <body> </body> </html> |
2. Document Description - HTML meta tags
This is again important information and many search engine use this information as well while searching a web page. So you should give an appropriate description of the page.
1 2 3 4 5 6 7 | <html> <head> <meta name="description" content="Learn about Meta Tags." /> </head> <body> </body> </html> |
3. Document Revision date - HTML meta tags
This information tells about last time the document was updated.
1 2 3 4 5 6 7 | <html> <head> <meta name="revised" content="Tutorialspoint, 6/12/2006" /> </head> <body> </body> </html> |
4. Document Refreshing - HTML meta tags
You can specify a duration after which your web page will keep refreshing. If you want your page keep refreshing after every 10 seconds then use the following syntax.
1 2 3 4 5 6 7 | <html> <head> <meta http-equiv="refresh" content="30"> </head> <body> </body> </html> |
5. Page Redirection - HTML meta tags
You can specify a page redirection using Meta Tag. Following is an example of redirecting current page to another page. You can specify a duration after which page will be redirected.
1 2 3 4 5 6 7 | <html> <head> <meta http-equiv="refresh" content="10; url=http://www.dbhacker.hpage.com" /> </head> <body> </body> </html> |
You can use Meta Tag to store cookies on client side later information can be used by then Web Server to track a site visitor.
6. Setting Author Name - HTML meta tags
Note: If you do not include the expiration date and time, the cookie is considered a session cookie and will be deleted when the user exits the browser.
You can set an author name in a web page using Meta Tag. See an example below:
1 2 3 4 5 6 7 | <html> <head> <meta name="author" content="Deepak anand" /> </head> <body> </body> </html> |
If you have any query related to this topic, feel free to ask in our questionsbank section by clicking here.