Attributes :name and content

The name and content attributes specify properties of the document. The value of the name attribute is the property you are setting, and the value of the content attribute is the setting that you want to give for the property you set in the name attribute. In the example you just saw a moment ago, the < meta > element was setting a description property for the content of the document or site. As you can see, the name attribute had a value of description, and the value of the content attribute is a description of what the site is about:

< meta name=”description” content=”Buy computer programming books to learn HTML, XHTML, JavaScript, ASP.Net, PHP” />

The value of the name attribute can be anything; no restrictions are published in any standards. Therefore, if you need to add your own information about a document and its content, this can be a handy technique.

There are, however, some predefined values you will regularly see used this way. These are as follows:

- description: Specifies a description of the page

- keywords: Contains a list of comma-separated keywords that a user might search on to find the page

- robots: Indicates how search engines should index the page

The description and keywords properties can be used by programs called crawlers, bots, or spiders, which most search engines use to help index web sites, and are therefore worth adding to any web page. These programs go through web sites adding information to the databases used by the search engines, following links as they come across them, indexing those pages, and so on — this is how search engines manage to index so many sites.

Using name with a Value of description:

You have already seen an example of giving the name property a value of description, and using the content property to specify a sentence that describes the site. Sometimes search engines will display the description property when your site is returned in response to a user’s search.

A description should be a maximum of 200 characters long, although some search engines, such as Google, display only the first 100 characters, so you should try to get across the main content in the first 100 characters.

Using name with a Value of keywords:

The keywords property supplies a list of keywords that a search engine can use to index the site. If someone types in one of the words or a combination of the words you use as your keywords, then a search engine may have a better chance of returning your site. For example, an online computer bookstore might use keywords such as this:

< meta name=”description” content=”Buy computer programming books to learn HTML, XHTML, JavaScript, ASP.Net, PHP” />

The more words you supply, the better the chance your page will show up in a search engine; however, you should never use words that do not directly relate to the content of the site, and ideally the keywords will also appear in the text for that page.

It is generally considered that, while keywords used to have a large impact on how search engines indexed your site, they have very little effect these days. However, if you use all of the strategies available to get your site recognized by search engines, the more likely people will be to find your site.

Most search engines create their own limit for the number of keywords they will index, and this number varies between search engines, but you should generally keep your keywords to less than 1,000 characters.

You could also use the lang attribute in conjunction with the description and keywords to indicate the language they are using, or to offer them in multiple languages. For example, here are the keywords in U.S. English:

< meta name=”keywords” content=”computer, programming, books” lang=”en-us” />

Using name with a Value of robots:

As mentioned earlier, many search engines use little programs to index web pages on their behalf. You can use the name attribute with a value of robots to prevent one of these programs from indexing a page or links from the page (because many of these programs follow the links they find on your site and index those, too). For example, you probably would not want a search engine to index any pages that you are still developing, or which you use to administer the site—because you do not want people to just happen across them.

Here you can see that the < meta > element tells search engines not to index this page or to follow any of the links on it to index those.

< meta name=”robots” content=”noindex, nofollow” />

The content attribute can have the values shown in the table that follows.

Value Meaning:

all Index all pages.

none Index no pages.

index Index this page.

noindex Do not index this page.

follow Follow links from this page.

nofollow Do not follow links from this page.

By default the values would be all, index, and follow, allowing web crawlers to follow any link and index all pages.

http-equiv and content:

The http-equiv and content attributes are paired together to set HTTP header values. Every time a web browser requests a page, HTTP headers are sent with the request, and each time the server responds sending a page back to the client, it adds HTTP headers back to the client:

- The headers sent from a browser to a server when it requests a page contain information such as the formats the browser will accept, the type of browser, the operating system, the screen resolution, the date, and other information about the user’s configuration.

- The headers returned from a server to a web browser contain information such as the server type, the date and time the page was sent, and the date and time the page was last modified.

Of course, the headers can contain much more information, and using the < meta > tags is one way of adding new headers to be sent with the document.

For example, you might want to add a header to indicate when the page should expire (no longer be valid) — which is especially helpful if the document contains things such as special offer prices which you know will expire — or to refresh a page after a period of time.