<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
        "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML LANG="en-US"><HEAD>
<TITLE>META Tag Snob: META element syntax</TITLE>
<base href="http://www.bauser.com/websnob/meta/syntax.html">
<META NAME="description" CONTENT="A detailed discussion of the HTML meta
tag syntax, including explanations of six attributes.">
<meta name="keywords" content="meta tag, meta element">
<meta name="DCTERMS.created" scheme="DCTERMS.W3CDTF" content="2002-05-25">
<!--#exec cgi="/websnob/cgi/head.pl"-->
<script src="pop.js" type="text/javascript" language="Javascript"></script>
</HEAD><BODY BGCOLOR="#000000" TEXT="#00FF00" LINK="#0000FF" VLINK="#FF00FF">
<p id="breadcrumbs"><a href="/websnob" rel="Start">Websnob</a> &gt;
<a href="/websnob/meta/">META Tags</a> &gt;
<strong>Syntax</strong></p> 

<p class="advert"><!--#exec cgi="/websnob/adverts/ad_1.pl"--></p>

<h1><samp>META</samp> tag syntax</h1> 

<p>The <acronym title="Hypertext Markup Language">HTML</acronym>
<samp>META</samp> tag has been part of the language since the days of <abbr
title="HTML Plus">HTML+</abbr>, and has experienced only minor changes in
updates of the specification. Even in <a href="/websnob/html4/">HTML
4.01</a>, the <samp>META</samp> tag has only has six attributes, five of which
are optional.</p>

<p>If you just want to know what a <samp>META</samp> tag looks like (and don't
care about the more esoteric points of HTML), you should <a
href="#attributes">skip to the section on attributes</a>.</p> 

<h2 id="basic">Basic syntax issues</h2>

<p>In <acronym title="Standard Generalized Markup Language">SGML</acronym>
<samp>META</samp> is an <em>optional</em> and <em>empty</em> element that
<em>must</em> appear in the context of a <samp>HEAD</samp> element. That
means:</p>

<p>No HTML document is required to have a <samp>META</samp> element. (In fact,
the only element required for all HTML documents is <samp>TITLE</samp>.) On the
other hand, I <em>recommend</em> that all HTML documents include at least
one of the most common <samp>META</samp> tags.</p>

<p>The <samp>META</samp> tag has a start tag, but not an end tag, so there is
never a <samp>&lt;/meta&gt;</samp> in HTML. A <samp>META</samp> tags contains its
metadata <em>inside</em> a tag, not between tags. That information is
contained in <dfn>attributes</dfn>, qualities of a tag identified by
name/value pairs, where the name is a keyword (like "http-equiv") and the
value is connected to the keyword with an = (equal sign).</p>

<p><samp>META</samp> tags always appear in the <samp>HEAD</samp> element. That
doesn't necessarily mean they have to appear between &lt;head&gt; and
&lt;/head&gt;, since the <samp>HEAD</samp> element exists in HTML documents
even when they don't use <samp>HEAD</samp> tags. If the boundaries of the
<samp>HEAD</samp> element aren't marked with <samp>HEAD</samp> tags, the
<samp>META</samp> tag must appear before any of the regular <samp>BODY</samp>
content.</p>

<p>An HTML file may have as many <samp>META</samp> elements as it needs to
encode its metainformation. Technically, it can even have multiple
<samp>META</samp> elements with the same <samp>name</samp> or <samp>http-equiv</samp>,
but this may cause problems for the user agents that read the metadata.</p>

<h2 id="attributes"><samp>META</samp> and its attributes</h2>

<p>As mentioned above, the <samp>META</samp> tag is an empty element with one
required attribute (<samp>content</samp>) and five optional ones
(<samp>name</samp>, <samp>http-equiv</samp>, <samp>lang</samp>, <samp>dir</samp>, and
<samp>scheme</samp>). As such, the simplest legal form of the tag looks like:</p>

<p><code>
&lt;meta content="this is an example"&gt;
</code></p>

<p>Although it's <em>syntactically</em> valid, this tag is
<em>semantically</em> meaningless, because it doesn't associate the
<samp>content</samp> with a labeling attribute (<samp>name</samp> or
<samp>http-equiv</samp>). <strong>Useful metadata is always a name/value
pair.</strong> <samp>META</samp> tags with only one attribute aren't useful
(except possibly when used to designate a strictly boolean value, as
<var><a href="browser.html#Cleartype">Cleartype</a></var> does.)</p>

<p>The three most common (and most important) attributes of the
<samp>META</samp> tag are valid HTML in all versions of HTML since <A
href="http://www.w3.org/MarkUp/htmlplus_paper/htmlplus.html">HTML+</a>.</p>

<h3 id="name">name</h3>

<p>The <samp>name</samp> attribute provides the "name" portion of the
"name/value" metadata pair. It identifies a type of metadata (for example,
a document's publication date or abstract), but doesn't assign a value to
the name. (That's the job of <samp>content</samp>.) Most <a
href="engines.html">META tags for influencing search engines</a> use
<samp>NAME</samp>. For example:</p> 

<p><code>
&lt;meta name="Description" content="This is my home page!"&gt;
</code></p>

<p>The HTML specifications give <samp>content</samp> an SGML data type of
<samp>NAME</samp>, meaning it can only contain letters, numbers, hyphens,
underscores, and periods. It must always begin with a letter. Technically,
the value of of <samp>name</samp> is always case-sensitive, but no software
applications are known to treat it as such.</p>

<h3 id="http-equiv">http-equiv</h3>

<p>The <samp>http-equiv</samp> attribute, provides the "name" of a "name/value"
pair, just like <samp>name</samp> does, with one important difference: By using
the <samp>http-equiv</samp> attribute, an author gives permission to the web
server holding his document to read and process that <samp>META</samp> tag,
converting it into an <acronym title="Hypertext Transfer
Protocol">HTTP</acronym> to be read by the software that requested the file
from the server.</p>

<p>The <samp>http-equiv</samp> attribute is intended for use by authors who
need to supplement or override the HTTP headers created by their web
servers. In practice, few server administrators allow their users to
override server settings that way, so <samp>http-equiv</samp> is seldom used as
intended. Instead, <samp>http-equiv</samp> has been bootstrapped by software
authors as a tag for controlling <em>web browsers</em>. Most uses of the
<samp>http-equiv</samp> tag activate (or deactivate) special functions in
select web browser. For example:</p>
 
<p><code>
&lt;meta http-equiv="Refresh" content="13"&gt;
</code></p>

<p>Like <samp>name</samp> the <samp>http-equiv</samp> attribute can only
contain letters, numbers, hyphens, underscores, and periods, and must
always begin with a letter. Officially, <samp>http-equiv</samp> is
case-sensitive, but nobody treats it as such.</p>

<h3 id="content">content</h3>

<p>The <samp>content</samp> attribute is the only mandatory attribute for
<samp>META</samp> tags, and the most important, because it contains the
<em>value</em> of the label created by the <samp>name</samp> and/or
<samp>http-equiv</samp> attributes. <samp>name</samp> and <samp>http-equiv</samp>
declare which metadata is important, but <samp>content</samp> says what the
metatdata actually is.</p>

<p>The HTML specifications give <samp>content</samp> a "permitted value" of
<samp>CDATA</samp>, meaning it's case-sensitive and can contain any character
expressible in HTML, but characters outside HTML's normal ASCII character
set need to be encoded with the same HTML entities that you use in normal
<samp>BODY</samp> text.</p>

<p>The other three attributes of the <samp>META</samp> element are only
legal in HTML 4.0 and its derivatives (HTML 4.01, <A
href="http://www.purl.org/NET/ISO+IEC.15445/15445.html">ISO/IEC 15445</a>,
and <A href="http://www.w3.org/TR/xhtml1/">XHTML</a>). They are all optional.</p>

<h3 id="lang">lang</h3>

<p>The <samp>lang</samp> attribute designates the language of the <samp>META</samp>
tag's <samp>content</samp> value. The <samp>lang</samp> uses the <cite>RFC
1755</cite> language codes (for major languages, they're two-letter
abbreviations), and is only necessary when a <samp>META</samp> tag uses a
language different from its home document's primary language.</p>

<h3 id="dir">dir</h3>

<p>The <samp>dir</samp> attribute specifies the <em>directionality</em> of the
value of the <samp>content</samp> value. <samp>dir</samp> only has two possible
values s of 4.0 files are supposed , using <var>rtl</var> for text meant to
be read right-to-left, and <var>ltr</var> for text meant to be read left-to-
right. This attribute is very rarely used, because it's only necessary when
you need to override the directionality determined by the UNICODE
bidirectional algorithm <em>and</em> the default directionality you've
specified at the document level. If you're writing in English or one of the
other left-to-right languages, you probably don't need to use the <samp>dir</samp>
attribute.</p>

<p>(In case you're wondering, HTML authors are supposed to identify the
primary language and directionality of their HTML documents by including
the <samp>lang</samp> and <samp>dir</samp> attributes on the opening tag of the
<samp>html</samp> element itself. Relatively few people do this right now.)</p>


<h3 id="scheme">scheme</h3>
 
<p>The <samp>scheme</samp> attribue is used to identify a metadata scheme used
for decoding the value of the <samp>content</samp> attribute. This attribute
is a little tricky, because it can contain a simple self-explanation of how
<samp>content</samp> is encoded, or it can be a label identifying a complete
specification.</p>

<p>For example, if I was using using the <samp>name</samp> value "date" to
label when this web page was written, and using <var>2002-05-19</var> as the value
of <samp>content</samp>, a self-explanatory <samp>scheme</samp> value might look
like this:</p>

<p><code>
&lt;meta name="date" scheme="year-month-date" content="2002-05-19"&gt;
</code></p>

<p>On the other hand, a labeling <samp>scheme</samp> might mention the <acronym
title="International Organization for Standardization">ISO</acronym> date
standard, which is where I really got the format:</p> 

<p><code>
&lt;meta name="date" scheme="ISO 8601" content="2002-05-19"&gt;
</code></p>

<h4 id="profiles">A note on metadata profiles</h4>

<p>Using the <samp>scheme</samp> attribute brings up the whole issue of
metadata <em>profiles</em>. <dfn>Profiles</dfn> are documents that explain
the metadata system used to describe a document. In HTML, the location of a
profile document (which may or may not be human-readable) can be defined
two ways: by including a <samp>profile</samp> attribute in the opening tag of
the <samp>HEAD</samp> element, or by using the <a
href="/websnob/html4/relationships.html#scheme">scheme link
relationship</a>. Both methods use the <acronym title="Uniform Resource
Identifier">URI</acronym> (address) of the document to identify it.</p>

<p>In theory, that means every web page should point to another page explaining
exactly which <samp>name</samp>, <samp>http-equiv</samp>, and <samp>scheme</samp>
values it uses, and what they mean. In practice, only advanced users (more
advanced than <cite>Websnob</cite> even) are doing so, because there are
very few coherant metadata schemes available for use. Many sites (including
this one) use combinations of multiple schemes, making it difficult to
single out one as "the scheme" for a site.</p>

<p>Until this issue is cleared up (by the development of more detailed
schemes, with reference URIs), you shouldn't worry about designating
profiles. There are currently no software agents that utilize them, anyway.</p> 

<h2 id="xhtml"><samp>META</samp> syntax in <acronym title="Extensible
Hypertext MarkUp Language">XHTML</acronym></h2>

<p>XHTML (HTML re-implemented in <acronym title="Extensible MarkUp
Language">XML</acronym>) is slowly supplanting traditonal HTML on the
Web. <samp>META</samp> exists in all three versions of XHTML currently
published (XHTML 1.0, 1.1, and 2.0). There are three major (but easily
made) changes to how XHTML formats the <samp>META</samp> element. These
apply to all versions of XHTML:</p>

<p>The first, and most important, is that XHTML elements are <em>case
sensitive</em> and <em>lower-cased</em>. In other words, you have to type
<code>meta</code>, not <code>META</code>.</p>

<p>Just as important is the fact that XHTML closes empty elements with
<code>/></code> instead of <code>></code>. <em>All versions of XHTML close
the element this way.</em> The typical <var>Description</var> would look
like this in XHTML 1.0:</p>

<p><code>
&lt;meta name="Description" content="This is my home page!"/&gt;
</code></p>

<p>Finally (and not as critical) is the addition of the <samp>xml:lang</samp>
attribute, which identifies the language used in the <samp>content</samp>
attribute. <samp>xml:lang</samp> uses the same language abbreviations as the <a
href="#"><samp>lang</samp> attribute</a>. <samp>META</samp> elements in
XHTML 1.0 may have both <samp>lang</samp> and <samp>xml:lang</samp>
attributes.

<h3 id="xhtml1.1">XHTML 1.1</h3>

<p>XHTML 1.1 goes one step further than XHTML 1.0, in that it completely
drops the <a href="#lang"><samp>lang</samp></a> attribute in favor of using
the <samp>xml:lang</samp> exclusively.</p>

<h3 id="xhtml2.0">XHTML 2.0</h3>

<p>XHTML 2.0 (still in development) includes three more <em>major</em>
changes to the <samp>META</samp> element: two attributes (<a
href="#content"><samp>content</samp></a> and <a
href="#http-equiv"><samp>http-equiv</samp></a>) have been removed, and the
element is no longer empty. Information that previously would have been
included in the <samp>content</samp> attribute is instead included between
the two <samp>meta</samp> tags. That means the typical
<samp>Description</samp> looks like:</p>

<p><code>
&lt;meta name="Description"&gt;This is my home page!&lt;/meta&gt;
</code></p>

<p>At this point (November 2003), it remains unclear what the removal of
the <samp>http-equiv</samp> attribute will mean the <samp>META</samp> tags
that use it. In at least one case (<a href="browsers.html#Refresh"
><samp>META</samp>="<var>refresh</var></a>"), an new <a
href="../HTML4/relationships.html"><samp>link</samp> relationship</a> has
been proposed as substitute.</p>

<p class="advert"><!--#exec cgi="/websnob/adverts/ad_2.pl"--></p>
<!--#exec cgi="/websnob/cgi/menu.pl"--> <!--#exec cgi="/websnob/cgi/2002"-->
</BODY></HTML>

