html elementhead element followed by a body element.manifestHTMLElement.The html element represents the root of an HTML
document.
The manifest
attribute gives the address of the document's application
cache manifest, if there is
one. If the attribute is present, the attribute's value must be a
valid URL.
The manifest attribute
only has an
effect during the early stages of document load. Changing the
attribute dynamically thus has no effect (and thus, no DOM API is
provided for this attribute).
Later base elements don't affect the
resolving of relative URLs in
manifest attributes, as the
attributes are processed before those elements are seen.
head elementhtml element.title element.HTMLElement.The head element collects the document's
metadata.
title elementhead element containing no other title elements.HTMLElement.The title element represents the document's title or
name. Authors should use titles that identify their documents even
when they are used out of context, for example in a user's history
or bookmarks, or in search results. The document's title is often
different from its first header, since the first header does not
have to stand alone when taken out of context.
There must be no more than one title element per
document.
The title element must not contain any
elements.
Here are some examples of appropriate titles, contrasted with the top-level headers that might be used on those same pages.
<title>Introduction to The Mating Rituals of Bees</title>
...
<h1>Introduction</h1>
<p>This companion guide to the highly successful
<cite>Introduction to Medieval Bee-Keeping</cite> book is...
The next page might be a part of the same site. Note how the title describes the subject matter unambiguously, while the first header assumes the reader knowns what the context is and therefore won't wonder if the dances are Salsa or Waltz:
<title>Dances used during bee mating rituals</title>
...
<h1>The Dances</h1>
The string to use as the document's title is given by the document.title DOM attribute. User
agents should use the document's title when referring to the
document in their user interface.
base elementhead element containing no other base elements.hreftargetinterface HTMLBaseElement : HTMLElement {
attribute DOMString href;
attribute DOMString target;
};
The base element allows authors to specify the
document base URL for the purposes of resolving relative URLs, and the name
of the default browsing context for the purposes of
following hyperlinks.
There must be no more than one base element per
document.
A base element must have either an href attribute, a target attribute, or both.
The href content
attribute, if specified, must contain a valid URL.
A base element, if it has an href attribute, must come before any
other elements in the tree that have attributes defined as taking
URLs, except the html element
(its manifest attribute
isn't affected by base elements).
If there are multiple base elements
with href attributes, all but the
first are ignored.
The target
attribute, if specified, must contain a valid browsing context
name or keyword. User agents use this name when
following hyperlinks.
A base element, if it has a target attribute, must come before
any elements in the tree that represent hyperlinks.
If there are multiple base elements
with target attributes, all but
the first are ignored.
The href and target DOM attributes
must reflect the respective content attributes of the
same name.
link elementnoscript element that is a child of a head element.hrefrelmediahreflangtypesizestitle attribute has special semantics on this element.interface HTMLLinkElement : HTMLElement {
attribute boolean disabled;
attribute DOMString href;
attribute DOMString rel;
readonly attribute DOMTokenList relList;
attribute DOMString media;
attribute DOMString hreflang;
attribute DOMString type;
attribute DOMString sizes;
};
The LinkStyle interface must also be implemented
by this element, the styling processing model defines
how. [CSSOM]
The link element allows authors to link their
document to other resources.
The destination of the link is given by the href attribute, which must
be present and must contain a valid URL. If the href attribute is absent, then the
element does not define a link.
The type of link indicated (the relationship) is given by the
value of the rel
attribute, which must be present, and must have a value that is a
set of space-separated tokens. The allowed values and their meanings are defined
in a later section. If the rel
attribute is absent, or if the value used is not allowed according
to the definitions in this specification, then the element does not
define a link.
Two categories of links can be created using the
link element. Links
to external resources are links to resources that are to be
used to augment the current document, and hyperlink links are links to
other documents. The link types
section defines whether a particular link type is an external
resource or a hyperlink. One element can create multiple links (of
which some might be external resource links and some might be
hyperlinks); exactly which and how many links are created depends on
the keywords given in the rel
attribute. User agents must process the links on a per-link basis,
not a per-element basis.
The exact behavior for links to external resources depends on the exact relationship, as defined for the relevant link type. Some of the attributes control whether or not the external resource is to be applied (as defined below). For external resources that are represented in the DOM (for example, style sheets), the DOM representation must be made available even if the resource is not applied. (However, user agents may opt to only fetch such resources when they are needed, instead of pro-actively fetching all the external resources that are not applied.)
The semantics of the protocol used (e.g. HTTP) must be followed when fetching external resources. (For example, redirects must be followed and 404 responses must cause the external resource to not be applied.)
Interactive user agents should provide users with a means to
follow the hyperlinks
created using the link element, somewhere within their
user interface. The exact interface is not defined by this
specification, but it should include the following information
(obtained from the element's attributes, again as defined below), in
some form or another (possibly simplified), for each hyperlink
created with each link element in the document:
rel attribute)title attribute).href attribute).hreflang attribute).media attribute).User agents may also include other information, such as the type
of the resource (as given by the type attribute).
Hyperlinks created with the link
element and its rel attribute
apply to the whole page. This contrasts with the rel attribute of a
and area elements, which indicates the type of a link
whose context is given by the link's location within the
document.
The media
attribute says which media the resource applies to. The value must
be a valid media query. [MQ]
If the link is a hyperlink
then the media attribute is
purely advisory, and describes for which media the document in
question was designed.
However, if the link is an external resource link,
then the media attribute is
prescriptive. The user agent must apply the external resource to
views while their state match the
listed media and the other relevant conditions apply, and must not
apply them otherwise.
The default, if the media attribute is omitted, is
all, meaning that by default links apply to all
media.
The hreflang
attribute on the link element has the same semantics as
the hreflang
attribute on hyperlink elements.
The type attribute
gives the MIME type of the linked resource. It is purely advisory.
The value must be a valid MIME type, optionally with parameters. [RFC2046]
For external resource
links, the type attribute
is used as a hint to user agents so that they can avoid fetching
resources they do not support. If the attribute is present, then the
user agent must assume that the resource is of the given type. If
the attribute is omitted, but the external resource link type has a
default type defined, then the user agent must assume that the
resource is of that type. If the UA does not support the given MIME
type for the given link relationship, then the UA should not fetch
the resource; if the UA does support the given MIME type for the
given link relationship, then the UA should fetch the
resource. If the attribute is omitted, and the external resource
link type does not have a default type defined, but the user agent
would fetch the resource if the type was known and supported, then
the user agent should fetch the resource under the
assumption that it will be supported.
User agents must not consider the type attribute authoritative —
upon fetching the resource, user agents must not use the type attribute to determine its actual
type. Only the actual type (as defined in the next paragraph) is
used to determine whether to apply the resource, not the
aforementioned assumed type.
If the resource is expected to be an image, user agents may apply the image sniffing rules, with the official type being the type determined from the resource's Content-Type metadata, and use the resulting sniffed type of the resource as if it was the actual type. Otherwise, if the resource is not expected to be an image, or if the user agent opts not to apply those rules, then the user agent must use the resource's Content-Type metadata to determine the type of the resource. If there is no type metadata, but the external resource link type has a default type defined, then the user agent must assume that the resource is of that type.
Once the user agent has established the type of the resource, the user agent must apply the resource if it is of a supported type and the other relevant conditions apply, and must ignore the resource otherwise.
If a document contains style sheet links labeled as follows:
<link rel="stylesheet" href="A" type="text/plain"> <link rel="stylesheet" href="B" type="text/css"> <link rel="stylesheet" href="C">
...then a compliant UA that supported only CSS style sheets
would fetch the B and C files, and skip the A file (since
text/plain is not the MIME type for CSS style
sheets).
For files B and C, it would then check the actual types returned
by the server. For those that are sent as text/css, it
would apply the styles, but for those labeled as
text/plain, or any other type, it would not.
If one the two files was returned without a
Content-Type metadata, or with a syntactically
incorrect type like Content-Type: "null", then the default type
for stylesheet links would kick
in. Since that default type is text/css, the
style sheet would nonetheless be applied.
The title
attribute gives the title of the link. With one exception, it is
purely advisory. The value is text. The exception is for style sheet
links, where the title
attribute defines alternative style sheet sets.
The title
attribute on link elements differs from the global
title attribute of most other
elements in that a link without a title does not inherit the title
of the parent element: it merely has no title.
The sizes attribute is used
with the icon link type. The attribute
must not be specified on link elements that do not have
a rel attribute that specifies
the icon keyword.
Some versions of HTTP defined a Link:
header, to be processed like a series of link elements.
If supported, for the purposes of ordering links defined by HTTP
headers must be assumed to come before any links in the document, in
the order that they were given in the HTTP entity header. (URIs in
these headers are to be processed and resolved according to the
rules given in HTTP; the rules of this specification don't
apply.) [RFC2616] [RFC2068]
The DOM attributes href, rel, media, hreflang, and type, and sizes each must
reflect the respective content attributes of the same
name.
The DOM attribute relList must
reflect the rel
content attribute.
The DOM attribute disabled only applies
to style sheet links. When the link element defines a
style sheet link, then the disabled attribute behaves as
defined for the alternative
style sheets DOM. For all other link elements it
always return false and does nothing on setting.
meta elementcharset attribute is present, or if the element is in the Encoding declaration state: as the first element in a head element.http-equiv attribute is present, and the element is not in the Encoding declaration state: in a head element.http-equiv attribute is present, and the element is not in the Encoding declaration state: in a noscript element that is a child of a head element.name attribute is present: where metadata content is expected.namehttp-equivcontentcharset (HTML only)interface HTMLMetaElement : HTMLElement {
attribute DOMString content;
attribute DOMString name;
attribute DOMString httpEquiv;
};
The meta element represents various kinds of
metadata that cannot be expressed using the title,
base, link, style, and
script elements.
The meta element can represent document-level
metadata with the name
attribute, pragma directives with the http-equiv attribute, and the
file's character encoding declaration when an HTML
document is serialized to string form (e.g. for transmission over
the network or for disk storage) with the charset attribute.
Exactly one of the name,
http-equiv, and charset attributes must be
specified.
If either name or http-equiv is specified, then
the content attribute must
also be specified. Otherwise, it must be omitted.
The charset
attribute specifies the character encoding used by the
document. This is called a character encoding
declaration.
The charset attribute may
be specified in HTML documents only, it
must not be used in XML documents. If the
charset attribute is
specified, the element must be the first element in the
head element of the file.
The content
attribute gives the value of the document metadata or pragma
directive when the element is used for those purposes. The allowed
values depend on the exact context, as described in subsequent
sections of this specification.
If a meta element has a name attribute, it sets
document metadata. Document metadata is expressed in terms of
name/value pairs, the name
attribute on the meta element giving the name, and the
content attribute on the same
element giving the value. The name specifies what aspect of metadata
is being set; valid names and the meaning of their values are
described in the following sections. If a meta element
has no content attribute,
then the value part of the metadata name/value pair is the empty
string.
If a meta element has the http-equiv attribute specified,
it must be either in a head element or in a
noscript element that itself is in a head
element. If a meta element does not have the http-equiv attribute specified,
it must be in a head element.
The DOM attributes name and content must
reflect the respective content attributes of the same
name. The DOM attribute httpEquiv must
reflect the content attribute http-equiv.
This specification defines a few names for the name attribute of the
meta element.
The value must be a short free-form string that giving the
name of the Web application that the page represents. If the page
is not a Web application, the application-name metadata name
must not be used. User agents may use the application name in UI in
preference to the page's title, since the title might
include status messages and the like relevant to the status of the
page at a particular moment in time instead of just being the name
of the application.
The value must be a free-form string that describes the page. The value must be appropriate for use in a directory of pages, e.g. in a search engine.
The value must be a free-form string that identifies the software used to generate the document. This value must not be used on hand-authored pages.
Extensions to the predefined set of metadata names may be registered in the WHATWG Wiki MetaExtensions page.
Anyone is free to edit the WHATWG Wiki MetaExtensions page at any time to add a type. These new names must be specified with the following information:
The actual name being defined. The name should not be confusingly similar to any other defined name (e.g. differing only in case).
A short description of what the metadata name's meaning is, including the format the value is required to be in.
A list of other names that have exactly the same processing requirements. Authors should not use the names defined to be synonyms, they are only intended to allow user agents to support legacy content.
One of the following:
If a metadata name is added with the "proposal" status and found to be redundant with existing values, it should be removed and listed as a synonym for the existing value.
Conformance checkers must use the information given on the WHATWG Wiki MetaExtensions page to establish if a value not explicitly defined in this specification is allowed or not. When an author uses a new type not defined by either this specification or the Wiki page, conformance checkers should offer to add the value to the Wiki, with the details described above, with the "proposal" status.
This specification does not define how new values will get approved. It is expected that the Wiki will have a community that addresses this.
Metadata names whose values are to be URLs must not be proposed or accepted. Links must
be represented using the link element, not the
meta element.
When the http-equiv attribute
is specified on a meta element, the element is a pragma
directive.
The http-equiv attribute
is an enumerated attribute. The following table lists
the keywords defined for this attribute. The states given in the
first cell of the rows with keywords give the states to which
those keywords map. Some of the keywords are non-conforming, as
noted in the last column.
| State | Keywords | Notes |
|---|---|---|
| Content Language | content-language
| Non-conforming |
| Encoding declaration | content-type
| |
| Default style | default-style
| |
| Refresh | refresh
|
When a meta element is inserted into the document, if its
http-equiv attribute is
present and represents one of the above states, then the user agent
must run the algorithm appropriate for that state, as described in
the following list:
This non-conforming pragma sets the document-wide default language. Until the pragma is successfully processed, there is no document-wide default language.
If another meta element in the Content Language
state has already been successfully processed (i.e. when
it was inserted the user agent processed it and reached the last
step of this list of steps), then abort these steps.
If the meta element has no content attribute, or if that
attribute's value is the empty string, then abort these
steps.
Let input be the value of the
element's content
attribute.
Let position point at the first character of input.
Collect a sequence of characters that are neither space characters nor a U+002C COMMA character (",").
Let the document-wide default language be the string that resulted from the previous step.
For meta elements in the Content Language
state, the content
attribute must have a value consisting of a valid RFC 3066
language code. [RFC3066]
This pragma is not exactly equivalent to the HTTP
Content-Language header, for instance it only
supports one language. [RFC2616]
The Encoding
declaration state's user agent requirements are all handled
by the parsing section of the specification. The state is just an
alternative form of setting the charset attribute: it is a
character encoding declaration.
For meta elements in the Encoding declaration
state, the content
attribute must have a value that is an ASCII
case-insensitive match for a string that consists of: the
literal string "text/html;", optionally
followed by any number of space
characters, followed by the literal string "charset=", followed by the character encoding name
of the character encoding declaration.
If the document contains a meta element in the
Encoding
declaration state then that element must be the first
element in the document's head element, and the
document must not contain a meta element with the
charset attribute
present.
The Encoding declaration state may be used in HTML documents only, elements in that state must not be used in XML documents.
If another meta element in the Refresh state has
already been successfully processed (i.e. when it was inserted
the user agent processed it and reached the last step of this
list of steps), then abort these steps.
If the meta element has no content attribute, or if that
attribute's value is the empty string, then abort these
steps.
Let input be the value of the
element's content
attribute.
Let position point at the first character of input.
Collect a sequence of characters in the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE, and parse the resulting string using the rules for parsing non-negative integers. If the sequence of characters collected is the empty string, then no number will have been parsed; abort these steps. Otherwise, let time be the parsed number.
Collect a
sequence of characters in the range U+0030 DIGIT ZERO to
U+0039 DIGIT NINE and U+002E FULL STOP ("."). Ignore any collected characters.
Let url be the address of the current page.
If the character in input pointed to
by position is a U+003B SEMICOLON (";"), then advance position to
the next character. Otherwise, jump to the last step.
If the character in input pointed to by position is one of U+0055 LATIN CAPITAL LETTER U or U+0075 LATIN SMALL LETTER U, then advance position to the next character. Otherwise, jump to the last step.
If the character in input pointed to by position is one of U+0052 LATIN CAPITAL LETTER R or U+0072 LATIN SMALL LETTER R, then advance position to the next character. Otherwise, jump to the last step.
If the character in input pointed to by position is one of U+004C LATIN CAPITAL LETTER L or U+006C LATIN SMALL LETTER L, then advance position to the next character. Otherwise, jump to the last step.
If the character in input pointed to
by position is a U+003D EQUALS SIGN ("="), then advance position to
the next character. Otherwise, jump to the last step.
Let url be equal to the substring of input from the character at position to the end of the string.
Strip any trailing space characters from the end of url.
Strip any U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), and U+000D CARRIAGE RETURN (CR) characters from url.
Resolve the url value to an absolute URL. (For
the purposes of determining the base URL, the url value comes from the value of a content
attribute of the meta element.) If this fails, abort
these steps.
Perform one or more of the following steps:
Set a timer so that in time seconds, adjusted to take into account user or user agent preferences, if the user has not canceled the redirect, the user agent navigates the document's browsing context to url, with replacement enabled, and with the document's browsing context as the source browsing context.
Provide the user with an interface that, when selected, navigates a browsing context to url, with the document's browsing context as the source browsing context.
Do nothing.
In addition, the user agent may, as with anything, inform the user of any and all aspects of its operation, including the state of any timers, the destinations of any timed redirects, and so forth.
For meta elements in the Refresh state, the
content attribute must have
a value consisting either of:
;), followed by one or
more space characters,
followed by either a U+0055 LATIN CAPITAL LETTER U or a U+0075
LATIN SMALL LETTER U, a U+0052 LATIN CAPITAL LETTER R or a U+0072
LATIN SMALL LETTER R, a U+004C LATIN CAPITAL LETTER L or a U+006C
LATIN SMALL LETTER L, a U+003D EQUALS SIGN (=), and then a valid URL.In the former case, the integer represents a number of seconds before the page is to be reloaded; in the latter case the integer represents a number of seconds before the page is to be replaced by the page at the given URL.
There must not be more than one meta element with
any particular state in the document at a time.
A character encoding declaration is a mechanism by which the character encoding used to store or transmit a document is specified.
The following restrictions apply to character encoding declarations:
If the document does not start with a BOM, and if its encoding is
not explicitly given by Content-Type
metadata, then the character encoding used must be an
ASCII-compatible character encoding, and, in addition,
if that encoding isn't US-ASCII itself, then the encoding must be
specified using a meta element with a charset attribute or a
meta element in the Encoding declaration
state.
If the document contains a meta element with a charset attribute or a
meta element in the Encoding declaration
state, then the character encoding used must be an
ASCII-compatible character encoding.
Authors should not use JIS_X0212-1990, x-JIS0208, and encodings based on EBCDIC. Authors should not use UTF-32. Authors must not use the CESU-8, UTF-7, BOCU-1 and SCSU encodings. [CESU8] [UTF7] [BOCU1] [SCSU]
Authors are encouraged to use UTF-8. Conformance checkers may advise against authors using legacy encodings.
In XHTML, the XML declaration should be used for inline character encoding information, if necessary.
style elementscoped attribute is present: flow content.scoped attribute is absent: where metadata content is expected.scoped attribute is absent: in a noscript element that is a child of a head element.scoped attribute is present: where flow content is expected, but before any other flow content other than other style elements and inter-element whitespace.type attribute.mediatypescopedtitle attribute has special semantics on this element.interface HTMLStyleElement : HTMLElement {
attribute boolean disabled;
attribute DOMString media;
attribute DOMString type;
attribute boolean scoped;
};
The LinkStyle interface must also be implemented
by this element, the styling processing model defines
how. [CSSOM]
The style element allows authors to embed style
information in their documents. The style element is
one of several inputs to the styling processing
model.
If the type
attribute is given, it must contain a valid MIME type, optionally
with parameters, that designates a styling language. [RFC2046] If the attribute is absent, the
type defaults to text/css. [RFC2138]
When examining types to determine if they support the language, user agents must not ignore unknown MIME parameters — types with unknown parameters must be assumed to be unsupported.
The media
attribute says which media the styles apply to. The value must be a
valid media query. [MQ] User
agents must apply the styles to views while their state
match the listed media, and must not apply them otherwise. [DOM3VIEWS]
The default, if the media attribute is omitted, is
all, meaning that by default styles apply to all
media.
The scoped
attribute is a boolean attribute. If the attribute is
present, then the user agent must apply the specified style
information only to the style element's parent element
(if any), and that element's child nodes. Otherwise, the specified
styles must, if applied, be applied to the entire document.
The title attribute on
style elements defines alternative style sheet
sets. If the style element has no title attribute, then it has no
title; the title attribute of
ancestors does not apply to the style element.
The title
attribute on style elements, like the title attribute on link
elements, differs from the global title attribute in that a
style block without a title does not inherit the title
of the parent element: it merely has no title.
All descendant elements must be processed, according to their
semantics, before the style element itself is
evaluated. For styling languages that consist of pure text, user
agents must evaluate style elements by passing the
concatenation of the contents of all the text nodes that are direct children of the
style element (not any other nodes such as comments or
elements), in tree order, to the style system. For
XML-based styling languages, user agents must pass all the children
nodes of the style element to the style system.
This specification does not specify a style system, but CSS is expected to be supported by most Web browsers. [CSS21]
The media, type and scoped DOM attributes
must reflect the respective content attributes of the
same name.
The DOM disabled attribute
behaves as defined for the
alternative style sheets DOM.
The link and style elements can provide
styling information for the user agent to use when rendering the
document. The DOM Styling specification specifies what styling
information is to be used by the user agent and how it is to be
used. [CSSOM]
The style and link elements implement
the LinkStyle interface. [CSSOM]
For style elements, if the user agent does not
support the specified styling language, then the sheet attribute of the element's
LinkStyle interface must return null. Similarly,
link elements that do not represent external resource links that contribute to
the styling processing model (i.e. that do not have a stylesheet keyword in their rel attribute), and link
elements whose specified resource has not yet been fetched, or is
not in a supported styling language, must have their
LinkStyle interface's sheet attribute return null.
Otherwise, the LinkStyle interface's sheet attribute must return a
StyleSheet object with the attributes implemented as
follows: [CSSOM]
type DOM attribute)The content type must be the same as the style's specified
type. For style elements, this is the same as the
type content attribute's
value, or text/css if that is omitted. For
link elements, this is the Content-Type metadata of the specified
resource.
href DOM attribute)For link elements, the location must be the
result of resolving the
URL given by the element's href content attribute, or the empty
string if that fails. For style elements, there is no
location.
media DOM attribute)The media must be the same as the value of the element's
media content attribute.
title DOM attribute)The title must be the same as the value of the element's
title content attribute. If the attribute is
absent, then the style sheet does not have a title. The title is
used for defining alternative style sheet sets.
The disabled DOM
attribute on link and style elements must
return false and do nothing on setting, if the sheet attribute of their
LinkStyle interface is null. Otherwise, it must return
the value of the StyleSheet interface's disabled attribute on
getting, and forward the new value to that same attribute on
setting.
Scripts allow authors to add interactivity to their documents.
Authors are encouraged to use declarative alternatives to scripting where possible, as declarative mechanisms are often more maintainable, and many users disable scripting.
For example, instead of using script to show or hide a section
to show more details, the details element could be
used.
Authors are also encouraged to make their applications degrade gracefully in the absence of scripting support.
For example, if an author provides a link in a table header to dynamically resort the table, the link could also be made to function without scripts by requesting the sorted table from the server.
script elementsrc
attribute, depends on the value of the type attribute.src
attribute, the element must be empty.srcasyncdefertypecharsetinterface HTMLScriptElement : HTMLElement {
attribute DOMString src;
attribute boolean async;
attribute boolean defer;
attribute DOMString type;
attribute DOMString charset;
attribute DOMString text;
};
The script element allows authors to include dynamic
script and data blocks in their documents.
When used to include dynamic scripts, the scripts may either be
embedded inline or may be imported from an external file using the
src attribute. If the language
is not that described by "text/javascript",
then the type attribute must
be present. If the type
attribute is present, its value must be the type of the script's
language.
When used to include data blocks, the data must be embedded
inline, the format of the data must be given using the type attribute, and the src attribute must not be
specified.
The type
attribute gives the language of the script or format of the data. If
the attribute is present, its value must be a valid MIME type,
optionally with parameters. The charset
parameter must not be specified. (The default, which is used if the
attribute is absent, is "text/javascript".) [RFC2046]
The src
attribute, if specified, gives the address of the external script
resource to use. The value of the attribute must be a valid
URL identifying a script resource of the type given by the
type attribute, if the
attribute is present, or of the type "text/javascript", if the attribute is absent.
The charset
attribute gives the character encoding of the external script
resource. The attribute must not be specified if the src attribute is not present. If the
attribute is set, its value must be a valid character encoding name,
and must be the preferred name for that encoding. [IANACHARSET]
The encoding specified must be the encoding used by the script
resource. If the charset
attribute is omitted, the character encoding of the document will be
used. If the script resource uses a different encoding than the
document, then the attribute must be specified.
The async and
defer attributes
are boolean attributes that
indicate how the script should be executed.
There are three possible modes that can be selected using these
attributes. If the async
attribute is present, then the script will be executed
asynchronously, as soon as it is available. If the async attribute is not present but
the defer attribute is
present, then the script is executed when the page has finished
parsing. If neither attribute is present, then the script is
fetched and executed immediately, before the user agent continues
parsing the page. The exact processing details for these attributes
is described below.
The defer attribute may be
specified even if the async
attribute is specified, to cause legacy Web browsers that only
support defer (and not async) to fall back to the defer behavior instead of the
synchronous blocking behavior that is the default.
Changing the src, type, charset, async, and defer attributes dynamically has no
direct effect; these attribute are only used at specific times
described below (namely, when the element is inserted into the document).
script elements have four associated pieces of
metadata. The first is a flag indicating whether or not the script
block has been "already executed". Initially,
script elements must have this flag unset (script
blocks, when created, are not "already executed"). When a
script element is cloned, the "already executed" flag,
if set, must be propagated to the clone when it is created. The
second is a flag indicating whether the element was
"parser-inserted". This flag is set by the HTML
parser and is used to handle document.write() calls. The
third and fourth pieces of metadata are the script's
type and the script's character
encoding. They are determined when the script is run,
based on the attributes on the element at that time.
When an XML parser creates a script
element, it must be marked as being
"parser-inserted". When the element's end tag is
parsed, the user agent must run the script element.
Equivalent requirements exist for the HTML parser, but they are detailed in that section instead.
When a script element that is marked as neither
having "already executed" nor being
"parser-inserted" is inserted into a document, the user agent
must run the
script element.
Running a script: When a
script element is to be run, the user agent must act as
follows:
If either:
script element has a type attribute and its value is
the empty string, orscript element has no type attribute but it has a language attribute and
that attribute's value is the empty string, orscript element has neither a type attribute nor a language attribute, then...let the script's type for this
script element be "text/javascript".
Otherwise, if the script element has a type attribute, let the
script's type for this script element be the
value of that attribute.
Otherwise, the element has a language attribute; let
the script's type for this script element
be the concatenation of the string "text/"
followed by the value of the language attribute.
If the script element has a charset attribute, then let
the script's character encoding for this
script element be the encoding given by the charset attribute.
Otherwise, let the script's character encoding for
this script element be the same as the encoding of the document
itself.
If the script element is without
script, or if the script element was created
by an XML parser that itself was created as part of
the processing of the innerHTML attribute's setter, or if the user agent does not support the
scripting language given by the script's type
for this script element, then the user agent must
abort these steps at this point. The script is not executed.
The user agent must set the element's "already executed" flag.
If the element has a src
attribute, then the specified resource must be fetched.
For historical reasons, if the URL is a javascript:
URL, then the user agent must not, despite the requirements
in the definition of the fetching
algorithm, actually execute the given script; instead the user
agent must act as if it had received an empty HTTP 400
response.
Once the fetching process has completed, and the script has completed loading, the user agent will have to complete the steps described below. (If the parser is still active at that time, those steps defer to the parser to handle the execution of pending scripts.)
For performance reasons, user agents may start fetching the
script as soon as the attribute is set, instead, in the hope that
the element will be inserted into the document. Either way, once
the element is inserted into the document, the load must have
started. If the UA performs such prefetching, but the element is
never inserted in the document, or the src attribute is dynamically
changed, then the user agent will not execute the script, and the
fetching process will have been effectively wasted.
Then, the first of the following options that describes the situation must be followed:
defer attribute, and the
element does not have an async attributeThis isn't compatible with IE for inline deferred scripts, but then what IE does is pretty hard to pin down exactly. Do we want to keep this like it is? Be more compatible?
async attribute and a src attributeasync attribute but no src attribute, and the list
of scripts that will execute asynchronously is not
emptysrc
attribute and has been flagged as
"parser-inserted"src
attributeWhen a script completes loading: If the script's element was added to one of the lists mentioned above and the document is still being parsed, then the parser handles it. Otherwise, the UA must run the following steps as the task that the networking task source places on the task queue:
If the script's element is not the first element in the list, then do nothing yet. Stop going through these steps.
Otherwise, execute the script (that is, the script associated with the first element in the list).
Remove the script's element from the list (i.e. shift out the first entry in the list).
If there are any more entries in the list, and if the script associated with the element that is now the first in the list is already loaded, then jump back to step two to execute it.
If the script is not the first element in the list, then do nothing yet. Stop going through these steps.
Execute the script (the script associated with the first element in the list).
Remove the script's element from the list (i.e. shift out the first entry in the list).
If there are any more scripts in the list, and the element
now at the head of the list had no src attribute when it was added
to the list, or had one, but its associated script has finished
loading, then jump back to step two to execute the script
associated with this element.
Remove the script's element from the list.
Fetching an external script must delay the load event.
Executing a script block: When the steps above require that the script be executed, the user agent must act as follows:
Executing the script must just consist of firing an error
event at the element.
If the script element's Document is
the active document in its browsing
context, the user agent must execute the script:
That file must be used as the file to execute.
The file must be interpreted using the character encoding given by the script's character encoding, regardless of any metadata given by the file's Content-Type metadata.
This means that a UTF-16 document will always assume external scripts are UTF-16...? This applies, e.g., to document's created using createDocument()... It also means changing document.charSet will affect the character encoding used to interpret scripts, is that really what happens?
For scripting languages that consist of pure text, user
agents must use the value of the DOM text attribute (defined below) as
the script to execute, and for XML-based scripting languages,
user agents must use all the child nodes of the
script element as the script to execute.
In any case, the user agent must execute the script according to the semantics defined by the language associated with the script's type (see the scripting languages section below).
The script execution context of the script must
be the Window object of that browsing
context.
The script document context of the script must
be the Document object that owns the
script element.
The element's attributes' values might have changed
between when the element was inserted into the document and when the
script has finished loading, as may its other attributes; similarly,
the element itself might have been taken back out of the DOM, or had
other changes made. These changes do not in any way affect the above
steps; only the values of the attributes at the time the
script element is first inserted into the document
matter.
Then, the user agent must fire a load event at the
script element.
The DOM attributes src, type, charset, async, and defer, each must
reflect the respective content attributes of the same
name.
The DOM attribute text must return a
concatenation of the contents of all the text nodes that are direct children of the
script element (ignoring any other nodes such as
comments or elements), in tree order. On setting, it must act the
same way as the textContent DOM attribute.
In this example, two script elements are used. One
embeds an external script, and the other includes some data.
<script src="game-engine.js"></script> <script type="text/x-game-map"> ........U.........e o............A....e .....A.....AAA....e .A..AAA...AAAAA...e </script>
The data in this case might be used by the script to generate the map of a video game. The data doesn't have to be used that way, though; maybe the map data is actually embedded in other parts of the page's markup, and the data block here is just used by the site's search engine to help users who are looking for particular features in their game maps.
A user agent is said to support the scripting language if the script's type matches the MIME type of a scripting language that the user agent implements.
The following lists some MIME types and the languages to which they refer:
text/javascripttext/javascript1.1text/javascript1.2text/javascript1.3text/javascript;e4x=1User agents may support other MIME types and other languages.
When examining types to determine if they support the language, user agents must not ignore unknown MIME parameters — types with unknown parameters must be assumed to be unsupported.
noscript elementhead element of an HTML document, if there are no ancestor noscript elements.noscript elements.head element: in any order, zero or more link elements, zero or more style elements, and zero or more meta elements.head element: transparent, but there must be no noscript element descendants.HTMLElement.The noscript element does not represent anything. It
is used to present different markup to user agents that support
scripting and those that don't support scripting, by affecting how
the document is parsed.
The noscript element must not be used in XML
documents.
The noscript element is only
effective in the HTML serialization, it has no effect in the XML
serialization.
When used in HTML documents, the allowed content model is as follows:
In a head element, if the noscript
element is without script, then the content model of a
noscript element must contain only link,
style, and meta elements. If the
noscript element is with script, then the
content model of a noscript element is text, except
that invoking the HTML fragment parsing algorithm with
the noscript element as the context
element and the text contents as the input must
result in a list of nodes that consists only of link,
style, and meta elements.
Outside of head elements, if the
noscript element is without script, then
the content model of a noscript element is
transparent, with the additional restriction that a
noscript element must not have a noscript
element as an ancestor (that is, noscript can't be
nested).
Outside of head elements, if the
noscript element is with script, then the
content model of a noscript element is text, except
that the text must be such that running the following algorithm
results in a conforming document with no noscript
elements and no script elements, and such that no step
in the algorithm causes an HTML parser to flag a
parse error:
script element from the
document.noscript element in the
document. For every noscript element in that list,
perform the following steps:
noscript element.noscript element, and call these
elements the before children.noscript element, and
call these elements the after children.noscript
element.innerHTML
attribute of the parent element to the value
of s. (This, as a side-effect, causes the
noscript element to be removed from the
document.)The noscript element has no other requirements. In
particular, children of the noscript element are not
exempt from form submission, scripting, and so forth, even when the
element is with script.
All these contortions are required because, for
historical reasons, the noscript element is handled
differently by the HTML parser based on whether scripting was enabled or not when the
parser was invoked. The element is not allowed in XML, because in
XML the parser is not affected by such state, and thus the element
would not have the desired effect.
The noscript element interacts poorly
with the designMode
feature. Authors are encouraged to not use noscript
elements on pages that will have designMode enabled.
eventsource elementsrcinterface HTMLEventSourceElement : HTMLElement {
attribute DOMString src;
};
The eventsource element represents a target for
events generated by a remote server.
The src
attribute, if specified, must give a valid URL
identifying a resource that uses the text/event-stream
format.
When an eventsource element with a src attribute specified is inserted into the
document, and when an eventsource element that
is already in the document has a src attribute added, the user
agent must run the add declared event source
algorithm.
While an eventsource element is in a document, if its src
attribute is mutated, the user agent must must run the remove
declared event source algorithm followed by the add
declared event source algorithm.
When an eventsource element with a src attribute specified is
removed from a document, and when an
eventsource element that is in a document with a src
attribute specified has its src attribute removed, the user
agent must run the remove declared event source
algorithm.
When it is created, an eventsource element must
have its current declared event source set to
"undefined".
The add declared event source algorithm is as follows:
eventsource element's src attribute.addEventSource()
method on the eventsource element had been invoked
with the resulting absolute URL.The remove declared event source algorithm is as follows:
removeEventSource()
method on the eventsource element had been invoked
with the element's current declared event source.There can be more than one eventsource element per
document, but authors should take care to avoid opening multiple
connections to the same server as HTTP recommends a limit to the
number of simultaneous connections that a user agent can open per
server.
The src DOM
attribute must reflect the content attribute of the
same name.
Some elements, for example
address elements, are scoped to their nearest ancestor
sectioning content. For such elements x, the elements that apply to a sectioning
content element e are all the x elements whose nearest sectioning
content ancestor is e.
body elementhtml element.interface HTMLBodyElement : HTMLElement {};
The body element represents the main content of the
document.
In conforming documents, there is only one body
element. The document.body
DOM attribute provides scripts with easy access to a document's
body element.
Some DOM operations (for example, parts of the
drag and drop model) are defined in terms of "the
body element". This refers to a particular element in the
DOM, as per the definition of the term, and not any arbitrary
body element.
section elementHTMLElement.The section element represents a generic document or
application section. A section, in this context, is a thematic
grouping of content, typically with a header, possibly with a
footer.
Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, contact information.
nav elementHTMLElement.The nav element represents a section of a page that
links to other pages or to parts within the page: a section with
navigation links. Not all groups of links on a page need to be in a
nav element — only sections that consist of
primary navigation blocks are appropriate for the nav
element. In particular, it is common for footers to have a list of
links to various key parts of a site, but the footer
element is more appropriate in such cases.
In the following example, the page has several places where links are present, but only one of those places is considered a navigation section.
<body>
<header>
<h1>Wake up sheeple!</h1>
<p><a href="news.html">News</a> -
<a href="blog.html">Blog</a> -
<a href="forums.html">Forums</a></p>
</header>
<nav>
<h1>Navigation</h1>
<ul>
<li><a href="articles.html">Index of all articles</a><li>
<li><a href="today.html">Things sheeple need to wake up for today</a><li>
<li><a href="successes.html">Sheeple we have managed to wake</a><li>
</ul>
</nav>
<article>
<p>...page content would be here...</p>
</article>
<footer>
<p>Copyright © 2006 The Example Company</p>
<p><a href="about.html">About</a> -
<a href="policy.html">Privacy Policy</a> -
<a href="contact.html">Contact Us</a></p>
</footer>
</body>
article elementHTMLElement.The article element represents a section of a page
that consists of a composition that forms an independent part of a
document, page, or site. This could be a forum post, a magazine or
newspaper article, a Web log entry, a user-submitted comment, or any
other independent item of content.
An article element is "independent" in
that its contents could stand alone, for example in syndication.
However, the element is still associated with its ancestors; for
instance, contact information that applies to a parent body
element still covers the article as well.
When article elements are nested, the inner
article elements represent articles that are in
principle related to the contents of the outer article. For
instance, a Web log entry on a site that accepts user-submitted
comments could represent the comments as article
elements nested within the article element for the Web
log entry.
Author information associated with an article
element (q.v. the address element) does not apply to
nested article elements.
aside elementHTMLElement.The aside element represents a section of a page
that consists of content that is tangentially related to the content
around the aside element, and which could be considered
separate from that content. Such sections are often represented as
sidebars in printed typography.
The following example shows how an aside is used to mark up background material on Switzerland in a much longer news story on Europe.
<aside> <h1>Switzerland</h1> <p>Switzerland, a land-locked country in the middle of geographic Europe, has not joined the geopolitical European Union, though it is a signatory to a number of European treaties.</p> </aside>
The following example shows how an aside is used to mark up a pull quote in a longer article.
... <p>He later joined a large company, continuing on the same work. <q>I love my job. People ask me what I do for fun when I'm not at work. But I'm paid to do my hobby, so I never know what to answer. Some people wonder what they would do if they didn't have to work... but I know what I would do, because I was unemployed for a year, and I filled that time doing exactly what I do now.</q></p> <aside> <q> People ask me what I do for fun when I'm not at work. But I'm paid to do my hobby, so I never know what to answer. </q> </aside> <p>Of course his work — or should that be hobby? — isn't his only passion. He also enjoys other pleasures.</p> ...
h1, h2,
h3, h4,
h5, and h6
elementsHTMLElement.These elements define headers for their sections.
The semantics and meaning of these elements are defined in the section on headings and sections.
These elements have a rank given by the number in
their name. The h1 element is said to have the highest
rank, the h6 element has the lowest rank, and two
elements with the same name have equal rank.
header elementheader element
descendants, and no footer element descendants.HTMLElement.