p
elementhr
elementpre
elementblockquote
elementol
elementul
elementli
elementdl
elementdt
elementdd
elementfigure
elementfigcaption
elementmain
elementdiv
elementa
elementem
elementstrong
elementsmall
elements
elementcite
elementq
elementdfn
elementabbr
elementruby
elementrb
elementrt
elementrtc
elementrp
elementdata
elementtime
elementcode
elementvar
elementsamp
elementkbd
elementsub
and sup
elementsi
elementb
elementu
elementmark
elementbdi
elementbdo
elementspan
elementbr
elementwbr
elementa
and area
elementsa
and area
elementsalternate
"author
"bookmark
"help
"icon
"license
"nofollow
"noreferrer
"prefetch
"search
"stylesheet
"tag
"picture
elementsource
element when used with the picture
elementimg
elementpicture
elementiframe
elementembed
elementobject
elementparam
elementvideo
elementaudio
elementsource
elementtrack
elementTrackEvent
interfacemap
elementarea
elementtable
elementcaption
elementcolgroup
elementcol
elementtbody
elementthead
elementtfoot
elementtr
elementtd
elementth
elementtd
and th
elementsform
elementlabel
elementinput
elementtype
attributetype=hidden
)type=text
) state and Search state (type=search
)type=tel
)type=url
)type=email
)type=password
)type=datetime
)type=date
)type=month
)type=week
)type=time
)type=number
)type=range
)type=color
)type=checkbox
)type=radio
)type=file
)type=submit
)type=image
)type=reset
)type=button
)input
element attributesmaxlength
and minlength
attributessize
attributereadonly
attributerequired
attributemultiple
attributepattern
attributemin
and max
attributesstep
attributelist
attributeplaceholder
attributeinput
element APIsbutton
elementselect
elementdatalist
elementoptgroup
elementoption
elementtextarea
elementkeygen
elementoutput
elementprogress
elementmeter
elementfieldset
elementlegend
elementname
attributedirname
attributemaxlength
attributeminlength
attributedisabled
attributeinputmode
attributedetails
elementsummary
elementmenu
elementmenuitem
elementa
element to define a commandbutton
element to define a commandinput
element to define a commandoption
element to define a commandmenuitem
element to define a
commandcommand
attribute on menuitem
elements to define
a command indirectlyaccesskey
attribute
on a label
element to define a commandaccesskey
attribute
on a legend
element to define a commandaccesskey
attribute to define a command on other elementsdialog
elementhtml
elementhead
element followed by a body
element.html
element's start tag can be omitted
if the first thing inside the html
element is not a comment.html
element's end tag can be omitted if
the html
element is not immediately followed by a comment.manifest
— Application cache manifestinterface HTMLHtmlElement : HTMLElement { // also has obsolete members };
The html
element represents the root of an HTML document.
Authors are encouraged to specify a lang
attribute on the root
html
element, giving the document's language. This aids speech synthesis tools to
determine what pronunciations to use, translation tools to determine what rules to use, and so
forth.
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 non-empty URL potentially surrounded by
spaces.
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).
For the purposes of application cache
selection, later base
elements cannot affect the resolving of relative URLs in manifest
attributes, as the attributes are processed before those elements are seen.
The window.applicationCache
IDL
attribute provides scripted access to the offline application cache mechanism.
The html
element in the following example declares that the document's language
is English.
<!DOCTYPE html> <html lang="en"> <head> <title>Swapping Songs</title> </head> <body> <h1>Swapping Songs</h1> <p>Tonight I swapped some of the songs I wrote with some friends, who gave me some of the songs they wrote. I love sharing my music.</p> </body> </html>
head
elementhtml
element.iframe
srcdoc
document or if title information is available from a higher-level protocol: Zero or more elements of metadata content, of which no more than one is a title
element and no more than one is a base
element.title
element and no more than one is a base
element.head
element's start tag can be omitted if
the element is empty, or if the first thing inside the head
element is an
element.head
element's end tag can be omitted if the
head
element is not immediately followed by a space character or a comment.interface HTMLHeadElement : HTMLElement {};
The head
element represents a collection of metadata for the
Document
.
The collection of metadata in a head
element can be large or small. Here is an
example of a very short one:
<!doctype html> <html> <head> <title>A document with a short head</title> </head> <body> ...
Here is an example of a longer one:
<!DOCTYPE HTML> <HTML> <HEAD> <META CHARSET="UTF-8"> <BASE HREF="http://www.example.com/"> <TITLE>An application with a long head</TITLE> <LINK REL="STYLESHEET" HREF="default.css"> <LINK REL="STYLESHEET ALTERNATE" HREF="big.css" TITLE="Big Text"> <SCRIPT SRC="support.js"></SCRIPT> <META NAME="APPLICATION-NAME" CONTENT="Long headed application"> </HEAD> <BODY> ...
The title
element is a required child in most situations, but when a
higher-level protocol provides title information, e.g. in the Subject line of an e-mail when HTML
is used as an e-mail authoring format, the title
element can be omitted.
title
elementhead
element containing no other title
elements.interface HTMLTitleElement : HTMLElement { attribute DOMString text; };
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 heading, since the first heading does not have to stand alone when taken
out of context.
There must be no more than one title
element per document.
If it's reasonable for the Document
to have no title, then the
title
element is probably not required. See the head
element's content
model for a description of when the element is required.
text
[ = value ]Returns the contents of the element, ignoring child nodes that aren't Text
nodes.
Can be set, to replace the element's children with the given value.
The IDL attribute text
must return a
concatenation of the contents of all the Text
nodes that are children of the
title
element (ignoring any other nodes such as comments or elements), in tree order.
On setting, it must act the same way as the textContent
IDL attribute.
Here are some examples of appropriate titles, contrasted with the top-level headings 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 heading assumes the reader knows 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
IDL attribute.
User agents should use the document's title when referring to the document in their user
interface. When the contents of a title
element are used in this way, the
directionality of that title
element should be used to set the directionality
of the document's title in the user interface.
base
elementhead
element containing no other base
elements.href
— Document base URLtarget
— Default browsing context for hyperlink navigation and form submissioninterface 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. The
element does not represent any content beyond this
information.
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 potentially surrounded by spaces.
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, which specifies which
browsing context is to be used as the default when hyperlinks and forms in the
Document
cause navigation.
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.
A base
element that is the first base
element with an href
content attribute in a particular Document
has a
frozen base URL. The frozen base URL must be immediately set whenever any of the following situations occur:
base
element becomes the first base
element in tree
order with an href
content attribute in its
Document
.base
element is the first base
element in tree
order with an href
content attribute in its
Document
, and its href
content attribute is
changed.To set the frozen base URL, resolve the value of
the element's href
content attribute relative to the
Document
's fallback base URL; if this is successful, set the
frozen base URL to the resulting absolute URL, otherwise, set the
frozen base URL to the fallback base URL.
The href
IDL attribute, on getting, must return
the result of running the following algorithm:
If the base
element has no href
content
attribute, then return the document base URL and abort these steps.
Let fallback base url be the Document
's fallback
base URL.
Let url be the value of the href
attribute of the base
element.
Resolve url relative to fallback base
url (thus, the base
's href
attribute
isn't affected by other base
elements).
If the previous step was successful, return the resulting absolute URL and abort these steps.
Otherwise, return the empty string.
The href
IDL attribute, on setting, must set the href
content attribute to the given new value.
The target
IDL attribute must
reflect the content attribute of the same name.
In this example, a base
element is used to set the document base
URL:
<!DOCTYPE html> <html> <head> <title>This is an example for the <base> element</title> <base href="http://www.example.com/news/index.html"> </head> <body> <p>Visit the <a href="archives.html">archives</a>.</p> </body> </html>
The link in the above example would be a link to "http://www.example.com/news/archives.html
".
link
elementitemprop
attribute is present: flow content.itemprop
attribute is present: phrasing content.noscript
element that is a child of a head
element.itemprop
attribute is present: where phrasing content is expected.href
— Address of the hyperlinkcrossorigin
— How the element handles crossorigin requestsrel
— Relationship between the document containing the hyperlink and the destination resourcemedia
— Applicable mediahreflang
— Language of the linked resourcetype
— Hint for the type of the referenced resourcesizes
— Sizes of the icons (for rel
="icon
")title
attribute has special semantics on this element: Title of the link; alternative style sheet set name.link
(default - do not set).aria-*
attributes applicable to the allowed roles.role
value interface HTMLLinkElement : HTMLElement { attribute DOMString href; attribute DOMString? crossOrigin; attribute DOMString rel; readonly attribute DOMTokenList relList; attribute DOMString media; attribute DOMString hreflang; attribute DOMString type; [PutForwards=value] readonly attribute DOMSettableTokenList sizes; // also has obsolete members }; HTMLLinkElement implements LinkStyle;
The link
element allows authors to link their document to other resources.
The destination of the link(s) is given by the href
attribute, which must be present and must contain a
valid non-empty URL potentially surrounded by spaces. If the href
attribute is absent, then the element does not define a
link.
A link
element must have either a rel
attribute
or an itemprop
attribute, but not both.
If the rel
attribute is used, the element is
restricted to the head
element. When used with the itemprop
attribute, the element can be used both in the
head
element and in the body
of the page, subject to the constraints of
the microdata model.
The types of link indicated (the relationships) are given by the value of the rel
attribute, which, if present, must have a value that
is a set of space-separated tokens. The allowed keywords and
their meanings are defined in a later section. If the rel
attribute is absent, has no keywords, or if none of the keywords
used are allowed according to the definitions in this specification, then the element does not
create any links.
Two categories of links can be created using the link
element: Links to external resources and hyperlinks. The link types section defines
whether a particular link type is an external resource or a hyperlink. One link
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.
Each link created for a link
element is handled separately. For
instance, if there are two link
elements with rel="stylesheet"
,
they each count as a separate external resource, and each is affected by its own attributes
independently. Similarly, if a single link
element has a rel
attribute with the value next stylesheet
,
it creates both a hyperlink (for the next
keyword) and
an external resource link (for the stylesheet
keyword), and they are affected by other attributes (such as media
or title
)
differently.
For example, the following link
element creates two hyperlinks (to the same
page):
<link rel="author license" href="/about">
The two links created by this element are one whose semantic is that the target page has information about the current page's author, and one whose semantic is that the target page has information regarding the license under which the current page is provided.
The crossorigin
attribute is a CORS
settings attribute. It is intended for use with external resource links.
The exact behaviour 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 (modulo cross-origin restrictions) even if the resource is not applied. To obtain the resource, the user agent must run the following steps:
If the href
attribute's value is the empty string,
then abort these steps.
Resolve the URL given by the href
attribute, relative to the element.
If the previous step fails, then abort these steps.
Let corsAttributeState be the current state of the element's crossorigin
content attribute.
Let request be the result of creating a potential-CORS request given the absolute URL and corsAttributeState.
Set request's client to the
link
element's node document's Window
object's
environment settings object.
Fetch request.
User agents may opt to only try to obtain 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 will be followed and 404 responses will cause the external resource to not be applied.)
Once the attempts to obtain the resource and its critical subresources are
complete, the user agent must, if the loads were successful, queue a task to
fire a simple event named load
at the
link
element, or, if the resource or one of its critical subresources
failed to completely load for any reason (e.g. DNS error, HTTP 404 response, a connection being
prematurely closed, unsupported Content-Type), queue a task to fire a simple
event named error
at the link
element.
Non-network errors in processing the resource or its subresources (e.g. CSS parse errors, PNG
decoding errors) are not failures for the purposes of this paragraph.
The task source for these tasks is the DOM manipulation task source.
The element must delay the load event of the element's node document until all the attempts to obtain the resource and its critical subresources are complete. (Resources that the user agent has not yet attempted to obtain, e.g. because it is waiting for the resource to be needed, do not delay the load event.)
Interactive user agents may 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
could 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 could 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 list.
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 when the media
attribute's value
matches the environment and the other relevant conditions apply, and must not apply
it otherwise.
The external resource might have further restrictions defined within that limit
its applicability. For example, a CSS style sheet might have some @media
blocks. This specification does not override such further restrictions or requirements.
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 a
and
area
elements.
The type
attribute gives the MIME
type of the linked resource. It is purely advisory. The value must be a valid MIME
type.
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 (even if that is not a
valid MIME type, e.g. the empty string). 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 obtain
the resource; if the UA does support the given MIME type for the given link
relationship, then the UA should obtain the resource at
the appropriate time as specified for the external resource link's particular type.
If the attribute is omitted, and the external resource link type does not have a default type
defined, but the user agent would obtain the resource if
the type was known and supported, then the user agent should obtain 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 external resource link type defines rules for processing the resource's Content-Type metadata, then those rules apply. Otherwise, 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 neither of these conditions apply or if the user agent opts not to apply the image sniffing 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.
The stylesheet
link type defines rules for
processing the resource's Content-Type metadata.
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 of 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.
The activation behaviour of link
elements that create hyperlinks is to run the following steps:
If the link
element's node document is not fully active,
then abort these steps.
Follow the hyperlink created by the
link
element.
HTTP `Link
` headers, if supported, must be assumed to come
before any links in the document, in the order that they were given in the HTTP message. These
headers are to be processed according to the rules given in the relevant specifications. [HTTP] [WEBLINK]
Registration of relation types in HTTP `Link
`
headers is distinct from HTML link types, and thus their semantics can be
different from same-named HTML types.
The IDL attributes href
, rel
, media
,
hreflang
, type
, and sizes
each must reflect the respective
content attributes of the same name.
The crossOrigin
IDL attribute must
reflect the crossorigin
content attribute.
The IDL attribute relList
must reflect the rel
content attribute.
The LinkStyle
interface is also implemented by this element. [CSSOM]
Here, a set of link
elements provide some style sheets:
<!-- a persistent style sheet --> <link rel="stylesheet" href="default.css"> <!-- the preferred alternate style sheet --> <link rel="stylesheet" href="green.css" title="Green styles"> <!-- some alternate style sheets --> <link rel="alternate stylesheet" href="contrast.css" title="High contrast"> <link rel="alternate stylesheet" href="big.css" title="Big fonts"> <link rel="alternate stylesheet" href="wide.css" title="Wide screen">
The following example shows how you can specify versions of the page that use alternative formats, are aimed at other languages, and that are intended for other media:
<link rel=alternate href="/en/html" hreflang=en type=text/html title="English HTML"> <link rel=alternate href="/fr/html" hreflang=fr type=text/html title="French HTML"> <link rel=alternate href="/en/html/print" hreflang=en type=text/html media=print title="English HTML (for printing)"> <link rel=alternate href="/fr/html/print" hreflang=fr type=text/html media=print title="French HTML (for printing)"> <link rel=alternate href="/en/pdf" hreflang=en type=application/pdf title="English PDF"> <link rel=alternate href="/fr/pdf" hreflang=fr type=application/pdf title="French PDF">
meta
elementitemprop
attribute is present: flow content.itemprop
attribute is present: phrasing content.charset
attribute is present, or if the element's http-equiv
attribute is in the Encoding declaration state: in a head
element.http-equiv
attribute is present but not in the Encoding declaration state: in a head
element.http-equiv
attribute is present but 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.itemprop
attribute is present: where metadata content is expected.itemprop
attribute is present: where phrasing content is expected.name
— Metadata namehttp-equiv
— Pragma directivecontent
— Value of the elementcharset
— Character encoding declarationinterface HTMLMetaElement : HTMLElement { attribute DOMString name; attribute DOMString httpEquiv; attribute DOMString content; // also has obsolete members };
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 serialised 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
, charset
,
and itemprop
attributes must be specified.
If either name
, http-equiv
, or itemprop
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 a character encoding declaration. If the
attribute is present in an XML document, its value must be an
ASCII case-insensitive match for the string "UTF-8
" (and the
document is therefore forced to use UTF-8 as its encoding).
The charset
attribute on the
meta
element has no effect in XML documents, and is only allowed in order to
facilitate migration to and from XHTML.
There must not be more than one meta
element with a charset
attribute per document.
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.
The name
and content
IDL attributes must reflect the
respective content attributes of the same name. The IDL attribute httpEquiv
must reflect the content
attribute http-equiv
.
This specification defines a few names for the name
attribute of the meta
element.
Names are case-insensitive, and must be compared in an ASCII case-insensitive manner.
application-name
The value must be a short free-form string 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.
Translations of the Web application's name may be given, using the lang
attribute to specify the language of each name.
There must not be more than one meta
element with a given language
and with its name
attribute set to the value application-name
per document.
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.
To find the application name to use given an ordered list of languages (e.g. British English, American English, and English), user agents must run the following steps:
Let languages be the list of languages.
Let default language be the language of the
Document
's root element,
if any, and if that language is not unknown.
If there is a default language, and if it is not the same language as any of the languages in languages, append it to languages.
Let winning language be the first language in languages for which there is a meta
element in the
Document
that has its name
attribute set to
the value application-name
and whose
language is the language in question.
If none of the languages have such a meta
element, then abort these steps;
there's no given application name.
Return the value of the content
attribute of the
first meta
element in the Document
in tree order that
has its name
attribute set to the value application-name
and whose language is winning language.
This algorithm would be used by a browser when it needs a name for the page, for instance, to label a bookmark. The languages it would provide to the algorithm would be the user's preferred languages.
author
The value must be a free-form string giving the name of one of the page's authors.
description
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. There must not be more than
one meta
element with its name
attribute set to
the value description
per document.
generator
The value must be a free-form string that identifies one of the software packages used to generate the document. This value must not be used on pages whose markup is not generated by software, e.g. pages whose markup was written by a user in a text editor.
Here is what a tool called "Frontweaver" could include in its output, in the page's
head
element, to identify itself as the tool used to generate the page:
<meta name=generator content="Frontweaver 8.2">
keywords
The value must be a set of comma-separated tokens, each of which is a keyword relevant to the page.
This page about typefaces on British motorways uses a meta
element to specify
some keywords that users might use to look for the page:
<!DOCTYPE HTML> <html> <head> <title>Typefaces on UK motorways</title> <meta name="keywords" content="british,type face,font,fonts,highway,highways"> </head> <body> ...
Many search engines do not consider such keywords, because this feature has historically been used unreliably and even misleadingly as a way to spam search engine results in a way that is not helpful for users.
To obtain the list of keywords that the author has specified as applicable to the page, the user agent must run the following steps:
Let keywords be an empty list.
For each meta
element with a name
attribute and a content
attribute and whose name
attribute's value is keywords
, run the following substeps:
Split the value of the element's content
attribute on commas.
Add the resulting tokens, if any, to keywords.
Remove any duplicates from keywords.
Return keywords. This is the list of keywords that the author has specified as applicable to the page.
User agents should not use this information when there is insufficient confidence in the reliability of the value.
For instance, it would be reasonable for a content management system to use the keyword information of pages within the system to populate the index of a site-specific search engine, but a large-scale content aggregator that used this information would likely find that certain users would try to game its ranking mechanism through the use of inappropriate keywords.
Extensions to the predefined set of metadata names may be registered in the WHATWG Wiki MetaExtensions page. [WHATWGWIKI]
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 non-normative 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. Anyone may remove synonyms that are not used in practice; only names that need to be processed as synonyms for compatibility with legacy content are to be registered in this way.
One of the following:
If a metadata name is found to be redundant with existing values, it should be removed and listed as a synonym for the existing value.
If a metadata name is registered in the "proposed" state for a period of a month or more without being used or specified, then it may be removed from the registry.
If a metadata name is added with the "proposed" status and found to be redundant with existing values, it should be removed and listed as a synonym for the existing value. If a metadata name is added with the "proposed" status and found to be harmful, then it should be changed to "discontinued" status.
Anyone can change the status at any time, but should only do so in accordance with the definitions above.
Conformance checkers may use the information given on the WHATWG Wiki MetaExtensions page to establish if a value is allowed or not: values defined in this specification or marked as "proposed" or "ratified" must be accepted, whereas values marked as "discontinued" or not listed in either this specification or on the aforementioned page must be rejected as invalid. Conformance checkers may cache this information (e.g. for performance reasons or to avoid the use of unreliable network connectivity).
When an author uses a new metadata name 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 "proposed" status.
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 | Keyword | Notes |
---|---|---|
Content Language | content-language
| Non-conforming |
Encoding declaration | content-type
| |
Default style | default-style
| |
Refresh | refresh
| |
Cookie setter | set-cookie
| Non-conforming |
X-UA-Compatible | x-ua-compatible
| |
Content security policy | Content-Security-Policy
|
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:
http-equiv="content-language"
)
This feature is non-conforming. Authors are encouraged to use the lang
attribute instead.
This pragma sets the pragma-set default language. Until such a pragma is successfully processed, there is no pragma-set default language.
If the meta
element has no content
attribute, then abort these steps.
If the element's content
attribute contains a
U+002C COMMA character (,) 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 not space characters.
Let candidate be the string that resulted from the previous step.
If candidate is the empty string, abort these steps.
Set the pragma-set default language to candidate.
If the value consists of multiple space-separated tokens, tokens after the first are ignored.
This pragma is almost, but not quite, entirely unlike the HTTP `Content-Language
` header of the same name. [HTTP]
http-equiv="content-type"
)
The Encoding declaration state is
just an alternative form of setting the charset
attribute: it is a character encoding declaration. This state's user
agent requirements are all handled by the parsing section of the specification.
For meta
elements with an http-equiv
attribute 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 one of the labels of
the character encoding of the character encoding
declaration.
A document must not contain both a meta
element with an http-equiv
attribute in the Encoding declaration state and a
meta
element with the charset
attribute
present.
The Encoding declaration state may be
used in HTML documents, but elements with an http-equiv
attribute in that state must not be used in
XML documents.
http-equiv="default-style"
)
This pragma sets the name of the default alternative style sheet set.
If the meta
element has no content
attribute, or if that attribute's value is the empty string, then abort these steps.
Set the preferred style sheet set to the value of the element's content
attribute. [CSSOM]
http-equiv="refresh"
)
This pragma acts as timed redirect.
If another meta
element with an http-equiv
attribute 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 that are ASCII digits, 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 that are ASCII digits and U+002E FULL STOP characters (.). 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 character (;) or a U+002C COMMA character (,), 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+0055 LATIN CAPITAL LETTER U character (U) or a U+0075 LATIN SMALL LETTER U character (u), 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+0052 LATIN CAPITAL LETTER R character (R) or a U+0072 LATIN SMALL LETTER R character (r), then advance position to the next character. Otherwise, jump to the last step.
If the character in input pointed to by position is s U+004C LATIN CAPITAL LETTER L character (L) or a U+006C LATIN SMALL LETTER L character (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.
If the character in input pointed to by position is either a U+0027 APOSTROPHE character (') or U+0022 QUOTATION MARK character ("), then let quote be that character, and advance position to the next character. Otherwise, let quote be the empty string.
Let url be equal to the substring of input from the character at position to the end of the string.
If quote is not the empty string, and there is a character in url equal to quote, then truncate url at that character, so that it and all subsequent characters are removed.
Strip any trailing space characters from the end of url.
Strip any U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), and U+000D CARRIAGE RETURN (CR) characters from url.
Resolve the url value to an
absolute URL, relative to the meta
element. If this fails, abort
these steps.
Perform one or more of the following steps:
After the refresh has come due (as defined below), if the user has not canceled the
redirect and if the meta
element's node document's active
sandboxing flag set does not have the sandboxed automatic features browsing
context flag set, navigate the
Document
's browsing context to url, with
replacement enabled, and with the Document
's browsing
context as the source browsing context.
For the purposes of the previous paragraph, a refresh is said to have come due as soon as the later of the following two conditions occurs:
meta
element was inserted into the
Document
, adjusted to take into account user or user agent
preferences.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 with an http-equiv
attribute in the Refresh state, the content
attribute must have a value consisting either of:
URL
", followed by a U+003D EQUALS SIGN character (=), followed by a valid
URL that does not start with a literal U+0027 APOSTROPHE (') or U+0022 QUOTATION MARK
(") character.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.
A news organization's front page could include the following markup in the page's
head
element, to ensure that the page automatically reloads from the server every
five minutes:
<meta http-equiv="Refresh" content="300">
A sequence of pages could be used as an automated slide show by making each page refresh to the next page in the sequence, using markup such as the following:
<meta http-equiv="Refresh" content="20; URL=page4.html">
http-equiv="set-cookie"
)
This pragma sets an HTTP cookie. [COOKIES]
It is non-conforming. Real HTTP headers should be used instead.
If the meta
element has no content
attribute, or if that attribute's value is the empty string, then abort these steps.
Act as if receiving a
set-cookie-string for the document's address via a "non-HTTP" API,
consisting of the value of the element's content
attribute encoded as UTF-8. [COOKIES] [ENCODING]
http-equiv="x-ua-compatible"
)
In practice, this pragma encourages Internet Explorer to more closely follow the specifications.
For meta
elements with an http-equiv
attribute in the X-UA-Compatible state, the
content
attribute must have a value that is an
ASCII case-insensitive match for the string "IE=edge
".
User agents are required to ignore this pragma.
http-equiv="content-security-policy"
)
This pragma enforces a Content Security
Policy on a Document
. [CSP]
If the meta
element is not a child of a head
element,
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 policy be the result of executing Content Security Policy's parse
the policy algorithm on the meta
element's
content
attribute's value.
Remove all occurrences of the reflected-xss
, report-uri
, frame-ancestors
, and sandbox
directives from policy.
Enforce the policy policy.
For meta
elements with an http-equiv
attribute in the Content security
policy state, the content
attribute must have a
value consisting of a valid Content Security
Policy, which will be enforced upon the current
document. [CSP]
A page might choose to mitigate the risk of cross-site scripting attacks by preventing the execution of inline JavaScript, as well as blocking all plugin content, using a policy such as the following:
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; object-src 'none'">
There must not be more than one meta
element with any particular state in the
document at a time.
Extensions to the predefined set of pragma directives may, under certain conditions, be registered in the WHATWG Wiki PragmaExtensions page. [WHATWGWIKI]
Such extensions must use a name that is identical to an HTTP header registered in the Permanent Message Header Field Registry, and must have behaviour identical to that described for the HTTP header. [IANAPERMHEADERS]
Pragma directives corresponding to headers describing metadata, or not requiring specific user agent processing, must not be registered; instead, use metadata names. Pragma directives corresponding to headers that affect the HTTP processing model (e.g. caching) must not be registered, as they would result in HTTP-level behaviour being different for user agents that implement HTML than for user agents that do not.
Anyone is free to edit the WHATWG Wiki PragmaExtensions page at any time to add a pragma directive satisfying these conditions. Such registrations must specify the following information:
The actual name being defined. The name must match a previously-registered HTTP name with the same requirements.
A short non-normative description of the purpose of the pragma directive.
Conformance checkers must use the information given on the WHATWG Wiki PragmaExtensions page to establish if a value is allowed or not: values defined in this specification or listed on the aforementioned page must be accepted, whereas values not listed in either this specification or on the aforementioned page must be rejected as invalid. Conformance checkers may cache this information (e.g. for performance reasons or to avoid the use of unreliable network connectivity).
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:
In addition, due to a number of restrictions on meta
elements, there can only be
one meta
-based character encoding declaration per document.
If an HTML document does not start with a BOM, and its
encoding is not explicitly given by Content-Type
metadata, and the document is not an iframe
srcdoc
document, then the character encoding used must be
an ASCII-compatible encoding, and the encoding must be specified using a
meta
element with a charset
attribute or a
meta
element with an http-equiv
attribute
in the Encoding declaration state.
A character encoding declaration is required (either in the Content-Type metadata or explicitly in the file) even if the encoding is US-ASCII, because a character encoding is needed to process non-ASCII characters entered by the user in forms, in URLs generated by scripts, and so forth.
If the document is an iframe
srcdoc
document, the document must not have a character encoding declaration. (In
this case, the source is already decoded, since it is part of the document that contained the
iframe
.)
If an HTML document contains a meta
element
with a charset
attribute or a meta
element
with an http-equiv
attribute in the Encoding declaration state, then the character
encoding used must be an ASCII-compatible encoding.
Authors should use UTF-8. Conformance checkers may advise authors against using legacy encodings. [ENCODING]
Authoring tools should default to using UTF-8 for newly-created documents. [ENCODING]
Authors must not use encodings that are not defined in the WHATWG Encoding standard. Additionally, authors should not use ISO-2022-JP. [ENCODING]
Some encodings that are not defined in the WHATWG Encoding standard use bytes in the range 0x20 to 0x7E, inclusive, to encode characters other than the corresponding characters in the range U+0020 to U+007E, inclusive, and represent a potential security vulnerability: A user agent might end up interpreting supposedly benign plain text content as HTML tags and JavaScript.
Using non-UTF-8 encodings can have unexpected results on form submission and URL encodings, which use the document's character encoding by default.
In XHTML, the XML declaration should be used for inline character encoding information, if necessary.
In HTML, to declare that the character encoding is UTF-8, the author could include the
following markup near the top of the document (in the head
element):
<meta charset="utf-8">
In XML, the XML declaration would be used instead, at the very top of the markup:
<?xml version="1.0" encoding="utf-8"?>
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 inter-element whitespace and style
elements, and not as the child of an element whose content model is transparent.type
attribute, but must match requirements described in prose below.media
— Applicable medianonce
— Cryptographic nonce used in Content Security Policy checks [CSP]type
— Type of embedded resourcescoped
— Whether the styles apply to the entire document or just the parent subtreetitle
attribute has special semantics on this element: Alternative style sheet set name.interface HTMLStyleElement : HTMLElement { attribute DOMString media; attribute DOMString nonce; attribute DOMString type; attribute boolean scoped; }; HTMLStyleElement implements LinkStyle;
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. The element does not represent content for the
user.
The type
attribute gives the styling language.
If the attribute is present, its value must be a valid MIME type that designates a
styling language. The charset
parameter must not be specified. The default
value for the type
attribute, which is used if the attribute
is absent, is "text/css
". [RFC2318]
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 charset
parameter must be treated as an unknown parameter for the purpose of
comparing MIME types here.
The media
attribute says which media the
styles apply to. The value must be a valid media query list. The user
agent must apply the styles when the media
attribute's
value matches the environment and the other relevant conditions apply, and must not
apply them otherwise.
The styles might be further limited in scope, e.g. in CSS with the use of @media
blocks. This specification does not override such further restrictions or
requirements.
The default, if the media
attribute is omitted, is "all
", meaning that by default styles apply to all
media.
The nonce
attribute represents a
cryptographic nonce ("number used once") which can be used by Content Security Policy
to determine whether or not the style specified by an element will be applied to the document. The
value is text. [CSP]
The processing model for the nonce
attribute needs to be integrated into the update a
style
block algorithm. The current definition in [CSP] is fairly
vague. See w3c/webappsec#463.
The scoped
attribute is a boolean
attribute. If present, it indicates that the styles are intended just for the subtree
rooted at the style
element's parent element, as opposed to the whole
Document
.
If the scoped
attribute is present and the element has a
parent element, then the style
element must precede any flow content in
its parent element other than inter-element whitespace and other style
elements, and the parent element's content model must not have a transparent
component.
This implies that scoped style
elements cannot be children of, e.g.,
a
or ins
elements, even when those are used as flow content
containers.
A style
element without a scoped
attribute is restricted to appearing in the
head
of the document.
A style sheet declared by a style
element that has a scoped
attribute and has a parent node that is an element is
scoped, with the scoping root being the style
element's parent
element. [CSSSCOPED]
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. [CSSOM]
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.
The textContent
of a style
element must match the style
production in the following ABNF, the character set for which is Unicode. [ABNF]
style = no-c-start *( c-start no-c-end c-end no-c-start ) no-c-start = < any string that doesn't contain a substring that matches c-start > c-start = "<!--" no-c-end = < any string that doesn't contain a substring that matches c-end > c-end = "-->"
Whenever one of the following conditions occur for an element whose Document
is in
a browsing context:
...the user agent must run the update a style
block algorithm that applies for the style sheet language specified by the element's type
attribute, passing it the element's style
data.
For styling languages that consist of pure text (as opposed to XML), a style
element's style data is the concatenation of the contents of all the
Text
nodes that are children of the style
element (not any other nodes
such as comments or elements), in tree order. For XML-based styling languages, the
style data consists of all the child nodes of the style
element.
The update a style
block algorithm for CSS (text/css
) is
as follows:
Let element be the style
element.
If element has an associated CSS style sheet, remove the CSS style sheet in question.
If element is not in a Document
, then abort
these steps.
Create a CSS style sheet with the following properties:
text/css
element
The media
attribute of element.
This is a reference to the (possibly absent at this time) attribute, rather than a copy of the attribute's current value. The CSSOM specification defines what happens when the attribute is dynamically set, changed, or removed.
The title
attribute of element.
Again, this is a reference to the attribute.
Unset.
Set.
null
Left at its default value.
Left uninitialised.
This specification does not define any other styling language's update a style
block algorithm.
Once the attempts to obtain the style sheet's critical subresources, if any, are
complete, or, if the style sheet has no critical subresources, once the style sheet
has been parsed and processed, the user agent must, if the loads were successful or there were
none, queue a task to fire a simple event named load
at the style
element, or, if one of the style sheet's
critical subresources failed to completely load for any reason (e.g. DNS error, HTTP
404 response, a connection being prematurely closed, unsupported Content-Type), queue a
task to fire a simple event named error
at
the style
element. Non-network errors in processing the style sheet or its
subresources (e.g. CSS parse errors, PNG decoding errors) are not failures for the purposes of
this paragraph.
The task source for these tasks is the DOM manipulation task source.
The element must delay the load event of the element's node document until all the attempts to obtain the style sheet's critical subresources, if any, are complete.
This specification does not specify a style system, but CSS is expected to be supported by most Web browsers. [CSS]
The media
, nonce
, type
and scoped
IDL attributes must
reflect the respective content attributes of the same name.
The LinkStyle
interface is also implemented by this element. [CSSOM]
The following document has its stress emphasis styled as bright red text rather than italics text, while leaving titles of works and Latin words in their default italics. It shows how using appropriate elements enables easier restyling of documents.
<!DOCTYPE html> <html lang="en-US"> <head> <title>My favorite book</title> <style> body { color: black; background: white; } em { font-style: normal; color: red; } </style> </head> <body> <p>My <em>favorite</em> book of all time has <em>got</em> to be <cite>A Cat's Life</cite>. It is a book by P. Rahmel that talks about the <i lang="la">Felis Catus</i> in modern human society.</p> </body> </html>
Style sheets, whether added by a link
element, a style
element, an
<?xml-stylesheet?>
PI, an HTTP `Link
` header, or
some other mechanism, have a style sheet ready flag, which is initially unset.
When a style sheet is ready to be applied, its style sheet ready flag must be set.
If the style sheet referenced no other resources (e.g. it was an internal style sheet given by a
style
element with no @import
rules), then the style rules must
be immediately made available to script; otherwise, the style rules must only be made available
to script once the event loop reaches its update the rendering step.
A style sheet in the context of the Document
of an HTML parser or
XML parser is said to be a style sheet that is blocking scripts if the
element was created by that Document
's parser, and the element is either a
style
element or a link
element that was an external resource link that contributes to the styling processing
model when the element was created by the parser, and the element's style sheet was enabled
when the element was created by the parser, and the element's style sheet ready flag
is not yet set, and, the last time the event loop reached step 1, the element was
in that Document
, and the user agent hasn't given
up on that particular style sheet yet. A user agent may give up on a style sheet at any time.
Giving up on a style sheet before the style sheet loads, if the style sheet eventually does still load, means that the script might end up operating with incorrect information. For example, if a style sheet sets the colour of an element to green, but a script that inspects the resulting style is executed before the sheet is loaded, the script will find that the element is black (or whatever the default colour is), and might thus make poor choices (e.g. deciding to use black as the colour elsewhere on the page, instead of green). Implementors have to balance the likelihood of a script using incorrect information with the performance impact of doing nothing while waiting for a slow network request to finish.
A Document
has a style sheet that is blocking scripts if there is
either a style sheet that is blocking scripts in the context of that
Document
, or if that Document
is in a browsing context that
has a parent browsing context, and the active document of that
parent browsing context itself has a style sheet that is blocking
scripts.
A Document
has no style sheet that is blocking scripts if it does not
have a style sheet that is blocking
scripts as defined in the previous paragraph.
body
elementhtml
element.body
element's start tag can be omitted
if the element is empty, or if the first thing inside the body
element is not a
space character or a comment, except if the
first thing inside the body
element is a meta
, link
,
script
, style
, or template
element. body
element's end tag can be omitted if the
body
element is not immediately followed by a comment.onafterprint
onbeforeprint
onbeforeunload
onhashchange
onlanguagechange
onmessage
onoffline
ononline
onpagehide
onpageshow
onpopstate
onstorage
onunload
document
role (default - do not set), application
.aria-*
attributes applicable to the allowed roles.interface HTMLBodyElement : HTMLElement { // also has obsolete members }; HTMLBodyElement implements WindowEventHandlers;
The body
element represents the content of the document.
In conforming documents, there is only one body
element. The document.body
IDL 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.
The body
element exposes as event handler content attributes a number
of the event handlers of the Window
object. It also mirrors their
event handler IDL attributes.
The onblur
, onerror
,
onfocus
, onload
, onresize
, and onscroll
event handlers of the Window
object, exposed on the body
element, replace the generic event handlers with the same names normally supported by
HTML elements.
Thus, for example, a bubbling error
event
dispatched on a child of the body element of a Document
would first
trigger the onerror
event handler content
attributes of that element, then that of the root html
element, and only
then would it trigger the onerror
event handler content attribute on the
body
element. This is because the event would bubble from the target, to the
body
, to the html
, to the Document
, to the
Window
, and the event handler on the
body
is watching the Window
not the body
. A regular event
listener attached to the body
using addEventListener()
,
however, would be run when the event bubbled through the body
and not when it reaches
the Window
object.
This page updates an indicator to show whether or not the user is online:
<!DOCTYPE HTML> <html> <head> <title>Online or offline?</title> <script> function update(online) { document.getElementById('status').textContent = online ? 'Online' : 'Offline'; } </script> </head> <body ononline="update(true)" onoffline="update(false)" onload="update(navigator.onLine)"> <p>You are: <span id="status">(Unknown)</span></p> </body> </html>
article
elementarticle
(default - do not set), application
, document
or main
.aria-*
attributes applicable to the allowed roles.HTMLElement
.The article
element represents a complete, or self-contained,
composition in a document, page, application, or site and that is, in principle, independently
distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or
newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any
other independent item of content. Each article
should be identified, typically by
including a heading
(h1
–h6
element) as a child of the
article
element.
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 blog entry on a site that accepts user-submitted comments could represent the comments
as article
elements nested within the article
element for the blog
entry.
Author information associated with an article
element (q.v. the
address
element) does not apply to nested article
elements.
When used specifically with content to be redistributed in syndication, the
article
element is similar in purpose to the entry
element in
Atom. [ATOM]
The schema.org microdata vocabulary can be used to provide the publication date
for an article
element, using one of the CreativeWork subtypes.
When the main content of the page (i.e. excluding footers, headers, navigation blocks, and
sidebars) is all one single self-contained composition, that content may be marked with an
article
, but it is technically redundant in that case (since it's self-evident that
the page is a single composition, as it is a single document).
This example shows a blog post using the article
element, with some schema.org
annotations:
<article itemscope itemtype="http://schema.org/BlogPosting"> <header> <h1 itemprop="headline">The Very First Rule of Life</h1> <p><time itemprop="datePublished" datetime="2009-10-09">3 days ago</time></p> <link itemprop="url" href="?comments=0"> </header> <p>If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.</p> <p>...</p> <footer> <a itemprop="discussionUrl" href="?comments=1">Show comments...</a> </footer> </article>
Here is that same blog post, but showing some of the comments:
<article itemscope itemtype="http://schema.org/BlogPosting"> <header> <h1 itemprop="headline">The Very First Rule of Life</h1> <p><time itemprop="datePublished" datetime="2009-10-09">3 days ago</time></p> <link itemprop="url" href="?comments=0"> </header> <p>If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.</p> <p>...</p> <section> <h1>Comments</h1> <article itemprop="comment" itemscope itemtype="http://schema.org/UserComments" id="c1"> <link itemprop="url" href="#c1"> <footer> <p>Posted by: <span itemprop="creator" itemscope itemtype="http://schema.org/Person"> <span itemprop="name">George Washington</span> </span></p> <p><time itemprop="commentTime" datetime="2009-10-10">15 minutes ago</time></p> </footer> <p>Yeah! Especially when talking about your lobbyist friends!</p> </article> <article itemprop="comment" itemscope itemtype="http://schema.org/UserComments" id="c2"> <link itemprop="url" href="#c2"> <footer> <p>Posted by: <span itemprop="creator" itemscope itemtype="http://schema.org/Person"> <span itemprop="name">George Hammond</span> </span></p> <p><time itemprop="commentTime" datetime="2009-10-10">5 minutes ago</time></p> </footer> <p>Hey, you have the same first name as me.</p> </article> </section> </article>
Notice the use of footer
to give the information for each comment (such as who
wrote it and when): the footer
element can appear at the start of its
section when appropriate, such as in this case. (Using header
in this case wouldn't
be wrong either; it's mostly a matter of authoring preference.)
In this example, article
elements are used to host widgets on a portal page.
<!DOCTYPE HTML> <title>eHome Portal</title> <link rel=stylesheet href="/styles/main.css"> <article> <style scoped> @import url(/widgets/stocks/look.css); </style> <script src="/widgets/stocks/core.js"></script> <h1>Stocks</h1> <table> <thead> <tr> <th> Stock <th> Value <th> Delta <tbody> <template> <tr> <td> <td> <td> </template> </table> <p> <input type=button value="Refresh" onclick="stocks.refresh()"> </article> <article> <style scoped> @import url(/widgets/news/look.css); </style> <script src="/widgets/news/core.js"></script> <h1>News</h1> <ul> <template> <li> <p><img> <strong></strong> <p> </template> </ul> <p> <input type=button value="Refresh" onclick="news.refresh()"> </article>
section
elementregion
role (default - do not set), alert
, alertdialog
, application
, contentinfo
, dialog
, document
, log
, main
, marquee
, presentation
, search
or status
.aria-*
attributes applicable to the allowed roles.HTMLElement
.The section
element represents a generic section of a document or
application. A section, in this context, is a thematic grouping of content. Each section
should
be identified, typically by including a heading (
h1
-
h6
element) as a child of the section
element.
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, and contact information.
Authors are encouraged to use the article
element instead of the
section
element when it would make sense to syndicate the contents of the
element.
The section
element is not a generic
container element. When an element is needed only for styling purposes or as a convenience for
scripting, authors are encouraged to use the div
element instead. A general rule is
that the section
element is appropriate only if the element's contents would be
listed explicitly in the document's outline.
Here is a graduation programme with two sections, one for the list of people graduating, and one for the description of the ceremony. (The markup in this example features an uncommon style sometimes used to minimise the amount of inter-element whitespace.)
<!DOCTYPE Html> <Html ><Head ><Title >Graduation Ceremony Summer 2022</Title ></Head ><Body ><H1 >Graduation</H1 ><Section ><H1 >Ceremony</H1 ><P >Opening Procession</P ><P >Speech by Validactorian</P ><P >Speech by Class President</P ><P >Presentation of Diplomas</P ><P >Closing Speech by Headmaster</P ></Section ><Section ><H1 >Graduates</H1 ><Ul ><Li >Molly Carpenter</Li ><Li >Anastasia Luccio</Li ><Li >Ebenezar McCoy</Li ><Li >Karrin Murphy</Li ><Li >Thomas Raith</Li ><Li >Susan Rodriguez</Li ></Ul ></Section ></Body ></Html>
nav
elementmain
element descendants.navigation
role (default - do not set) or presentation
.aria-*
attributes applicable to the allowed roles.HTMLElement
.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.
In cases where the content of a nav
element represents
a list of items, use list markup to aid understanding and navigation.
Not all groups of links on a page need to be in a nav
element —
the element is primarily intended for sections that consist of major navigation blocks. In
particular, it is common for footers to have a short list of links to various pages of a site,
such as the terms of service, the home page, and a copyright page. The footer
element
alone is sufficient for such cases; while a nav
element can be used in such cases, it
is usually unnecessary.
User agents (such as screen readers) that are targeted at users who can benefit from navigation information being omitted in the initial rendering, or who can benefit from navigation information being immediately available, can use this element as a way to determine what content on the page to initially skip or provide on request (or both).
In the following example, there are two nav
elements, one for primary navigation
around the site, and one for secondary navigation around the page itself.
<body> <h1>The Wiki Center Of Exampland</h1> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/events">Current Events</a></li> ...more... </ul> </nav> <article> <header> <h1>Demos in Exampland</h1> <p>Written by A. N. Other.</p> </header> <nav> <ul> <li><a href="#public">Public demonstrations</a></li> <li><a href="#destroy">Demolitions</a></li> ...more... </ul> </nav> <div> <section id="public"> <h1>Public demonstrations</h1> <p>...more...</p> </section> <section id="destroy"> <h1>Demolitions</h1> <p>...more...</p> </section> ...more... </div> <footer> <p><a href="?edit">Edit</a> | <a href="?delete">Delete</a> | <a href="?Rename">Rename</a></p> </footer> </article> <footer> <p><small>© copyright 1998 Exampland Emperor</small></p> </footer> </body>
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 itemscope itemtype="http://schema.org/Blog"> <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> <p>Last Modified: <span itemprop="dateModified">2009-04-01</span></p> <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> </header> <main> <article itemprop="blogPosts" itemscope itemtype="http://schema.org/BlogPosting"> <header> <h1 itemprop="headline">My Day at the Beach</h1> </header> <main itemprop="articleBody"> <p>Today I went to the beach and had a lot of fun.</p> ...more content... </main> <footer> <p>Posted <time itemprop="datePublished" datetime="2009-10-10">Thursday</time>.</p> </footer> </article> ...more blog posts... </main> <footer> <p>Copyright © <span itemprop="copyrightYear">2010</span> <span itemprop="copyrightHolder">The Example Company</span> </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>
Notice the main
elements being used to wrap all the contents of the page other
than the header and footer, and all the contents of the blog entry other than its header and
footer.
You can also see microdata annotations in the above example that use the schema.org vocabulary to provide the publication date and other metadata about the blog post.
A nav
element doesn't have to contain a list, it can contain other kinds of
content as well. In this navigation block, links are provided in prose:
<nav> <h1>Navigation</h1> <p>You are on my home page. To the north lies <a href="/blog">my blog</a>, from whence the sounds of battle can be heard. To the east you can see a large mountain, upon which many <a href="/school">school papers</a> are littered. Far up thus mountain you can spy a little figure who appears to be me, desperately scribbling a <a href="/school/thesis">thesis</a>.</p> <p>To the west are several exits. One fun-looking exit is labeled <a href="http://games.example.com/">"games"</a>. Another more boring-looking exit is labeled <a href="http://isp.example.net/">ISP™</a>.</p> <p>To the south lies a dark and dank <a href="/about">contacts page</a>. Cobwebs cover its disused entrance, and at one point you see a rat run quickly out of the page.</p> </nav>
In this example, nav
is used in an e-mail application, to let the user switch
folders:
<p><input type=button value="Compose" onclick="compose()"></p> <nav> <h1>Folders</h1> <ul> <li> <a href="/inbox" onclick="return openFolder(this.href)">Inbox</a> <span class=count></span> <li> <a href="/sent" onclick="return openFolder(this.href)">Sent</a> <li> <a href="/drafts" onclick="return openFolder(this.href)">Drafts</a> <li> <a href="/trash" onclick="return openFolder(this.href)">Trash</a> <li> <a href="/customers" onclick="return openFolder(this.href)">Customers</a> </ul> </nav>
aside
elementmain
element descendants.complementary
role (default - do not set), note
, search
or presentation
.aria-*
attributes applicable to the allowed roles.HTMLElement
.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 element can be used for typographical effects like pull quotes or sidebars, for
advertising, for groups of nav
elements, and for other content that is considered
separate from the main content of the page.
It's not appropriate to use the aside
element just for
parentheticals, since those are part of the main flow of the document.
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> ...
The following extract shows how aside
can be used for blogrolls and other side
content on a blog:
<body> <header> <h1>My wonderful blog</h1> <p>My tagline</p> </header> <aside> <!-- this aside contains two sections that are tangentially related to the page, namely, links to other blogs, and links to blog posts from this blog --> <nav> <h1>My blogroll</h1> <ul> <li><a href="http://blog.example.com/">Example Blog</a> </ul> </nav> <nav> <h1>Archives</h1> <ol reversed> <li><a href="/last-post">My last post</a> <li><a href="/first-post">My first post</a> </ol> </nav> </aside> <aside> <!-- this aside is tangentially related to the page also, it contains twitter messages from the blog author --> <h1>Twitter Feed</h1> <blockquote cite="http://twitter.example.net/t31351234"> I'm on vacation, writing my blog. </blockquote> <blockquote cite="http://twitter.example.net/t31219752"> I'm going to go on vacation soon. </blockquote> </aside> <article> <!-- this is a blog post --> <h1>My last post</h1> <p>This is my last post.</p> <footer> <p><a href="/last-post" rel=bookmark>Permalink</a> </footer> </article> <article> <!-- this is also a blog post --> <h1>My first post</h1> <p>This is my first post.</p> <aside> <!-- this aside is about the blog post, since it's inside the <article> element; it would be wrong, for instance, to put the blogroll here, since the blogroll isn't really related to this post specifically, only to the page as a whole --> <h1>Posting</h1> <p>While I'm thinking about it, I wanted to say something about posting. Posting is fun!</p> </aside> <footer> <p><a href="/first-post" rel=bookmark>Permalink</a> </footer> </article> <footer> <nav> <a href="/archives">Archives</a> — <a href="/about">About me</a> — <a href="/copyright">Copyright</a> </nav> </footer> </body>
h1
, h2
, h3
, h4
, h5
, and
h6
elementsheading
role (default - do not set), tab
or presentation
.aria-*
attributes applicable to the allowed roles.interface HTMLHeadingElement : HTMLElement { // also has obsolete members };
These elements represent headings 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.
h1
–
h6
elements must not be
used to markup subheadings, subtitles, alternative titles and taglines unless intended
to be the heading for a new section or subsection. Instead use the markup patterns in
the Common idioms without dedicated elements section of
the specification.
As far as their respective document outlines (their heading and section structures) are concerned, these two snippets are semantically equivalent:
<body> <h1>Let's call it a draw(ing surface)</h1> <h2>Diving in</h2> <h2>Simple shapes</h2> <h2>Canvas coordinates</h2> <h3>Canvas coordinates diagram</h3> <h2>Paths</h2> </body>
<body> <h1>Let's call it a draw(ing surface)</h1> <section> <h1>Diving in</h1> </section> <section> <h1>Simple shapes</h1> </section> <section> <h1>Canvas coordinates</h1> <section> <h1>Canvas coordinates diagram</h1> </section> </section> <section> <h1>Paths</h1> </section> </body>
Authors might prefer the former style for its terseness, or the latter style for its convenience in the face of heavy editing; which is best is purely an issue of preferred authoring style.
The two styles can be combined, for compatibility with legacy tools while still future-proofing for when that compatibility is no longer needed. This third snippet again has the same outline as the previous two:
<body> <h1>Let's call it a draw(ing surface)</h1> <section> <h2>Diving in</h2> </section> <section> <h2>Simple shapes</h2> </section> <section> <h2>Canvas coordinates</h2> <section> <h3>Canvas coordinates diagram</h3> </section> </section> <section> <h2>Paths</h2> </section> </body>
header
elementheader
, footer
, or main
element descendants.banner
role (default - do not set) or presentation
.aria-*
attributes applicable to the allowed roles.HTMLElement
.
The header
element represents introductory content for its nearest ancestor sectioning content or sectioning
root element. A header
typically contains a
group of introductory or navigational aids. When the nearest ancestor sectioning content or sectioning
root element is the body element, then it applies to the
whole page.
The header
element is not sectioning content; it doesn't
introduce a new section.
In this example, the page has a page heading given by the h1
element, and two
subsections whose headings are given by h2
elements. The content after the
header
element is still part of the last subsection started in the
header
element, because the header
element doesn't take part in the
outline algorithm.
<body> <header> <h1>Little Green Guys With Guns</h1> <nav> <ul> <li><a href="/games">Games</a> <li><a href="/forum">Forum</a> <li><a href="/download">Download</a> </ul> </nav> <h2>Important News</h2> <!-- this starts a second subsection --> <!-- this is part of the subsection entitled "Important News" --> <p>To play today's games you will need to update your client.</p> <h2>Games</h2> <!-- this starts a third subsection --> </header> <p>You have three active games:</p> <!-- this is still part of the subsection entitled "Games" --> ...
footer
elementheader
, footer
, or main
element descendants.contentinfo
role (default - do not set) or presentation
.aria-*
attributes applicable to the allowed roles.HTMLElement
.The footer
element represents a footer for its nearest ancestor
sectioning content or sectioning root element. A footer typically
contains information about its section such as who wrote it, links to related documents, copyright
data, and the like.
When the footer
element contains entire sections, they represent appendices, indexes, long colophons, verbose license
agreements, and other such content.
Contact information for the author or editor of a section belongs in an
address
element, possibly itself inside a footer
. Bylines and other
information that could be suitable for both a header
or a footer
can be
placed in either (or neither). The primary purpose of these elements is merely to help the author
write self-explanatory markup that is easy to maintain and style; they are not intended to impose
specific structures on authors.
Footers don't necessarily have to appear at the end of a section, though they usually do.
When the nearest ancestor sectioning content or sectioning root element is the body element, then it applies to the whole page.
The footer
element is not sectioning content; it doesn't
introduce a new section.
Here is an example which shows the footer
element being used both for a site-wide
footer and for a section footer.
<!DOCTYPE HTML> <HTML><HEAD> <TITLE>The Ramblings of a Scientist</TITLE> <BODY> <H1>The Ramblings of a Scientist</H1> <ARTICLE> <H1>Episode 15</H1> <VIDEO SRC="/fm/015.ogv" CONTROLS PRELOAD> <P><A HREF="/fm/015.ogv">Download video</A>.</P> </VIDEO> <FOOTER> <!-- footer for article --> <P>Published <TIME DATETIME="2009-10-21T18:26-07:00">on 2009/10/21 at 6:26pm</TIME></P> </FOOTER> </ARTICLE> <ARTICLE> <H1>My Favorite Trains</H1> <P>I love my trains. My favorite train of all time is a Köf.</P> <P>It is fun to see them pull some coal cars because they look so dwarfed in comparison.</P> <FOOTER> <!-- footer for article --> <P>Published <TIME DATETIME="2009-09-15T14:54-07:00">on 2009/09/15 at 2:54pm</TIME></P> </FOOTER> </ARTICLE> <FOOTER> <!-- site wide footer --> <NAV> <P><A HREF="/credits.html">Credits</A> — <A HREF="/tos.html">Terms of Service</A> — <A HREF="/index.html">Blog Index</A></P> </NAV> <P>Copyright © 2009 Gordon Freeman</P> </FOOTER> </BODY> </HTML>
Some site designs have what is sometimes referred to as "fat footers" — footers that contain a lot of material, including images, links to other articles, links to pages for sending feedback, special offers... in some ways, a whole "front page" in the footer.
This fragment shows the bottom of a page on a site with a "fat footer":
... <footer> <nav> <section> <h1>Articles</h1> <p><img src="images/somersaults.jpeg" alt=""> Go to the gym with our somersaults class! Our teacher Jim takes you through the paces in this two-part article. <a href="articles/somersaults/1">Part 1</a> · <a href="articles/somersaults/2">Part 2</a></p> <p><img src="images/kindplus.jpeg"> Tired of walking on the edge of a clif<!-- sic -->? Our guest writer Lara shows you how to bumble your way through the bars. <a href="articles/kindplus/1">Read more...</a></p> <p><img src="images/crisps.jpeg"> The chips are down, now all that's left is a potato. What can you do with it? <a href="articles/crisps/1">Read more...</a></p> </section> <ul> <li> <a href="/about">About us...</a> <li> <a href="/feedback">Send feedback!</a> <li> <a href="/sitemap">Sitemap</a> </ul> </nav> <p><small>Copyright © 2015 The Snacker — <a href="/tos">Terms of Service</a></small></p> </footer> </body>
address
elementheader
, footer
, or
address
element descendants.contentinfo
role.aria-*
attributes applicable to the allowed roles.HTMLElement
.The address
element represents the contact information for its
nearest article
or body
element ancestor. If that is the body
element, then the contact information applies to the document as a whole.
For example, a page at the W3C Web site related to HTML might include the following contact information:
<ADDRESS> <A href="../People/Raggett/">Dave Raggett</A>, <A href="../People/Arnaud/">Arnaud Le Hors</A>, contact persons for the <A href="Activity">W3C HTML Activity</A> </ADDRESS>
The address
element must not be used to represent arbitrary addresses (e.g. postal
addresses), unless those addresses are in fact the relevant contact information. (The
p
element is the appropriate element for marking up postal addresses in general.)
The address
element must not contain information other than contact
information.
For example, the following is non-conforming use of the
address
element:
<ADDRESS>Last Modified: 1999/12/24 23:37:50</ADDRESS>
Typically, the address
element would be included along with other information in a
footer
element.
The contact information for a node node is a collection of
address
elements defined by the first applicable entry from the following list:
article
elementbody
elementThe contact information consists of all the address
elements that have node as an ancestor and do not have another body
or
article
element ancestor that is a descendant of node.
article
elementbody
elementThe contact information of node is the same as the contact information of
the nearest article
or body
element ancestor, whichever is
nearest.
The contact information of node is the same as the contact information of
the body element of the Document
.
There is no contact information for node.
User agents may expose the contact information of a node to the user, or use it for other purposes, such as indexing sections based on the sections' contact information.
In this example the footer contains contact information and a copyright notice.
<footer> <address> For more details, contact <a href="mailto:js@example.com">John Smith</a>. </address> <p><small>© copyright 2038 Example Corp.</small></p> </footer>
The h1
–h6
elements are
headings.
The first element of heading content in an element of sectioning content represents the heading for that section. Subsequent headings of equal or higher rank start new (implied) sections, headings of lower rank start implied subsections that are part of the previous one. In both cases, the element represents the heading of the implied section.
Certain elements are said to be sectioning roots, including
blockquote
and td
elements. These elements can have their own outlines,
but the sections and headings inside these elements do not contribute to the outlines of their
ancestors.
Sectioning content elements are always considered subsections of their nearest ancestor sectioning root or their nearest ancestor element of sectioning content, whichever is nearest, regardless of what implied sections other headings may have created.
For the following fragment:
<body> <h1>Foo</h1> <h2>Bar</h2> <blockquote> <h3>Bla</h3> </blockquote> <p>Baz</p> <h2>Quux</h2> <section> <h3>Thud</h3> </section> <p>Grunt</p> </body>
...the structure would be:
body
section, containing the "Grunt" paragraph)
section
section)
Notice how the section
ends the earlier implicit section so that a later
paragraph ("Grunt") is back at the top level.
Sections may contain headings of any rank, but authors are strongly encouraged to
either use only h1
elements, or to use elements of the appropriate rank
for the section's nesting level.
Authors are also encouraged to explicitly wrap sections in elements of sectioning content, instead of relying on the implicit sections generated by having multiple headings in one element of sectioning content.
For example, the following is correct:
<body> <h4>Apples</h4> <p>Apples are fruit.</p> <section> <h2>Taste</h2> <p>They taste lovely.</p> <h6>Sweet</h6> <p>Red apples are sweeter than green ones.</p> <h1>Colour</h1> <p>Apples come in various colours.</p> </section> </body>
However, the same document would be more clearly expressed as:
<body> <h1>Apples</h1> <p>Apples are fruit.</p> <section> <h2>Taste</h2> <p>They taste lovely.</p> <section> <h3>Sweet</h3> <p>Red apples are sweeter than green ones.</p> </section> </section> <section> <h2>Colour</h2> <p>Apples come in various colours.</p> </section> </body>
Both of the documents above are semantically identical and would produce the same outline in compliant user agents.
This third example is also semantically identical, and might be easier to maintain (e.g. if sections are often moved around in editing):
<body> <h1>Apples</h1> <p>Apples are fruit.</p> <section> <h1>Taste</h1> <p>They taste lovely.</p> <section> <h1>Sweet</h1> <p>Red apples are sweeter than green ones.</p> </section> </section> <section> <h1>Colour</h1> <p>Apples come in various colours.</p> </section> </body>
This final example would need explicit style rules to be rendered well in legacy browsers. Legacy browsers without CSS support would render all the headings as top-level headings.
There are currently no known implementations of the outline algorithm in graphical browsers or
assistive technology user agents, although the algorithm is implemented in other software such as
conformance checkers. Therefore the outline algorithm cannot be relied upon
to convey document structure to users. Authors are advised to use heading rank
(h1
-h6
) to convey document structure.
This section defines an algorithm for creating an outline for a sectioning content element or a sectioning root element. It is defined in terms of a walk over the nodes of a DOM tree, in tree order, with each node being visited when it is entered and when it is exited during the walk.
The outline for a sectioning content element or a sectioning root element consists of a list of one or more potentially nested sections. The element for which an outline is created is said to be the outline's owner.
A section is a container that corresponds to some nodes in
the original DOM tree. Each section can have one heading associated with it, and can contain any
number of further nested sections. The algorithm for the outline also
associates each node in the DOM tree with a particular section and potentially a heading.
(The sections in the outline aren't section
elements, though some may correspond to
such elements — they are merely conceptual sections.)
The following markup fragment:
<body> <h1>A</h1> <p>B</p> <h2>C</h2> <p>D</p> <h2>E</h2> <p>F</p> </body>
...results in the following outline being created for the body
node (and thus the
entire document):
Section created for body
node.
Associated with heading "A".
Also associated with paragraph "B".
Nested sections:
The algorithm that must be followed during a walk of a DOM subtree rooted at a sectioning content element or a sectioning root element to determine that element's outline is as follows:
Let current outline target be null. (It holds the element whose outline is being created.)
Let current section be null. (It holds a pointer to a section, so that elements in the DOM can all be associated with a section.)
Create a stack to hold elements, which is used to handle nesting. Initialise this stack to empty.
Walk over the DOM in tree order, starting with the sectioning content element or sectioning root element at the root of the subtree for which an outline is to be created, and trigger the first relevant step below for each element as the walk enters and exits it.
The element being exited is a heading content element or an element with a attribute.
Pop that element from the stack.
Do nothing.
Push the element being entered onto the stack. (This causes the algorithm to skip that element and any descendants of the element.)
Run these steps:
If current outline target is not null, run these substeps:
If the current section has no heading, create an implied heading and let that be the heading for the current section.
Push current outline target onto the stack.
Let current outline target be the element that is being entered.
Let current section be a newly created section for the current outline target element.
Associate current outline target with current section.
Let there be a new outline for the new current outline target, initialised with just the new current section as the only section in the outline.
Run these steps:
If the current section has no heading, create an implied heading and let that be the heading for the current section.
Pop the top element from the stack, and let the current outline target be that element.
Let current section be the last section in the outline of the current outline target element.
Append the outline of the sectioning content element being exited to the current section. (This does not change which section is the last section in the outline.)
Run these steps:
If current outline target is not null, push current outline target onto the stack.
Let current outline target be the element that is being entered.
Let current outline target's parent section be current section.
Let current section be a newly created section for the current outline target element.
Let there be a new outline for the new current outline target, initialised with just the new current section as the only section in the outline.
Run these steps:
If the current section has no heading, create an implied heading and let that be the heading for the current section.
Let current section be current outline target's parent section.
Pop the top element from the stack, and let the current outline target be that element.
The current outline target is the element being exited, and it is the sectioning content element or a sectioning root element at the root of the subtree for which an outline is being generated.
If the current section has no heading, create an implied heading and let that be the heading for the current section.
Skip to the next step in the overall set of steps. (The walk is over.)
If the current section has no heading, let the element being entered be the heading for the current section.
Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of the outline of the current outline target, or if the heading of the last section of the outline of the current outline target is an implied heading, then create a new section and append it to the outline of the current outline target element, so that this new section is the new last section of that outline. Let current section be that new section. Let the element being entered be the new heading for the current section.
Otherwise, run these substeps:
Let candidate section be current section.
Heading loop: If the element being entered has a rank lower than the rank of the heading of the candidate section, then create a new section, and append it to candidate section. (This does not change which section is the last section in the outline.) Let current section be this new section. Let the element being entered be the new heading for the current section. Abort these substeps.
Let new candidate section be the section that contains candidate section in the outline of current outline target.
Let candidate section be new candidate section.
Return to the step labeled heading loop.
Push the element being entered onto the stack. (This causes the algorithm to skip any descendants of the element.)
Recall that h1
has the highest rank, and h6
has the lowest rank.
Do nothing.
In addition, whenever the walk exits a node, after doing the steps above, if the node is not associated with a section yet, associate the node with the section current section.
Associate all non-element nodes that are in the subtree for which an outline is being created with the section with which their parent element is associated.
Associate all nodes in the subtree with the heading of the section with which they are associated, if any.
The tree of sections created by the algorithm above, or a proper subset thereof, must be used when generating document outlines, for example when generating tables of contents.
The outline created for the body element of a Document
is the
outline of the entire document.
When creating an interactive table of contents, entries should jump the user to the relevant sectioning content element, if the section was created for a real element in the original document, or to the relevant heading content element, if the section in the tree was generated for a heading in the above process.
Selecting the first section of the document
therefore always takes the user to the top of the document, regardless of where the first heading
in the body
is to be found.
The outline depth of a heading content element associated with a section section is the number of sections that are ancestors of section in the
outermost outline that section finds itself in when the outlines of its Document
's elements are created, plus 1. The
outline depth of a heading content element not associated with a section is 1.
User agents should provide default headings for sections that do not have explicit section headings.
Consider the following snippet:
<body> <nav> <p><a href="/">Home</a></p> </nav> <p>Hello world.</p> <aside> <p>My cat is cute.</p> </aside> </body>
Although it contains no headings, this snippet has three sections: a document (the
body
) with two subsections (a nav
and an aside
). A user
agent could present the outline as follows:
These default headings ("Untitled document", "Navigation", "Sidebar") are not specified by this specification, and might vary with the user's language, the page's language, the user's preferences, the user agent implementor's preferences, etc.
The following JavaScript function shows how the tree walk could be implemented. The root argument is the root of the tree to walk (either a sectioning content element or a sectioning root element), and the enter and exit arguments are callbacks that are called with the nodes as they are entered and exited. [ECMA262]
function (root, enter, exit) { var node = root; start: while (node) { enter(node); if (node.firstChild) { node = node.firstChild; continue start; } while (node) { exit(node); if (node == root) { node = null; } else if (node.nextSibling) { node = node.nextSibling; continue start; } else { node = node.parentNode; } } } }
This section is non-normative.
The following document shows a straight-forward application of the outline algorithm. First, here is the document, which is a book with very short chapters and subsections:
<!DOCTYPE HTML> <title>The Tax Book (all in one page)</title> <h1>The Tax Book</h1> <h2>Earning money</h2> <p>Earning money is good.</p> <h3>Getting a job</h3> <p>To earn money you typically need a job.</p> <h2>Spending money</h2> <p>Spending is what money is mainly used for.</p> <h3>Cheap things</h3> <p>Buying cheap things often not cost-effective.</p> <h3>Expensive things</h3> <p>The most expensive thing is often not the most cost-effective either.</p> <h2>Investing money</h2> <p>You can lend your money to other people.</p> <h2>Losing money</h2> <p>If you spend money or invest money, sooner or later you will lose money. <h3>Poor judgement</h3> <p>Usually if you lose money it's because you made a mistake.</p>
This book would form the following outline:
Notice that the title
element does not participate in the outline.
Here is a similar document, but this time using section
elements to get the same
effect:
<!DOCTYPE HTML> <title>The Tax Book (all in one page)</title> <h1>The Tax Book</h1> <section> <h1>Earning money</h1> <p>Earning money is good.</p> <section> <h1>Getting a job</h1> <p>To earn money you typically need a job.</p> </section> </section> <section> <h1>Spending money</h1> <p>Spending is what money is mainly used for.</p> <section> <h1>Cheap things</h1> <p>Buying cheap things often not cost-effective.</p> </section> <section> <h1>Expensive things</h1> <p>The most expensive thing is often not the most cost-effective either.</p> </section> </section> <section> <h1>Investing money</h1> <p>You can lend your money to other people.</p> </section> <section> <h1>Losing money</h1> <p>If you spend money or invest money, sooner or later you will lose money. <section> <h1>Poor judgement</h1> <p>Usually if you lose money it's because you made a mistake.</p> </section> </section>
This book would form the same outline:
A document can contain multiple top-level headings:
<!DOCTYPE HTML> <title>Alphabetic Fruit</title> <h1>Apples</h1> <p>Pomaceous.</p> <h1>Bananas</h1> <p>Edible.</p> <h1>Carambola</h1> <p>Star.</p>
This would form the following simple outline consisting of three top-level sections:
Effectively, the body
element is split into three.
Mixing both the h1
–h6
model and the
section
/h1
model can lead to some unintuitive results.
Consider for example the following, which is just the previous example but with the contents
of the (implied) body
wrapped in a section
:
<!DOCTYPE HTML> <title>Alphabetic Fruit</title> <section> <h1>Apples</h1> <p>Pomaceous.</p> <h1>Bananas</h1> <p>Edible.</p> <h1>Carambola</h1> <p>Star.</p> </section>
The resulting outline would be:
This result is described as unintuitive because it results in three subsections even
though there's only one section
element. Effectively, the section
is
split into three, just like the implied body
element in the previous example.
(In this example, "(untitled page)" is the implied heading for the body
element, since it has no explicit heading.)
Headings never rise above other sections. Thus, in the following example, the first
h1
does not actually describe the page header; it describes the header for the
second half of the page:
<!DOCTYPE HTML> <title>Feathers on The Site of Encyclopedic Knowledge</title> <section> <h1>A plea from our caretakers</h1> <p>Please, we beg of you, send help! We're stuck in the server room!</p> </section> <h1>Feathers</h1> <p>Epidermal growths.</p>
The resulting outline would be:
Thus, when an article
element starts with a nav
block and only later
has its heading, the result is that the nav
block is not part of the same section as
the rest of the article
in the outline. For instance, take this document:
<!DOCTYPE HTML> <title>We're adopting a child! — Ray's blog</title> <h1>Ray's blog</h1> <article> <header> <nav> <a href="?t=-1d">Yesterday</a>; <a href="?t=-7d">Last week</a>; <a href="?t=-1m">Last month</a> </nav> <h1>We're adopting a child!</h1> </header> <main> <p>As of today, Janine and I have signed the papers to become the proud parents of baby Diane! We've been looking forward to this day for weeks.</p> </main> </article>
The resulting outline would be:
Also worthy of note in this example is that the header
and main
elements have no effect whatsoever on the document outline.
User agents are encouraged to expose page outlines to users to aid in navigation. This is especially true for non-visual media, e.g. screen readers.
However, to mitigate the difficulties that arise from authors misusing sectioning content, user agents are also encouraged to offer a mode that navigates the page using heading content alone.
For instance, a user agent could map the arrow keys as follows:
Plus in addition, the user agent could map the j and k keys to navigating to the previous or next element of heading content, regardless of the section's outline depth and ignoring sections with no headings.
This section is non-normative.
Element | Purpose |
---|---|
Example | |
body
| The main content of the document. |
<!DOCTYPE HTML> <html> <head> <title>Steve Hill's Home Page</title> </head> <body> <p>Hard Trance is My Life.</p> </body> </html> | |
article
| A complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. |
<article> <img src="/tumblr_masqy2s5yn1rzfqbpo1_500.jpg" alt="Yellow smiley face with the caption 'masif'"> <p>My fave Masif tee so far!</p> <footer>Posted 2 days ago</footer> </article> <article> <img src="/tumblr_m9tf6wSr6W1rzfqbpo1_500.jpg" alt=""> <p>Happy 2nd birthday Masif Saturdays!!!</p> <footer>Posted 3 weeks ago</footer> </article> | |
section
| A generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading. |
<h1>Biography</h1> <section> <h1>The facts</h1> <p>1500+ shows, 14+ countries</p> </section> <section> <h1>2010/2011 figures per year</h1> <p>100+ shows, 8+ countries</p> </section> | |
nav
| A section of a page that links to other pages or to parts within the page: a section with navigation links. |
<nav> <p><a href="/">Home</a> <p><a href="/biog.html">Bio</a> <p><a href="/discog.html">Discog</a> </nav> | |
aside
| 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.
|
<h1>Music</h1> <p>As any burner can tell you, the event has a lot of trance.</p> <aside>You can buy the music we played at our <a href="buy.html">playlist page</a>.</aside> <p>This year we played a kind of trance that originated in Belgium, Germany, and the Netherlands in the mid 90s.</p> | |
h1 –h6
| A section heading |
<h1>The Guide To Music On The Playa</h1> <h2>The Main Stage</h2> <p>If you want to play on a stage, you should bring one.</p> <h2>Amplified Music</h2> <p>Amplifiers up to 300W or 90dB are welcome.</p> | |
header
| A group of introductory or navigational aids. |
<article> <header> <h1>Hard Trance is My Life</h1> <p>By DJ Steve Hill and Technikal</p> </header> <p>The album with the amusing punctuation has red artwork.</p> </article> | |
footer
| A footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like. |
<article> <h1>Hard Trance is My Life</h1> <p>The album with the amusing punctuation has red artwork.</p> <footer> <p>Artists: DJ Steve Hill and Technikal</p> </footer> </article> |
This section is non-normative.
A section
forms part of something else. An article
is its own thing.
But how does one know which is which? Mostly the real answer is "it depends on author intent".
For example, one could imagine a book with a "Granny Smith" chapter that just said "These
juicy, green apples make a great filling for apple pies."; that would be a section
because there'd be lots of other chapters on (maybe) other kinds of apples.
On the other hand, one could imagine a tweet or reddit comment or tumblr post or newspaper
classified ad that just said "Granny Smith. These juicy, green apples make a great filling for
apple pies."; it would then be article
s because that was the whole thing.
A comment on an article is not part of the article
on which it is commenting,
therefore it is its own article
.
p
elementp
element's end tag can be omitted if the
p
element is immediately followed by an address
, article
,
aside
, blockquote
, details
, div
, dl
,
fieldset
, figcaption
, figure
, footer
, form
, h1
, h2
,
h3
, h4
, h5
, h6
, header
,
hgroup
, hr
, main
, menu
, nav
,
ol
, p
, pre
, section
, table
, or
ul
element, or if there is no more content in the parent element and the parent
element is an HTML element that is not an a
, audio
, del
,
ins
, map
, noscript
, or video
element.aria-*
attributes applicable to the allowed roles.interface HTMLParagraphElement : HTMLElement { // also has obsolete members };
The p
element represents a paragraph.
While paragraphs are usually represented in visual media by blocks of text that are physically separated from adjacent blocks through blank lines, a style sheet or user agent would be equally justified in presenting paragraph breaks in a different manner, for instance using inline pilcrows (¶).
The following examples are conforming HTML fragments:
<p>The little kitten gently seated himself on a piece of carpet. Later in his life, this would be referred to as the time the cat sat on the mat.</p>
<fieldset> <legend>Personal information</legend> <p> <label>Name: <input name="n"></label> <label><input name="anon" type="checkbox"> Hide from other users</label> </p> <p><label>Address: <textarea name="a"></textarea></label></p> </fieldset>
<p>There was once an example from Femley,<br> Whose markup was of dubious quality.<br> The validator complained,<br> So the author was pained,<br> To move the error from the markup to the rhyming.</p>
The p
element should not be used when a more specific element is more
appropriate.
The following example is technically correct:
<section> <!-- ... --> <p>Last modified: 2001-04-23</p> <p>Author: fred@example.com</p> </section>
However, it would be better marked-up as:
<section> <!-- ... --> <footer>Last modified: 2001-04-23</footer> <address>Author: fred@example.com</address> </section>
Or:
<section> <!-- ... --> <footer> <p>Last modified: 2001-04-23</p> <address>Author: fred@example.com</address> </footer> </section>
List elements (in particular, ol
and ul
elements) cannot be children
of p
elements. When a sentence contains a bulleted list, therefore, one might wonder
how it should be marked up.
For instance, this fantastic sentence has bullets relating to
and is further discussed below.
The solution is to realise that a paragraph, in HTML terms, is not a logical concept, but a structural one. In the fantastic example above, there are actually five paragraphs as defined by this specification: one before the list, one for each bullet, and one after the list.
The markup for the above example could therefore be:
<p>For instance, this fantastic sentence has bullets relating to</p> <ul> <li>wizards, <li>faster-than-light travel, and <li>telepathy, </ul> <p>and is further discussed below.</p>
Authors wishing to conveniently style such "logical" paragraphs consisting of multiple
"structural" paragraphs can use the div
element instead of the p
element.
Thus for instance the above example could become the following:
<div>For instance, this fantastic sentence has bullets relating to <ul> <li>wizards, <li>faster-than-light travel, and <li>telepathy, </ul> and is further discussed below.</div>
This example still has five structural paragraphs, but now the author can style just the
div
instead of having to consider each part of the example separately.
hr
elementseparator
(default - do not set) or presentation
.aria-*
attributes applicable to the allowed roles.interface HTMLHRElement : HTMLElement { // also has obsolete members };
The hr
element represents a paragraph-level thematic
break, e.g. a scene change in a story, or a transition to another topic within a section of a
reference book.
The following fictional extract from a project manual shows two sections that use the
hr
element to separate topics within the section.
<section> <h1>Communication</h1> <p>There are various methods of communication. This section covers a few of the important ones used by the project.</p> <hr> <p>Communication stones seem to come in pairs and have mysterious properties:</p> <ul> <li>They can transfer thoughts in two directions once activated if used alone.</li> <li>If used with another device, they can transfer one's consciousness to another body.</li> <li>If both stones are used with another device, the consciousnesses switch bodies.</li> </ul> <hr> <p>Radios use the electromagnetic spectrum in the meter range and longer.</p> <hr> <p>Signal flares use the electromagnetic spectrum in the nanometer range.</p> </section> <section> <h1>Food</h1> <p>All food at the project is rationed:</p> <dl> <dt>Potatoes</dt> <dd>Two per day</dd> <dt>Soup</dt> <dd>One bowl per day</dd> </dl> <hr> <p>Cooking is done by the chefs on a set rotation.</p> </section>
There is no need for an hr
element between the sections themselves, since the
section
elements and the h1
elements imply thematic changes
themselves.
The following extract from Pandora's Star by Peter F. Hamilton shows two
paragraphs that precede a scene change and the paragraph that follows it. The scene change,
represented in the printed book by a gap containing a solitary centered star between the second
and third paragraphs, is here represented using the hr
element.
<p>Dudley was ninety-two, in his second life, and fast approaching
time for another rejuvenation. Despite his body having the physical
age of a standard fifty-year-old, the prospect of a long degrading
campaign within academia was one he regarded with dread. For a
supposedly advanced civilization, the Intersolar Commonwealth could be
appallingly backward at times, not to mention cruel.</p>
<p><i>Maybe it won't be that bad</i>, he told himself. The lie was
comforting enough to get him through the rest of the night's
shift.</p>
<hr>
<p>The Carlton AllLander drove Dudley home just after dawn. Like the
astronomer, the vehicle was old and worn, but perfectly capable of
doing its job. It had a cheap diesel engine, common enough on a
semi-frontier world like Gralmond, although its drive array was a
thoroughly modern photoneural processor. With its high suspension and
deep-tread tyres it could plough along the dirt track to the
observatory in all weather and seasons, including the metre-deep snow
of Gralmond's winters.</p>
pre
elementaria-*
attributes applicable to the allowed roles.interface HTMLPreElement : HTMLElement { // also has obsolete members };
The pre
element represents a block of preformatted text, in which
structure is represented by typographic conventions rather than by elements.
In the HTML syntax, a leading newline character immediately following
the pre
element start tag is stripped.
Some examples of cases where the pre
element could be used:
Authors are encouraged to consider how preformatted text will be experienced when the formatting is lost, as will be the case for users of speech synthesizers, braille displays, and the like. For cases like ASCII art, it is likely that an alternative presentation, such as a textual description, would be more universally accessible to the readers of the document.
To represent a block of computer code, the pre
element can be used with a
code
element; to represent a block of computer output the pre
element
can be used with a samp
element. Similarly, the kbd
element can be used
within a pre
element to indicate text that the user is to enter.
This element has rendering requirements involving the bidirectional algorithm.
In the following snippet, a sample of computer code is presented.
<p>This is the <code>Panel</code> constructor:</p> <pre><code>function Panel(element, canClose, closeHandler) { this.element = element; this.canClose = canClose; this.closeHandler = function () { if (closeHandler) closeHandler() }; }</code></pre>
In the following snippet, samp
and kbd
elements are mixed in the
contents of a pre
element to show a session of Zork I.
<pre><samp>You are in an open field west of a big white house with a boarded front door. There is a small mailbox here. ></samp> <kbd>open mailbox</kbd> <samp>Opening the mailbox reveals: A leaflet. ></samp></pre>
The following shows a contemporary poem that uses the pre
element to preserve its
unusual formatting, which forms an intrinsic part of the poem itself.
<pre> maxling it is with a heart heavy that i admit loss of a feline so loved a friend lost to the unknown (night) ~cdr 11dec07</pre>
blockquote
elementcite
- Link to the source of the quotation.aria-*
attributes applicable to the allowed roles.interface HTMLQuoteElement : HTMLElement { attribute DOMString cite; };
The HTMLQuoteElement
interface is
also used by the q
element.
The blockquote
element represents content that is quoted from another source, optionally with a citation which must be within a footer
or cite
element, and optionally
with in-line changes such as annotations and abbreviations.
Content inside a blockquote
other than citations and in-line changes must be quoted from another source, whose address, if it has one, may be cited in the cite
attribute.
In cases where a page contains contributions from multiple people, such as comments on a blog post, 'another source' can include text from the same page, written by another person.
If the cite
attribute is present, it must be a
valid URL potentially surrounded by spaces. To obtain the
corresponding citation link, the value of the attribute must be resolved relative to the element. User agents may allow users to follow such
citation links, but they are primarily intended for private use (e.g. by server-side scripts
collecting statistics about a site's use of quotations), not for readers.
The cite
IDL
attribute must reflect the element's cite
content attribute.
The content of a blockquote
may be abbreviated, may have context added or may have annotations. Any such additions or changes to quoted text must be indicated in the text (at the text level). This may mean the use of notational conventions or explicit remarks, such as "emphasis mine".
For example, in English, abbreviations are traditionally identified using square brackets. Consider a page with the sentence "Fred ate the cracker. He then said he liked apples and fish."; it could be quoted as follows:
<blockquote> <p>[Fred] then said he liked [...] fish.</p> </blockquote>
Quotation marks may be used to delineate between quoted text and annotations
within a blockquote
.
For example, an in-line note provided by the author:
<figure> <blockquote> "That monster custom, who all sense doth eat Of habit's devil," <abbr title="et cetera">&c.</abbr> not in Folio "What a falling off was there ! From me, whose love was of that dignity That it went hand in hand even with the vow I made to her in marriage, and to decline Upon a wretch." </blockquote> <footer> — <cite class="title">Shakespeare manual</cite> by <cite class="author">Frederick Gard Fleay</cite>, p19 (in Google Books) </footer> </figure>
In the example above, the citation is contained within the footer
of a figure
element,
this groups and associates the information, about the quote, with the quote. The figcaption
element was not
used, in this case, as a container for the citation as it is not a caption.
Attribution for the quotation, may be be placed inside the
blockquote
element, but must be within a cite
element for in-text attributions or within a footer
element.
For example, here the attribution is given in a footer
after
the quoted text, to clearly relate the quote to its attribution:
<blockquote> <p>I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours.</p> <footer>— <cite>Stephen Roberts</cite></footer> </blockquote>
Here the attribution is given in a cite
element on the last line of the quoted text.
Note that a link to the author is also included.
<blockquote> The people recognize themselves in their commodities; they find their soul in their automobile, hi-fi set, split-level home, kitchen equipment. — <cite><a href="http://en.wikipedia.org/wiki/Herbert_Marcuse">Herbert Marcuse</a></cite> </blockquote>
Here the attribution is given in a footer
after
the quoted text, and metadata about the reference has been added using the
Microdata syntax
(note it could have equally been marked up using RDFA Lite).
<blockquote> <p>... she said she would not sign any deposition containing the word "amorous" instead of "advances". For her the difference was of crucial significance, and one of the reasons she had separated from her husband was that he had never been amorous but had consistently made advances.</p> <footer itemscope itemtype="http://schema.org/Book"> <span itemprop="author">Heinrich Böll</span>, <span itemprop="name">The Lost Honor of Katharina Blum</span>, <span itemprop="datePublished">January 1, 1974</span> </footer> </blockquote>
There is no formal method for indicating the markup in a blockquote
is from a quoted source. It is suggested that if the footer
or cite
elements are included and these elements are also being used within a blockquote
to identify citations, the elements from the quoted source could be annotated with metadata to identify their origin, for example by using the class
attribute (a defined extensibility mechanism).
In this example the source of a quote includes a cite
element, which is annotated using the class
attribute:
<blockquote> <p>My favorite book is <cite class="from-source">At Swim-Two-Birds</cite></p> <footer>- <cite>Mike[tm]Smith</cite></footer> </blockquote>
Here a blockquote
element is used in conjunction
with a figure
element and its figcaption
:
<figure> <blockquote> <p>The truth may be puzzling. It may take some work to grapple with. It may be counterintuitive. It may contradict deeply held prejudices. It may not be consonant with what we desperately want to be true. But our preferences do not determine what's true. We have a method, and that method helps us to reach not absolute truth, only asymptotic approaches to the truth — never there, just closer and closer, always finding vast new oceans of undiscovered possibilities. Cleverly designed experiments are the key.</p> </blockquote> <figcaption><cite>Carl Sagan</cite>, in "<cite>Wonder and Skepticism</cite>", from the <cite>Skeptical Enquirer</cite> Volume 19, Issue 1 (January-February 1995)</figcaption> </figure>
This next example shows the use of cite
alongside
blockquote
:
<p>His next piece was the aptly named <cite>Sonnet 130</cite>:</p> <blockquote cite="http://quotes.example.org/s/sonnet130.html"> <p>My mistress' eyes are nothing like the sun,<br> Coral is far more red, than her lips red,<br> ...
This example shows how a forum post could use
blockquote
to show what post a user is replying
to. The article
element is used for each post, to mark
up the threading.
<article> <h1><a href="http://bacon.example.com/?blog=109431">Bacon on a crowbar</a></h1> <article> <header><strong>t3yw</strong> 12 points 1 hour ago</header> <p>I bet a narwhal would love that.</p> <footer><a href="?pid=29578">permalink</a></footer> <article> <header><strong>greg</strong> 8 points 1 hour ago</header> <blockquote><p>I bet a narwhal would love that.</p></blockquote> <p>Dude narwhals don't eat bacon.</p> <footer><a href="?pid=29579">permalink</a></footer> <article> <header><strong>t3yw</strong> 15 points 1 hour ago</header> <blockquote> <blockquote><p>I bet a narwhal would love that.</p></blockquote> <p>Dude narwhals don't eat bacon.</p> </blockquote> <p>Next thing you'll be saying they don't get capes and wizard hats either!</p> <footer><a href="?pid=29580">permalink</a></footer> <article> <article> <header><strong>boing</strong> -5 points 1 hour ago</header> <p>narwhals are worse than ceiling cat</p> <footer><a href="?pid=29581">permalink</a></footer> </article> </article> </article> </article> <article> <header><strong>fred</strong> 1 points 23 minutes ago</header> <blockquote><p>I bet a narwhal would love that.</p></blockquote> <p>I bet they'd love to peel a banana too.</p> <footer><a href="?pid=29582">permalink</a></footer> </article> </article> </article>
This example shows the use of a blockquote
for
short snippets, demonstrating that one does not have to use
p
elements inside blockquote
elements:
<p>He began his list of "lessons" with the following:</p> <blockquote>One should never assume that his side of the issue will be recognized, let alone that it will be conceded to have merits.</blockquote> <p>He continued with a number of similar points, ending with:</p> <blockquote>Finally, one should be prepared for the threat of breakdown in negotiations at any given moment and not be cowed by the possibility.</blockquote> <p>We shall now discuss these points...
Examples of how to
represent a conversation are shown in a later section; it is not
appropriate to use the cite
and blockquote
elements for this purpose.
ol
elementli
element: Palpable content.li
and script-supporting elements.reversed
— Number the list backwardsstart
— Ordinal value of the first itemtype
— Kind of list markerlist
role (default - do not set), directory
, group
, listbox
, menu
, menubar
, presentation
, radiogroup
, tablist
, toolbar
or tree
.aria-*
attributes applicable to the allowed roles.interface HTMLOListElement : HTMLElement { attribute boolean reversed; attribute long start; attribute DOMString type; // also has obsolete members };
The ol
element represents a list of items, where the items have been
intentionally ordered, such that changing the order would change the meaning of the document.
The items of the list are the li
element child nodes of the ol
element, in tree order.
The reversed
attribute is a boolean
attribute. If present, it indicates that the list is a descending list (..., 3, 2, 1). If
the attribute is omitted, the list is an ascending list (1, 2, 3, ...).
The start
attribute, if present, must be a
valid integer giving the ordinal value of the first list item.
If the start
attribute is present, user agents must parse it as an integer, in order to determine the
attribute's value. The default value, used if the attribute is missing or if the value cannot be
converted to a number according to the referenced algorithm, is 1 if the element has no reversed
attribute, and is the number of child li
elements otherwise.
The first item in the list has the ordinal value given by the ol
element's start
attribute, unless that li
element
has a value
attribute with a value that can be successfully
parsed, in which case it has the ordinal value given by that value
attribute.
Each subsequent item in the list has the ordinal value given by its value
attribute, if it has one, or, if it doesn't, the ordinal
value of the previous item, plus one if the reversed
is absent, or minus one if it is present.
The type
attribute can be used to specify the kind
of marker to use in the list, in the cases where that matters (e.g. because items are to be
referenced by their number/letter). The attribute, if specified, must have a value that is a
case-sensitive match for one of the characters given in the first cell of one of the
rows of the following table. The type
attribute represents the state given in the cell in the second column of the row whose first cell
matches the attribute's value; if none of the cells match, or if the attribute is omitted, then
the attribute represents the decimal
state.
Keyword | State | Description | Examples for values 1-3 and 3999-4001 | |||||||
---|---|---|---|---|---|---|---|---|---|---|
1 (U+0031)
| decimal | Decimal numbers | 1. | 2. | 3. | ... | 3999. | 4000. | 4001. | ... |
a (U+0061)
| lower-alpha | Lowercase latin alphabet | a. | b. | c. | ... | ewu. | ewv. | eww. | ... |
A (U+0041)
| upper-alpha | Uppercase latin alphabet | A. | B. | C. | ... | EWU. | EWV. | EWW. | ... |
i (U+0069)
| lower-roman | Lowercase roman numerals | i. | ii. | iii. | ... | mmmcmxcix. | i̅v̅. | i̅v̅i. | ... |
I (U+0049)
| upper-roman | Uppercase roman numerals | I. | II. | III. | ... | MMMCMXCIX. | I̅V̅. | I̅V̅I. | ... |
User agents should render the items of the list in a manner consistent with the state of the
type
attribute of the ol
element. Numbers less than
or equal to zero should always use the decimal system regardless of the type
attribute.
For CSS user agents, a mapping for this attribute to the 'list-style-type' CSS property is given in the rendering section (the mapping is straightforward: the states above have the same names as their corresponding CSS values).
It is possible to redefine the default CSS list styles used to implement this attribute in CSS user agents; doing so will affect how list items are rendered.
The reversed
, start
, and type
IDL attributes must reflect the
respective content attributes of the same name. The start
IDL
attribute has the same default as its content attribute.
The following markup shows a list where the order matters, and where the ol
element is therefore appropriate. Compare this list to the equivalent list in the ul
section to see an example of the same items using the ul
element.
<p>I have lived in the following countries (given in the order of when I first lived there):</p> <ol> <li>Switzerland <li>United Kingdom <li>United States <li>Norway </ol>
Note how changing the order of the list changes the meaning of the document. In the following example, changing the relative order of the first two items has changed the birthplace of the author:
<p>I have lived in the following countries (given in the order of when I first lived there):</p> <ol> <li>United Kingdom <li>Switzerland <li>United States <li>Norway </ol>
ul
elementli
element: Palpable content.li
and script-supporting elements.list
role (default - do not set), directory
, group
, listbox
, menu
, menubar
, presentation
,radiogroup
, tablist
, toolbar
or tree
.aria-*
attributes applicable to the allowed roles.interface HTMLUListElement : HTMLElement { // also has obsolete members };
The ul
element represents a list of items, where the order of the
items is not important — that is, where changing the order would not materially change the
meaning of the document.
The items of the list are the li
element child nodes of the ul
element.
The following markup shows a list where the order does not matter, and where the
ul
element is therefore appropriate. Compare this list to the equivalent list in the
ol
section to see an example of the same items using the ol
element.
<p>I have lived in the following countries:</p> <ul> <li>Norway <li>Switzerland <li>United Kingdom <li>United States </ul>
Note that changing the order of the list does not change the meaning of the document. The items in the snippet above are given in alphabetical order, but in the snippet below they are given in order of the size of their current account balance in 2007, without changing the meaning of the document whatsoever:
<p>I have lived in the following countries:</p> <ul> <li>Switzerland <li>Norway <li>United Kingdom <li>United States </ul>
li
elementol
elements.ul
elements.menu
elements whose type
attribute is in the toolbar state.li
element's end tag can be omitted if the
li
element is immediately followed by another li
element or if there is
no more content in the parent element.ol
element: value
— Ordinal value of the list itemlistitem
role (default - do not set), menuitem
, menuitemcheckbox
, menuitemradio
, option
, radio
, tab
, treeitem
or presentation
.aria-*
attributes applicable to the allowed roles.interface HTMLLIElement : HTMLElement { attribute long value; // also has obsolete members };
The li
element represents a list item. If its parent element is an
ol
, ul
, or menu
element, then the element is an item of the
parent element's list, as defined for those elements. Otherwise, the list item has no defined
list-related relationship to any other li
element.
If the parent element is an ol
element, then the li
element has an
ordinal value.
The value
attribute, if present, must be a
valid integer giving the ordinal value of the list item.
If the value
attribute is present, user agents must parse it as an integer, in order to determine the
attribute's value. If the attribute's value cannot be converted to a number, the attribute must be
treated as if it was absent. The attribute has no default value.
The value
attribute is processed relative to the element's
parent ol
element (q.v.), if there is one. If there is not, the attribute has no
effect.
The value
IDL attribute must reflect
the value of the value
content attribute.
The following example, the top ten movies are listed (in reverse order). Note the way the list
is given a title by using a figure
element and its figcaption
element.
<figure> <figcaption>The top 10 movies of all time</figcaption> <ol> <li value="10"><cite>Josie and the Pussycats</cite>, 2001</li> <li value="9"><cite lang="sh">Црна мачка, бели мачор</cite>, 1998</li> <li value="8"><cite>A Bug's Life</cite>, 1998</li> <li value="7"><cite>Toy Story</cite>, 1995</li> <li value="6"><cite>Monsters, Inc</cite>, 2001</li> <li value="5"><cite>Cars</cite>, 2006</li> <li value="4"><cite>Toy Story 2</cite>, 1999</li> <li value="3"><cite>Finding Nemo</cite>, 2003</li> <li value="2"><cite>The Incredibles</cite>, 2004</li> <li value="1"><cite>Ratatouille</cite>, 2007</li> </ol> </figure>
The markup could also be written as follows, using the reversed
attribute on the ol
element:
<figure> <figcaption>The top 10 movies of all time</figcaption> <ol reversed> <li><cite>Josie and the Pussycats</cite>, 2001</li> <li><cite lang="sh">Црна мачка, бели мачор</cite>, 1998</li> <li><cite>A Bug's Life</cite>, 1998</li> <li><cite>Toy Story</cite>, 1995</li> <li><cite>Monsters, Inc</cite>, 2001</li> <li><cite>Cars</cite>, 2006</li> <li><cite>Toy Story 2</cite>, 1999</li> <li><cite>Finding Nemo</cite>, 2003</li> <li><cite>The Incredibles</cite>, 2004</li> <li><cite>Ratatouille</cite>, 2007</li> </ol> </figure>
While it is conforming to include heading elements (e.g. h1
) inside
li
elements, it likely does not convey the semantics that the author intended. A
heading starts a new section, so a heading in a list implicitly splits the list into spanning
multiple sections.
dl
elementdt
elements followed by one or more dd
elements, optionally intermixed with script-supporting elements.aria-*
attributes applicable to the allowed roles.interface HTMLDListElement : HTMLElement { // also has obsolete members };
The dl
element represents an association list consisting of zero or
more name-value groups (a description list). A name-value group consists of one or more names
(dt
elements) followed by one or more values (dd
elements), ignoring any
nodes other than dt
and dd
elements. Within a single dl
element, there should not be more than one dt
element for each name.
Name-value groups may be terms and definitions, metadata topics and values, questions and answers, or any other groups of name-value data.
The values within a group are alternatives; multiple paragraphs forming part of the same value
must all be given within the same dd
element.
The order of the list of groups, and of the names and values within each group, may be significant.
If a dl
element has no dt
or dd
element children, it
contains no groups.
If a dl
element has one or more non-whitespace Text
node children, or has child elements that are
neither dt
nor dd
elements, all such Text
nodes and
elements, as well as their descendants (including any dt
or dd
elements), do not form part of any groups in that dl
.
If a dl
element has one or more dt
element children but no
dd
element children, then it consists of one group with names but no values.
If a dl
element has one or more dd
element children but no
dt
element children, then it consists of one group with values but no names.
If a dl
element's first dt
or dd
element child is a
dd
element, then the first group has no associated name.
If a dl
element's last dt
or dd
element child is a
dt
element, then the last group has no associated value.
When a dl
element doesn't match its content model, it is often due to
accidentally using dd
elements in the place of dt
elements and vice
versa. Conformance checkers can spot such mistakes and might be able to advise authors how to
correctly use the markup.
In the following example, one entry ("Authors") is linked to two values ("John" and "Luke").
<dl> <dt> Authors <dd> John <dd> Luke <dt> Editor <dd> Frank </dl>
In the following example, one definition is linked to two terms.
<dl> <dt lang="en-US"> <dfn>color</dfn> </dt> <dt lang="en-GB"> <dfn>colour</dfn> </dt> <dd> A sensation which (in humans) derives from the ability of the fine structure of the eye to distinguish three differently filtered analyses of a view. </dd> </dl>
The following example illustrates the use of the dl
element to mark up metadata
of sorts. At the end of the example, one group has two metadata labels ("Authors" and "Editors")
and two values ("Robert Rothman" and "Daniel Jackson").
<dl> <dt> Last modified time </dt> <dd> 2004-12-23T23:33Z </dd> <dt> Recommended update interval </dt> <dd> 60s </dd> <dt> Authors </dt> <dt> Editors </dt> <dd> Robert Rothman </dd> <dd> Daniel Jackson </dd> </dl>
The following example shows the dl
element used to give a set of instructions.
The order of the instructions here is important (in the other examples, the order of the blocks
was not important).
<p>Determine the victory points as follows (use the first matching case):</p> <dl> <dt> If you have exactly five gold coins </dt> <dd> You get five victory points </dd> <dt> If you have one or more gold coins, and you have one or more silver coins </dt> <dd> You get two victory points </dd> <dt> If you have one or more silver coins </dt> <dd> You get one victory point </dd> <dt> Otherwise </dt> <dd> You get no victory points </dd> </dl>
The following snippet shows a dl
element being used as a glossary. Note the use
of dfn
to indicate the word being defined.
<dl> <dt><dfn>Apartment</dfn>, n.</dt> <dd>An execution context grouping one or more threads with one or more COM objects.</dd> <dt><dfn>Flat</dfn>, n.</dt> <dd>A deflated tire.</dd> <dt><dfn>Home</dfn>, n.</dt> <dd>The user's login directory.</dd> </dl>
The dl
element is inappropriate for marking up dialogue. Examples of how to mark up dialogue are shown below.
dt
elementdd
or dt
elements inside dl
elements.header
, footer
, sectioning content, or heading content descendants.dt
element's end tag can be omitted if the
dt
element is immediately followed by another dt
element or a
dd
element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The dt
element represents the term, or name, part of a
term-description group in a description list (dl
element).
The dt
element itself, when used in a dl
element, does
not indicate that its contents are a term being defined, but this can be indicated using the
dfn
element.
This example shows a list of frequently asked questions (a FAQ) marked up using the
dt
element for questions and the dd
element for answers.
<article> <h1>FAQ</h1> <dl> <dt>What do we want?</dt> <dd>Our data.</dd> <dt>When do we want it?</dt> <dd>Now.</dd> <dt>Where is it?</dt> <dd>We are not sure.</dd> </dl> </article>
dd
elementdt
or dd
elements inside dl
elements.dd
element's end tag can be omitted if the
dd
element is immediately followed by another dd
element or a
dt
element, or if there is no more content in the parent element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The dd
element represents the description, definition, or value, part
of a term-description group in a description list (dl
element).
A dl
can be used to define a vocabulary list, like in a dictionary. In the
following example, each entry, given by a dt
with a dfn
, has several
dd
s, showing the various parts of the definition.
<dl> <dt><dfn>happiness</dfn></dt> <dd class="pronunciation">/'hæ p. nes/</dd> <dd class="part-of-speech"><i><abbr>n.</abbr></i></dd> <dd>The state of being happy.</dd> <dd>Good fortune; success. <q>Oh <b>happiness</b>! It worked!</q></dd> <dt><dfn>rejoice</dfn></dt> <dd class="pronunciation">/ri jois'/</dd> <dd><i class="part-of-speech"><abbr>v.intr.</abbr></i> To be delighted oneself.</dd> <dd><i class="part-of-speech"><abbr>v.tr.</abbr></i> To cause one to be delighted.</dd> </dl>
figure
elementfigcaption
element followed by flow content.figcaption
element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The figure
element represents some flow content,
optionally with a caption, that is self-contained (like a complete sentence) and is typically
referenced as a single unit from the main flow of the document.
Self-contained in this context does not necessarily mean independent. For example,
each sentence in a paragraph is self-contained; an image that is part of a sentence would be
inappropriate for figure
, but an entire sentence made of images would be fitting.
The element can thus be used to annotate illustrations, diagrams, photos, code listings, etc.
When a figure
is referred to from the main content of the document by identifying
it by its caption (e.g. by figure number), it enables such content to be easily moved away from
that primary content, e.g. to the side of the page, to dedicated pages, or to an appendix, without
affecting the flow of the document.
If a figure
element is referenced by its relative position, e.g. "in the
photograph above" or "as the next figure shows", then moving the figure would disrupt the page's
meaning. Authors are encouraged to consider using labels to refer to figures, rather than using
such relative references, so that the page can easily be restyled without affecting the page's
meaning.
The first figcaption
element child of the element, if
any, represents the caption of the figure
element's contents. If there is no child
figcaption
element, then there is no caption.
A figure
element's contents are part of the surrounding flow. If the purpose of
the page is to display the figure, for example a photograph on an image sharing site, the
figure
and figcaption
elements can be used to explicitly provide a
caption for that figure. For content that is only tangentially related, or that serves a separate
purpose than the surrounding flow, the aside
element should be used (and can itself
wrap a figure
). For example, a pull quote that repeats content from an
article
would be more appropriate in an aside
than in a
figure
, because it isn't part of the content, it's a repetition of the content for
the purposes of enticing readers or highlighting key topics.
This example shows the figure
element to mark up a code listing.
<p>In <a href="#l4">listing 4</a> we see the primary core interface API declaration.</p> <figure id="l4"> <figcaption>Listing 4. The primary core interface API declaration.</figcaption> <pre><code>interface PrimaryCore { boolean verifyDataLine(); void sendData(in sequence<byte> data); void initSelfDestruct(); }</code></pre> </figure> <p>The API is designed to use UTF-8.</p>
Here we see a figure
element to mark up a photo that is the main content of the
page (as in a gallery).
<!DOCTYPE HTML> <title>Bubbles at work — My Gallery™</title> <figure> <img src="bubbles-work.jpeg" alt="Bubbles, sitting in his office chair, works on his latest project intently."> <figcaption>Bubbles at work</figcaption> </figure> <nav><a href="19414.html">Prev</a> — <a href="19416.html">Next</a></nav>
In this example, we see an image that is not a figure, as well as an image and a
video that are. The first image is literally part of the example's second sentence, so it's not a
self-contained unit, and thus figure
would be inappropriate.
<h2>Malinko's comics</h2> <p>This case centered on some sort of "intellectual property" infringement related to a comic (see Exhibit A). The suit started after a trailer ending with these words: <blockquote> <img src="promblem-packed-action.png" alt="ROUGH COPY! Promblem-Packed Action!"> </blockquote> <p>...was aired. A lawyer, armed with a Bigger Notebook, launched a preemptive strike using snowballs. A complete copy of the trailer is included with Exhibit B. <figure> <img src="ex-a.png" alt="Two squiggles on a dirty piece of paper."> <figcaption>Exhibit A. The alleged <cite>rough copy</cite> comic.</figcaption> </figure> <figure> <video src="ex-b.mov"></video> <figcaption>Exhibit B. The <cite>Rough Copy</cite> trailer.</figcaption> </figure> <p>The case was resolved out of court.
Here, a part of a poem is marked up using figure
.
<figure> <p>'Twas brillig, and the slithy toves<br> Did gyre and gimble in the wabe;<br> All mimsy were the borogoves,<br> And the mome raths outgrabe.</p> <figcaption><cite>Jabberwocky</cite> (first verse). Lewis Carroll, 1832-98</figcaption> </figure>
In this example, which could be part of a much larger work discussing a castle, nested
figure
elements are used to provide both a group caption and individual captions for
each figure in the group:
<figure> <figcaption>The castle through the ages: 1423, 1858, and 1999 respectively.</figcaption> <figure> <figcaption>Etching. Anonymous, ca. 1423.</figcaption> <img src="castle1423.jpeg" alt="The castle has one tower, and a tall wall around it."> </figure> <figure> <figcaption>Oil-based paint on canvas. Maria Towle, 1858.</figcaption> <img src="castle1858.jpeg" alt="The castle now has two towers and two walls."> </figure> <figure> <figcaption>Film photograph. Peter Jankle, 1999.</figcaption> <img src="castle1999.jpeg" alt="The castle lies in ruins, the original tower all that remains in one piece."> </figure> </figure>
The previous example could also be more succintly written as follows (using title
attributes in place of the nested
figure
/figcaption
pairs):
<figure> <img src="castle1423.jpeg" title="Etching. Anonymous, ca. 1423." alt="The castle has one tower, and a tall wall around it."> <img src="castle1858.jpeg" title="Oil-based paint on canvas. Maria Towle, 1858." alt="The castle now has two towers and two walls."> <img src="castle1999.jpeg" title="Film photograph. Peter Jankle, 1999." alt="The castle lies in ruins, the original tower all that remains in one piece."> <figcaption>The castle through the ages: 1423, 1858, and 1999 respectively.</figcaption> </figure>
The figure is sometimes referenced only implicitly from the content:
<article> <h1>Fiscal negotiations stumble in Congress as deadline nears</h1> <figure> <img src="obama-reid.jpeg" alt="Obama and Reid sit together smiling in the Oval Office."> <figcaption>Barrak Obama and Harry Reid. White House press photograph.</figcaption> </figure> <p>Negotiations in Congress to end the fiscal impasse sputtered on Tuesday, leaving both chambers grasping for a way to reopen the government and raise the country's borrowing authority with a Thursday deadline drawing near.</p> ... </article>
figcaption
elementfigure
element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The figcaption
element represents a caption or legend for the rest of
the contents of the figcaption
element's parent figure
element, if any.
main
elementarticle
, aside
,
footer
, header
or nav
element ancestors.main
role (default - do not set) or presentation
.aria-*
attributes
applicable to the allowed roles.HTMLElement
The main
element represents the main content of the body
of a document or application. The main content area consists of content that is directly related to or expands upon
the central topic of a document or central functionality of an application.
The main
element is not sectioning content and has no effect
on the document outline
The main content area of a document includes content that is unique to that document and excludes content that is repeated across a set of documents such as site navigation links, copyright information, site logos and banners and search forms (unless the document or applications main function is that of a search form).
User agents that support keyboard navigation of content are strongly encouraged to provide
a method to navigate to the main
element and once navigated to, ensure the next
element in the focus order is the first focusable element within the main
element.
This will provide a simple method for keyboard users to bypass blocks of content such as navigation links.
Authors must not include more than one main
element in a document.
Authors must not include the main
element as a descendant of an article
,
aside
, footer
, header
or nav
element.
The main
element is not suitable for use to identify the main content areas of sub sections of a
document or application. The simplest solution is to not mark up the main content of a sub section at all, and just leave it
as implicit, but an author could use a grouping content or sectioning content element as appropriate.
In the following example, we see 2 articles about skateboards (the main topic of a
Web page) the main topic content is identified by the use of the main
element.
<!-- other content --> <main> <h1>Skateboards</h1> <p>The skateboard is the way cool kids get around</p> <article> <h2>Longboards</h2> <p>Longboards are a type of skateboard with a longer wheelbase and larger, softer wheels.</p> <p>... </p> <p>... </p> </article> <article> <h2>Electric Skateboards</h2> <p>These no longer require the propelling of the skateboard by means of the feet; rather an electric motor propels the board, fed by an electric battery.</p> <p>... </p> <p>... </p> </article> </main> <!-- other content -->
Here is a graduation programme where the main content section is defined by the use of the main
element.
Note in this example the main
element contains a nav
element consisting of links to
sub sections of the main content.
<!DOCTYPE html> <html lang="en"> <head>
<title>Graduation Ceremony Summer 2022</title> </head> <body> <header>The Lawson Academy: <nav> <ul> <li><a href="courses.html">Courses</a></li> <li><a href="fees.html">Fees</a></li> <li><a>Graduation</a></li> </ul> </nav> </header> <main> <h1>Graduation</h1> <nav> <ul> <li><a href="#ceremony">Ceremony</a></li> <li><a href="#graduates">Graduates</a></li> <li><a href="#awards">Awards</a></li> </ul> </nav> <H2 id="ceremony">Ceremony</H2> <p>Opening Procession</p> <p>Speech by Valedictorian</p> <p>Speech by Class President</p> <p>Presentation of Diplomas</p> <p>Closing Speech by Headmaster</p> <h2 id="graduates">Graduates</h2> <ul> <li>Eileen Williams</li> <li>Andy Maseyk</li> <li>Blanca Sainz Garcia</li> <li>Clara Faulkner</li> <li>Gez Lemon</li> <li>Eloisa Faulkner</li> </ul> <h2 id="awards">Awards</h2> <ul> <li>Clara Faulkner</li> <li>Eloisa Faulkner</li> <li>Blanca Sainz Garcia</li> </ul> </main> <footer> Copyright 2012 B.lawson</footer> </body> </html>
div
elementaria-*
attributes
applicable to the allowed roles.interface HTMLDivElement : HTMLElement { // also has obsolete members };
The div
element has no special meaning at all. It represents its
children. It can be used with the class
, lang
, and title
attributes to mark up
semantics common to a group of consecutive elements.
Authors are strongly encouraged to view the div
element as an element
of last resort, for when no other element is suitable. Use of more appropriate elements instead of
the div
element leads to better accessibility for readers and easier maintainability
for authors.
For example, a blog post would be marked up using article
, a chapter using
section
, a page's navigation aids using nav
, and a group of form
controls using fieldset
.
On the other hand, div
elements can be useful for stylistic purposes or to wrap
multiple paragraphs within a section that are all to be annotated in a similar way. In the
following example, we see div
elements used as a way to set the language of two
paragraphs at once, instead of setting the language on the two paragraph elements separately:
<article lang="en-US"> <h1>My use of language and my cats</h1> <p>My cat's behaviour hasn't changed much since her absence, except that she plays her new physique to the neighbors regularly, in an attempt to get pets.</p> <div lang="en-GB"> <p>My other cat, coloured black and white, is a sweetie. He followed us to the pool today, walking down the pavement with us. Yesterday he apparently visited our neighbours. I wonder if he recognises that their flat is a mirror image of ours.</p> <p>Hm, I just noticed that in the last paragraph I used British English. But I'm supposed to write in American English. So I shouldn't say "pavement" or "flat" or "colour"...</p> </div> <p>I should say "sidewalk" and "apartment" and "color"!</p> </article>
a
elementhref
— Address of the hyperlinktarget
— Browsing context for hyperlink navigationdownload
— Whether to download the resource instead of navigating to it, and its file name if sorel
— Relationship between the document containing the hyperlink and the destination resourcehreflang
— Language of the linked resourcetype
— Hint for the type of the referenced resourcelink
(default - do not set), button
, checkbox
, menuitem
, menuitemcheckbox
, menuitemradio
, tab
or treeitem
aria-*
attributes
applicable to the allowed roles.interface HTMLAnchorElement : HTMLElement { attribute DOMString target; attribute DOMString download; attribute DOMString rel; readonly attribute DOMTokenList relList; attribute DOMString hreflang; attribute DOMString type; attribute DOMString text; // also has obsolete members }; HTMLAnchorElement implements HTMLHyperlinkElementUtils;
If the a
element has an href
attribute,
then it represents a hyperlink (a hypertext anchor) labeled by its
contents.
If the a
element has no href
attribute,
then the element represents a placeholder for where a link might otherwise have been
placed, if it had been relevant, consisting of just the element's contents.
The target
, download
,
rel
, hreflang
, and type
attributes must be omitted if the href
attribute is not
present.
If the itemprop
attribute is specified on an a
element,
then the href
attribute must also be specified.
If a site uses a consistent navigation toolbar on every page, then the link that would
normally link to the page itself could be marked up using an a
element:
<nav> <ul> <li> <a href="/">Home</a> </li> <li> <a href="/news">News</a> </li> <li> <a>Examples</a> </li> <li> <a href="/legal">Legal</a> </li> </ul> </nav>
The href
, target
, download
attributes affect what happens when users follow
hyperlinks or download hyperlinks created using
the a
element. The rel
, hreflang
, and type
attributes may be used to indicate to the user the likely nature of the target resource before the
user follows the link.
The activation behaviour of a
elements that create hyperlinks is to run the following steps:
If the a
element's node document is not fully active, then abort these steps.
If either the a
element has a download
attribute and the algorithm is not allowed
to show a popup; or, if the user has not indicated a specific browsing context for following the link, and the element's target
attribute is present, and applying the rules for choosing a browsing context given a
browsing context name, using the value of the target
attribute as the browsing context name, would result
in there not being a chosen browsing context, then run these substeps:
If there is an entry settings object, throw an
InvalidAccessError
exception.
Abort these steps without following the hyperlink.
If the target of the click
event is an img
element with an ismap
attribute specified, then server-side
image map processing must be performed, as follows:
click
event was a real pointing-device-triggered
click
event on the img
element, then let x be the distance in CSS pixels from the left edge of the image's left border,
if it has one, or the left edge of the image otherwise, to the location of the click, and let
y be the distance in CSS pixels from the top edge of the image's top
border, if it has one, or the top edge of the image otherwise, to the location of the click.
Otherwise, let x and y be zero.Finally, the user agent must follow the
hyperlink or download the hyperlink created
by the a
element, as determined by the download
attribute and any expressed user preference. If
the steps above defined a hyperlink suffix, then take that
into account when following or downloading the hyperlink.
text
Same as textContent
.
The IDL attributes download
, target
,
rel
, hreflang
, and type
, must reflect the respective content
attributes of the same name.
The IDL attribute relList
must
reflect the rel
content attribute.
The text
IDL attribute, on getting, must return the
same value as the textContent
IDL attribute on the element, and on setting, must act
as if the textContent
IDL attribute on the element had been set to the new value.
The a
element may be wrapped around entire paragraphs, lists, tables, and so
forth, even entire sections, so long as there is no interactive content within (e.g. buttons or
other links). This example shows how this can be used to make an entire advertising block into a
link:
<aside class="advertising"> <h1>Advertising</h1> <a href="http://ad.example.com/?adid=1929&pubid=1422"> <section> <h1>Mellblomatic 9000!</h1> <p>Turn all your widgets into mellbloms!</p> <p>Only $9.99 plus shipping and handling.</p> </section> </a> <a href="http://ad.example.com/?adid=375&pubid=1422"> <section> <h1>The Mellblom Browser</h1> <p>Web browsing at the speed of light.</p> <p>No other browser goes faster!</p> </section> </a> </aside>
em
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The em
element represents stress emphasis of its contents.
The level of stress that a particular piece of content has is given by its number of ancestor
em
elements.
The placement of stress emphasis changes the meaning of the sentence. The element thus forms an integral part of the content. The precise way in which stress is used in this way depends on the language.
These examples show how changing the stress emphasis changes the meaning. First, a general statement of fact, with no stress:
<p>Cats are cute animals.</p>
By emphasizing the first word, the statement implies that the kind of animal under discussion is in question (maybe someone is asserting that dogs are cute):
<p><em>Cats</em> are cute animals.</p>
Moving the stress to the verb, one highlights that the truth of the entire sentence is in question (maybe someone is saying cats are not cute):
<p>Cats <em>are</em> cute animals.</p>
By moving it to the adjective, the exact nature of the cats is reasserted (maybe someone suggested cats were mean animals):
<p>Cats are <em>cute</em> animals.</p>
Similarly, if someone asserted that cats were vegetables, someone correcting this might emphasise the last word:
<p>Cats are cute <em>animals</em>.</p>
By emphasizing the entire sentence, it becomes clear that the speaker is fighting hard to get the point across. This kind of stress emphasis also typically affects the punctuation, hence the exclamation mark here.
<p><em>Cats are cute animals!</em></p>
Anger mixed with emphasizing the cuteness could lead to markup such as:
<p><em>Cats are <em>cute</em> animals!</em></p>
The em
element isn't a generic "italics" element. Sometimes, text is intended to
stand out from the rest of the paragraph, as if it was in a different mood or voice. For this,
the i
element is more appropriate.
The em
element also isn't intended to convey importance; for that purpose, the
strong
element is more appropriate.
strong
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The strong
element represents strong importance, seriousness, or
urgency for its contents.
Importance: The strong
element can be used in a heading, caption,
or paragraph to distinguish the part that really matters from other parts that might be more
detailed, more jovial, or merely boilerplate.
For example, the first word of the previous paragraph is marked up with
strong
to distinguish it from the more detailed text in the rest of the
paragraph.
Seriousness: The strong
element can be used to mark up a warning
or caution notice.
Urgency: The strong
element can be used to denote contents that
the user needs to see sooner than other parts of the document.
The relative level of importance of a piece of content is given by its number of ancestor
strong
elements; each strong
element increases the importance of its
contents.
Changing the importance of a piece of text with the strong
element does not change
the meaning of the sentence.
Here, the word "chapter" and the actual chapter number are mere boilerplate, and the actual
name of the chapter is marked up with strong
:
<h1>Chapter 1: <strong>The Praxis</strong></h1>
In the following example, the name of the diagram in the caption is marked up with
strong
, to distinguish it from boilerplate text (before) and the description
(after):
<figcaption>Figure 1. <strong>Ant colony dynamics</strong>. The ants in this colony are affected by the heat source (upper left) and the food source (lower right).</figcaption>
In this example, the heading is really "Flowers, Bees, and Honey", but the author has added a
light-hearted addition to the heading. The strong
element is thus used to mark up
the first part to distinguish it from the latter part.
<h1><strong>Flowers, Bees, and Honey</strong> and other things I don't understand</h1>
Here is an example of a warning notice in a game, with the various parts marked up according to how important they are:
<p><strong>Warning.</strong> This dungeon is dangerous. <strong>Avoid the ducks.</strong> Take any gold you find. <strong><strong>Do not take any of the diamonds</strong>, they are explosive and <strong>will destroy anything within ten meters.</strong></strong> You have been warned.</p>
In this example, the strong
element is used to denote the part of the text that
the user is intended to read first.
<p>Welcome to Remy, the reminder system.</p> <p>Your tasks for today:</p> <ul> <li><p><strong>Turn off the oven.</strong></p></li> <li><p>Put out the trash.</p></li> <li><p>Do the laundry.</p></li> </ul>
small
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The small
element represents side comments such as small print.
Small print typically features disclaimers, caveats, legal restrictions, or copyrights. Small print is also sometimes used for attribution, or for satisfying licensing requirements.
The small
element does not "de-emphasize" or lower the importance of
text emphasized by the em
element or marked as important with the strong
element. To mark text as not emphasized or important, simply do not mark it up with the
em
or strong
elements respectively.
The small
element should not be used for extended spans of text, such as multiple
paragraphs, lists, or sections of text. It is only intended for short runs of text. The text of a
page listing terms of use, for instance, would not be a suitable candidate for the
small
element: in such a case, the text is not a side comment, it is the main content
of the page.
The small
element must not be used for subheadings.
In this example, the small
element is used to indicate that value-added tax is
not included in a price of a hotel room:
<dl> <dt>Single room <dd>199 € <small>breakfast included, VAT not included</small> <dt>Double room <dd>239 € <small>breakfast included, VAT not included</small> </dl>
In this second example, the small
element is used for a side comment in an
article.
<p>Example Corp today announced record profits for the second quarter <small>(Full Disclosure: Foo News is a subsidiary of Example Corp)</small>, leading to speculation about a third quarter merger with Demo Group.</p>
This is distinct from a sidebar, which might be multiple paragraphs long and is removed from the main flow of text. In the following example, we see a sidebar from the same article. This sidebar also has small print, indicating the source of the information in the sidebar.
<aside> <h1>Example Corp</h1> <p>This company mostly creates small software and Web sites.</p> <p>The Example Corp company mission is "To provide entertainment and news on a sample basis".</p> <p><small>Information obtained from <a href="http://example.com/about.html">example.com</a> home page.</small></p> </aside>
In this last example, the small
element is marked as being important
small print.
<p><strong><small>Continued use of this service will result in a kiss.</small></strong></p>
s
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The s
element represents contents that are no longer accurate or no
longer relevant.
The s
element is not appropriate when indicating document edits; to
mark a span of text as having been removed from a document, use the del
element.
In this example a recommended retail price has been marked as no longer relevant as the product in question has a new sale price.
<p>Buy our Iced Tea and Lemonade!</p> <p><s>Recommended retail price: $3.99 per bottle</s></p> <p><strong>Now selling for just $2.99 a bottle!</strong></p>
cite
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The cite
element represents a reference to a creative work. It must include the
title of the work or the name of the author(person, people or organization) or an URL reference, or a
reference in abbreviated form as per the conventions used for the addition of citation metadata.
Creative works include a book, a paper, an essay, a poem, a score, a song, a script, a film, a TV show, a game, a sculpture, a painting, a theatre production, a play, an opera, a musical, an exhibition, a legal case report, a computer program, , a web site, a web page, a blog post or comment, a forum post or comment, a tweet, a written or oral statement, etc.
Here is an example of the author of a quote referenced using the cite
element:
<p>In the words of <cite>Charles Bukowski</cite> - <q>An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way.</q></p>
This second example identifies the author of a tweet by referencing the authors name using the cite
element:
<blockquote class="twitter-tweet"> <p>♥ Bukowski in <a href="https://twitter.com/search?q=%23HTML5&src=hash">#HTML5</a> spec examples <a href="http://t.co/0FIEiYN1pC">http://t.co/0FIEiYN1pC</a></p><cite>— karl dubost (@karlpro) <a href="https://twitter.com/karlpro/statuses/370905307293442048">August 23, 2013</a></cite> </blockquote>
In this example the cite
element is used to reference the title of a work
in a bibliography:
<p><cite>Universal Declaration of Human Rights</cite>, United Nations, December 1948. Adopted by General Assembly resolution 217 A (III).</p>
In this example the cite
element is used to reference the title of a television show:
<p>Who is your favorite doctor (in <cite>Doctor Who</cite>)?</p>
A very common use for the cite
element is to identify the author of a comment in a blog post or forum, as in this example:
<article id="comment-1"> Comment by <cite><a href="http://oli.jp">Oli Studholme</a></cite> <time datetime="2013-08-19T16:01">August 19th, 2013 at 4:01 pm</time> <p>Unfortunately I don't think adding names back into the definition of <code>cite</code> solves the problem: of the 12 blockquote examples in <a href="http://oli.jp/example/blockquote-metadata/">Examples of block quote metadata</a>, there's not even one that's <em>just</em> a person’s name.</p> <p>A subset of the problem, maybe…</p> </article>
Another common use for the cite
element is to reference the URL
of a search result, as in this example:
<div id="resultStats">About 416,000,000 results 0.33 seconds) </div> ... <p><a href="http://www.w3.org/html/wg/">W3C <i>HTML Working Group</i></a></p> <p><cite>www.w3.org/<b>html</b>/wg/</cite></p> <p>15 Apr 2013 - The <i>HTML Working Group</i> is currently chartered to continue its work through 31 December 2014. A Plan 2014 document published by the...</p> ...
Where the cite
element is used to identify an abbreviated reference such as Ibid. it is
suggested that this reference be linked to the base reference:
<article> <h2>Book notes</h2> ... ... <blockquote>"Money is the real cause of poverty," <footer> <cite id="baseref">The Ragged-Trousered Philanthropists, page 89.</cite> </footer> </blockquote> ... ... <blockquote>"Money is the cause of poverty because it is the device by which those who are too lazy to work are enabled to rob the workers of the fruits of their labour." <a href="#baseref"><cite>Ibid.</cite></a> </blockquote> ... </article>
A citation is not a quote (for
which the q
element is appropriate).
This is incorrect usage, because cite
is not for
quotes:
<p><cite>This is wrong!, said Hillary.</cite> is a quote from the popular daytime TV drama When Ian became Hillary.</p>
This is an example of the correct usage:
<p><q>This is correct, said Hillary.</q> is a quote from the popular daytime TV drama <cite>When Ian became Hillary</cite>.</p>
q
elementcite
— Link to the source of the quotation or more information about the editaria-*
attributes
applicable to the allowed roles.HTMLQuoteElement
.The q
element represents some phrasing
content quoted from another source.
Quotation punctuation (such as quotation marks) that is quoting the contents of the element
must not appear immediately before, after, or inside q
elements; they will be
inserted into the rendering by the user agent.
Content inside a q
element must be quoted from another source, whose address, if
it has one, may be cited in the cite
attribute. The
source may be fictional, as when quoting characters in a novel or screenplay.
If the cite
attribute is present, it must be a valid URL
potentially surrounded by spaces. To obtain the corresponding citation
link, the value of the attribute must be resolved relative to
the element. User agents may allow users to follow such citation links, but they are
primarily intended for private use (e.g. by server-side scripts collecting statistics about a
site's use of quotations), not for readers.
The q
element must not be used in place of quotation marks that do not represent
quotes; for example, it is inappropriate to use the q
element for marking up
sarcastic statements.
The use of q
elements to mark up quotations is entirely optional; using explicit
quotation punctuation without q
elements is just as correct.
Here is a simple example of the use of the q
element:
<p>The man said <q>Things that are impossible just take longer</q>. I disagreed with him.</p>
Here is an example with both an explicit citation link in the q
element, and an
explicit citation outside:
<p>The W3C page <cite>About W3C</cite> says the W3C's mission is <q cite="http://www.w3.org/Consortium/">To lead the World Wide Web to its full potential by developing protocols and guidelines that ensure long-term growth for the Web</q>. I disagree with this mission.</p>
In the following example, the quotation itself contains a quotation:
<p>In <cite>Example One</cite>, he writes <q>The man said <q>Things that are impossible just take longer</q>. I disagreed with him</q>. Well, I disagree even more!</p>
In the following example, quotation marks are used instead of the q
element:
<p>His best argument was ❝I disagree❞, which I thought was laughable.</p>
In the following example, there is no quote — the quotation marks are used to name a
word. Use of the q
element in this case would be inappropriate.
<p>The word "ineffable" could have been used to describe the disaster resulting from the campaign's mismanagement.</p>
dfn
elementdfn
element descendants.title
attribute has special semantics on this element: Full term or expansion of abbreviation.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The dfn
element represents the defining instance of a term. The paragraph, description list group, or section that is the nearest ancestor of the dfn
element must also contain the definition(s) for the term given
by the dfn
element.
Defining term: If the dfn
element has a title
attribute, then the exact value of that attribute
is the term being defined. Otherwise, if it contains exactly one element child node and no child
Text
nodes, and that child element is an abbr
element with a title
attribute, then the exact value of that attribute is
the term being defined. Otherwise, it is the exact textContent
of the
dfn
element that gives the term being defined.
If the title
attribute of the dfn
element is
present, then it must contain only the term being defined.
The title
attribute of ancestor elements does not
affect dfn
elements.
An a
element that links to a dfn
element represents an instance of
the term defined by the dfn
element.
In the following fragment, the term "Garage Door Opener" is first defined in the first paragraph, then used in the second. In both cases, its abbreviation is what is actually displayed.
<p>The <dfn><abbr title="Garage Door Opener">GDO</abbr></dfn> is a device that allows off-world teams to open the iris.</p> <!-- ... later in the document: --> <p>Teal'c activated his <abbr title="Garage Door Opener">GDO</abbr> and so Hammond ordered the iris to be opened.</p>
With the addition of an a
element, the reference can be made explicit:
<p>The <dfn id=gdo><abbr title="Garage Door Opener">GDO</abbr></dfn> is a device that allows off-world teams to open the iris.</p> <!-- ... later in the document: --> <p>Teal'c activated his <a href=#gdo><abbr title="Garage Door Opener">GDO</abbr></a> and so Hammond ordered the iris to be opened.</p>
abbr
elementtitle
attribute has special semantics on this element: Full term or expansion of abbreviation.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The abbr
element represents an abbreviation or acronym, optionally
with its expansion. The title
attribute may be
used to provide an expansion of the abbreviation. The attribute, if specified, must contain an
expansion of the abbreviation, and nothing else.
The paragraph below contains an abbreviation marked up with the abbr
element.
This paragraph defines the term "Web Hypertext Application
Technology Working Group".
<p>The <dfn id=whatwg><abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr></dfn> is a loose unofficial collaboration of Web browser manufacturers and interested parties who wish to develop new technologies designed to allow authors to write and deploy Applications over the World Wide Web.</p>
An alternative way to write this would be:
<p>The <dfn id=whatwg>Web Hypertext Application Technology Working Group</dfn> (<abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr>) is a loose unofficial collaboration of Web browser manufacturers and interested parties who wish to develop new technologies designed to allow authors to write and deploy Applications over the World Wide Web.</p>
This paragraph has two abbreviations. Notice how only one is defined; the other, with no
expansion associated with it, does not use the abbr
element.
<p>The <abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr> started working on HTML5 in 2004.</p>
This paragraph links an abbreviation to its definition.
<p>The <a href="#whatwg"><abbr title="Web Hypertext Application Technology Working Group">WHATWG</abbr></a> community does not have much representation from Asia.</p>
This paragraph marks up an abbreviation without giving an expansion, possibly as a hook to apply styles for abbreviations (e.g. smallcaps).
<p>Philip` and Dashiva both denied that they were going to get the issue counts from past revisions of the specification to backfill the <abbr>WHATWG</abbr> issue graph.</p>
If an abbreviation is pluralized, the expansion's grammatical number (plural vs singular) must match the grammatical number of the contents of the element.
Here the plural is outside the element, so the expansion is in the singular:
<p>Two <abbr title="Working Group">WG</abbr>s worked on this specification: the <abbr>WHATWG</abbr> and the <abbr>HTMLWG</abbr>.</p>
Here the plural is inside the element, so the expansion is in the plural:
<p>Two <abbr title="Working Groups">WGs</abbr> worked on this specification: the <abbr>WHATWG</abbr> and the <abbr>HTMLWG</abbr>.</p>
Abbreviations do not have to be marked up using this element. It is expected to be useful in the following cases:
abbr
element with a title
attribute is an
alternative to including the expansion inline (e.g. in parentheses).abbr
element with a title
attribute or include the expansion inline in the text the first
time the abbreviation is used.abbr
element
can be used without a title
attribute.Providing an expansion in a title
attribute once
will not necessarily cause other abbr
elements in the same document with the same
contents but without a title
attribute to behave as if they had
the same expansion. Every abbr
element is independent.
ruby
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.
The ruby
element allows one or more spans of phrasing content to be marked with
ruby annotations. Ruby annotations are short runs of text presented alongside base text,
primarily used in East Asian typography as a guide for pronunciation or to include other
annotations. In Japanese, this form of typography is also known as furigana. Ruby text
can appear on either side, and sometimes both sides, of the base text, and it is possible to
control its position using CSS. A more complete introduction to ruby can be found in the
Use Cases & Exploratory Approaches for Ruby Markup document as well as in
CSS Ruby Module Level 1. [RUBY-UC] [CSSRUBY]
The content model of ruby
elements consists of one or more of the following
sequences:
rb
elements.
rt
or rtc
elements, each of which either immediately
preceded or followed by an rp
elements.
The ruby
, rb
, rtc
, and rt
elements can be
used for a variety of kinds of annotations, including in particular (though by no means limited
to) those described below. For more details on Japanese Ruby in particular, and how to render
Ruby for Japanese, see Requirements for Japanese Text Layout. [JLREQ] The rp
element can be used as fallback content when
ruby rendering is not supported.
Annotations (the ruby text) are associated individually with each ideographic character (the base text). In Japanese this is typically hiragana or katakana characters used to provide readings of kanji characters.
<ruby>base<rt>annotation</ruby>
When no rb
element is used, the base is implied, as above. But you can also
make it explicit. This can be useful notably for styling, or when consecutive bases are
to be treated as a group, as in the jukugo ruby example further down.
<ruby><rb>base<rt>annotation</ruby>
In the following example, notice how each annotation corresponds to a single base character.
<ruby>日<rt>に</rt></ruby><ruby>本<rt>ほん</rt></ruby> <ruby>語<rt>ご</rt></ruby>で<ruby>書<rt>か</rt></ruby> いた<ruby>作<rt>さく</rt></ruby><ruby>文<rt>ぶん</rt></ruby>です。
Ruby text interspersed in regular text provides structure akin to the following image:
This example can also be written as follows, using one ruby
element with
two segments of base text and two annotations (one for each) rather than two
back-to-back ruby
elements each with one base text segment and annotation
(as in the markup above):
<ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby> で<ruby>書<rt>か</rt></ruby> いた<ruby>作<rt>さく</rt>文<rt>ぶん</rt></ruby>です。
Group ruby is often used where phonetic annotations don't map to discreet base characters, or for semantic glosses that span the whole base text. For example, the word "today" is written with the characters 今日, literally "this day". But it's pronounced きょう (kyou), which can't be broken down into a "this" part and a "day" part. In typical rendering, you can't split text that is annotated with group ruby; it has to wrap as a single unit onto the next line. When a ruby text annotation maps to a base that is comprised of more than one character, then that base is grouped.
The following group ruby:
Can be marked up as follows:
<ruby>今日<rt>きょう</ruby>
Jukugo refers to a Japanese compound noun, i.e. a word made up of more than one kanji character. Jukugo ruby is a term that is used not to describe ruby annotations over jukugo text, but rather to describe ruby with a behaviour slightly different from mono or group ruby. Jukugo ruby is similar to mono ruby, in that there is a strong association between ruby text and individual base characters, but the ruby text is typically rendered as grouped together over multiple ideographs when they are on the same line.
The distinction is captured in this example:
Which can be marked up as follows:
<ruby>法<rb>華<rb>経<rt>ほ<rt>け<rt>きょう</ruby>
In this example, each rt
element is paired with its respective
rb
element, the difference with an interleaved
rb
/rt
approach being that the sequences of both base text and
ruby annotations are implicitly placed in common containers so that the grouping
information is captured.
For more details on Jukugo Ruby rendering, see Appendix F in the Requirements for Japanese Text Layout and Use Case C: Jukugo ruby in the Use Cases & Exploratory Approaches for Ruby Markup. [JLREQ] [RUBY-UC]
In some contexts, for instance when the font size or line height are too small for ruby to be readable, it is desirable to inline the ruby annotation such that it appears in parentheses after the text it annotates. This also provides a convenient fallback strategy for user agents that do not support rendering ruby annotations.
Inlining takes grouping into account. For example, Tokyo is written with two kanji characters, 東, which is pronounced とう, and 京, which is pronounced きょう. Each base character should be annotated individually, but the fallback should be 東京(とうきょう) not 東(とう)京(きょう). This can be marked up as follows:
<ruby>東<rb>京<rt>とう<rt>きょう</ruby>
Note that the above markup will enable the usage of parentheses when inlining for
browsers that support ruby layout, but for those that don't it will fail to provide
parenthetical fallback. This is where the rp
element is useful. It can be
inserted into the above example to provide the appropriate fallback when ruby layout is
not supported:
<ruby>東<rb>京<rp>(<rt>とう<rt>きょう<rp>)</ruby>
Sometimes, ruby can be used to annotate a base twice.
In the following example, the Chinese word for San Francisco (旧金山, i.e. “old gold mountain”) is annotated both using pinyin to give the pronunciation, and with the original English.
Which is marked up as follows:
<ruby><rb>旧<rb>金<rb>山<rt>jiù<rt>jīn<rt>shān<rtc>San Francisco</ruby>
In this example, a single base run of three base characters is annotated with three
pinyin ruby text segments in a first (implicit) container, and an rtc
element is introduced in order to provide a second single ruby text annotation
being the city's English name.
We can also revisit our jukugo example above with 上手 ("skill") to show how it can be annotation in both kana and romaji phonetics while at the same time maintaining the pairing to bases and annotation grouping information.
Which is marked up as follows:
<ruby><rb>上<rb>手<rt>じよう<rt>ず<rtc><rt>jou<rt>zu</ruby>
Text that is a direct child of the rtc
element implicitly produces a ruby
text segment as if it were contained in an rt
element. In this contrived
example, this is shown with some symbols that are given names in English and French with
annotations intended to appear on either side of the base symbol.
<ruby> ♥<rt>Heart<rtc lang=fr>Cœur</rtc> ☘<rt>Shamrock<rtc lang=fr>Trèfle</rtc> ✶<rt>Star<rtc lang=fr>Étoile </ruby>
Similarly, text directly inside a ruby
element implicitly produces a ruby
base as if it were contained in an rb
element, and rt
children
of ruby
are implicitly contained in an rtc
container. In
effect, the above example is equivalent (in meaning, though not in the DOM it produces)
to the following:
<ruby> <rb>♥</rb><rtc><rt>Heart</rt></rtc><rtc lang=fr><rt>Cœur</rt></rtc> <rb>☘</rb><rtc><rt>Shamrock</rt></rtc><rtc lang=fr><rt>Trèfle</rt></rtc> <rb>✶</rb><rtc><rt>Star</rt></rtc><rtc lang=fr><rt>Étoile</rt></rtc> </ruby>
Within a ruby element, content is parcelled into a series of ruby segments. Each ruby segment is described by:
rb
element.
rtc
elements, or to sequences of rt
elements implicitly recognised as contained in an anonymous ruby text
container.
Each ruby text container is described by zero or more ruby text annotations each of which is a DOM range that may contain
phrasing content or an rt
element, and an annotations range that is a range
including all the annotations for that container. A ruby text container is also
known (primarily in a CSS context) as a ruby annotation container.
Furthermore, a ruby element contains ignored ruby content. Ignored ruby content
does not form part of the document's semantics. It consists of some inter-element
whitespace and rp
elements, the latter of which are used for legacy user
agents that do not support ruby at all.
The process of annotation pairing associates ruby annotations with ruby bases. Within each ruby segment, each ruby base in the ruby base container is paired with one ruby text annotation from the ruby text container, in order. If there are not enough ruby text annotations in a ruby annotation container, the last one is associated with any excess ruby bases. (If there are not any in the ruby annotation container, an anonymous empty one is assumed to exist.) If there are not enough ruby bases, any remaining ruby text annotations are assumed to be associated with empty, anonymous bases inserted at the end of the ruby base container.
Note that the terms ruby segment, ruby base, ruby text annotation, ruby text container, ruby base container, and ruby annotation container have their equivalents in CSS Ruby Module Level 1. [CSSRUBY]
Informally, the segmentation and categorisation algorithm below performs a simple set of
tasks. First it processes adjacent rb
elements, text nodes, and non-ruby
elements into a list of bases. Then it processes any number of rtc
elements or
sequences of rt
elements that are considered to automatically map to an
anonymous ruby text container. Put together these data items form a ruby
segment as detailed in the data model above. It will continue to produce such segments
until it reaches the end of the content of a given ruby
element. The complexity
of the algorithm below compared to this informal description stems from the need to support
an author-friendly syntax and being mindful of inter-element white space.
At any particular time, the segmentation and categorisation of content of a ruby
element
is the result that would be obtained from running the following algorithm:
ruby
element for which the algorithm is
being run.
rp
element, then increment
index by one and jump to the step labelled process a ruby child. (Note
that this has the effect of including this element in any range that we are currently
processing. This is done intentionally so that misplaced rp
can be
processed correctly; semantically they are ignored all the same.)
rt
element, then run these substeps:
rtc
element, then run these
substeps:
rtc
element and a DOM range whose start is
the boundary point (root,
index) and whose end is the boundary point (root, index plus
one). Append this new ruby annotation container at the end of current
annotation containers.
rt
element, an
rtc
element, or an rp
element, then set
index to the value of lookahead index and jump to the step
labelled process a ruby child.
rb
element, then run these substeps:
When the steps above say to commit a ruby segment, it means to run the following steps at that point in the algorithm:
When the steps above say to commit the base range, it means to run the following steps at that point in the algorithm:
When the steps above say to commit current annotations, it means to run the following steps at that point in the algorithm:
When the steps above say to commit an automatic base, it means to run the following steps at that point in the algorithm:
rb
elementruby
element.An rb
element's end tag may be omitted
if the rb
element is immediately followed by an rb
, rt
,
rtc
or rp
element, or if there is no more content in the parent
element.
aria-*
attributes
applicable to the allowed roles.HTMLElement
.
The rb
element marks the base text component of a ruby annotation. When it is
the child of a ruby
element, it doesn't represent anything itself, but its parent ruby
element uses it as part of determining what it represents.
An rb
element that is not a child of a ruby
element
represents the same thing as its children.
rt
elementruby
or of an rtc
element.An rt
element's end tag may be omitted if the
rt
element is immediately followed by an rb
, rt
, rtc
or
rp
element, or if there is no more content in the parent element.
aria-*
attributes
applicable to the allowed roles.HTMLElement
.
The rt
element marks the ruby text component of a ruby annotation. When it is
the child of a ruby
element or of an rtc
element that is itself
the child of a ruby
element, it doesn't represent anything itself, but its ancestor ruby
element uses it as part of determining what it represents.
An rt
element that is not a child of a ruby
element or of an
rtc
element that is itself the child of a ruby
element
represents the same thing as its children.
rtc
elementruby
element.rt
, or rp
elements.An rtc
element's end tag may be omitted
if the rtc
element is immediately followed by an rb
or
rtc
element, or if there is no more content in the parent
element.
aria-*
attributes
applicable to the allowed roles.HTMLElement
.
The rtc
element marks a ruby text container for ruby text components
in a ruby annotation. When it is the child of a ruby
element it doesn't represent anything itself, but its parent ruby
element
uses it as part of determining what it represents.
An rtc
element that is not a child of a ruby
element
represents the same thing as its children.
When an rtc
element is processed as part of the segmentation and
categorisation of content for a ruby
element, the following algorithm
defines how to process an rtc
element:
rtc
element for which the algorithm is
being run.
rt
element, then run these substeps:
When the steps above say to commit an automatic annotation, it means to run the following steps at that point in the algorithm:
rp
elementruby
or rtc
element, either immediately before or
immediately after an rt
or rtc
element, but not between
rt
elements.
An rp
element's end tag may be omitted
if the rp
element is immediately followed by an rb
, rt
,
rtc
or rp
element, or if there is no more content in the parent
element.
aria-*
attributes
applicable to the allowed roles.HTMLElement
.
The rp
element is used to provide fallback text to be shown by user agents that
don't support ruby annotations. One widespread convention is to provide parentheses around
the ruby text component of a ruby annotation.
The contents of the rp
elements are typically not displayed by user agents
which do support ruby annotations
An rp
element that is a child of a ruby
element represents nothing. An rp
element whose parent element is not a ruby
element represents its
children.
The example shown previously, in which each ideograph in the text 漢字 is annotated with its phonetic reading, could be expanded
to use rp
so that in legacy user agents the readings are in parentheses (please
note that white space has been introduced into this example in order to make it more
readable):
...
<ruby>
漢
<rb>字</rb>
<rp> (</rp>
<rt>かん</rt>
<rt>じ</rt>
<rp>) </rp>
</ruby>
...
In conforming user agents the rendering would be as above, but in user agents that do not support ruby, the rendering would be:
... 漢字 (かんじ) ...
When there are multiple annotations for a segment, rp
elements can also be
placed between the annotations. Here is another copy of an earlier contrived example showing
some symbols with names given in English and French using double-sided annotations, but this
time with rp
elements as well:
<ruby> ♥<rp>: </rp><rt>Heart</rt><rp>, </rp><rtc><rt lang=fr>Cœur</rt></rtc><rp>.</rp> ☘<rp>: </rp><rt>Shamrock</rt><rp>, </rp><rtc><rt lang=fr>Trèfle</rt></rtc><rp>.</rp> ✶<rp>: </rp><rt>Star</rt><rp>, </rp><rtc><rt lang=fr>Étoile</rt></rtc><rp>.</rp> </ruby>
This would make the example render as follows in non-ruby-capable user agents:
♥: Heart, Cœur. ☘: Shamrock, Trèfle. ✶: Star, Étoile.
data
elementvalue
— Machine-readable valuearia-*
attributes
applicable to the allowed roles.interface HTMLDataElement : HTMLElement { attribute DOMString value; };
The data
element represents its contents, along with a
machine-readable form of those contents in the value
attribute.
The value
attribute must be present. Its value
must be a representation of the element's contents in a machine-readable format.
When the value is date- or time-related, the more specific time
element can be used instead.
The element can be used for several purposes.
When combined with microformats or the microdata attributes defined in
this specification, the element serves to provide both a machine-readable value for the purposes
of data processors, and a human-readable value for the purposes of rendering in a Web browser. In
this case, the format to be used in the value
attribute is
determined by the microformats or microdata vocabulary in use.
The element can also, however, be used in conjunction with scripts in the page, for when a
script has a literal value to store alongside a human-readable value. In such cases, the format to
be used depends only on the needs of the script. (The data-*
attributes can also be useful in such situations.)
The value
IDL attribute must
reflect the content attribute of the same name.
Here, a short table has its numeric values encoded using data
so that the
table sorting model can provide a sorting mechanism on each column, despite the
numbers being presented in textual form in one column and in a decomposed form in another.
<table sortable> <thead> <tr> <th> Game <th> Corporations <th> Map Size <tbody> <tr> <td> 1830 <td> <data value="8">Eight</data> <td> <data value="93">19+74 hexes (93 total)</data> <tr> <td> 1856 <td> <data value="11">Eleven</data> <td> <data value="99">12+87 hexes (99 total)</data> <tr> <td> 1870 <td> <data value="10">Ten</data> <td> <data value="149">4+145 hexes (149 total)</data> </table>
time
elementdatetime
— Machine-readable valuearia-*
attributes
applicable to the allowed roles.interface HTMLTimeElement : HTMLElement { attribute DOMString dateTime; };
The time
element represents its contents, along with a
machine-readable form of those contents in the datetime
attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and
durations, as described below.
The datetime
attribute may be present. If
present, its value must be a representation of the element's contents in a machine-readable
format.
A time
element that does not have a datetime
content attribute must not have any element
descendants.
The datetime value of a time
element is the value of the element's
datetime
content attribute, if it has one, or the
element's textContent
, if it does not.
The datetime value of a time
element must match one of the following
syntaxes.
<time>2011-11</time>
<time>2011-11-18</time>
<time>11-18</time>
<time>14:54</time>
<time>14:54:39</time>
<time>14:54:39.929</time>
<time>2011-11-18T14:54</time>
<time>2011-11-18T14:54:39</time>
<time>2011-11-18T14:54:39.929</time>
<time>2011-11-18 14:54</time>
<time>2011-11-18 14:54:39</time>
<time>2011-11-18 14:54:39.929</time>
Times with dates but without a time zone offset are useful for specifying events that are observed at the same specific time in each time zone, throughout a day. For example, the 2020 new year is celebrated at 2020-01-01 00:00 in each time zone, not at the same precise moment across all time zones. For events that occur at the same time across all time zones, for example a videoconference meeting, a valid global date and time string is likely more useful.
<time>Z</time>
<time>+0000</time>
<time>+00:00</time>
<time>-0800</time>
<time>-08:00</time>
For times without dates (or times referring to events that recur on multiple dates), specifying the geographic location that controls the time is usually more useful than specifying a time zone offset, because geographic locations change time zone offsets with daylight savings time. In some cases, geographic locations even change time zone, e.g. when the boundaries of those time zones are redrawn, as happened with Samoa at the end of 2011. There exists a time zone database that describes the boundaries of time zones and what rules apply within each such zone, known as the time zone database. [TZDATABASE]
<time>2011-11-18T14:54Z</time>
<time>2011-11-18T14:54:39Z</time>
<time>2011-11-18T14:54:39.929Z</time>
<time>2011-11-18T14:54+0000</time>
<time>2011-11-18T14:54:39+0000</time>
<time>2011-11-18T14:54:39.929+0000</time>
<time>2011-11-18T14:54+00:00</time>
<time>2011-11-18T14:54:39+00:00</time>
<time>2011-11-18T14:54:39.929+00:00</time>
<time>2011-11-18T06:54-0800</time>
<time>2011-11-18T06:54:39-0800</time>
<time>2011-11-18T06:54:39.929-0800</time>
<time>2011-11-18T06:54-08:00</time>
<time>2011-11-18T06:54:39-08:00</time>
<time>2011-11-18T06:54:39.929-08:00</time>
<time>2011-11-18 14:54Z</time>
<time>2011-11-18 14:54:39Z</time>
<time>2011-11-18 14:54:39.929Z</time>
<time>2011-11-18 14:54+0000</time>
<time>2011-11-18 14:54:39+0000</time>
<time>2011-11-18 14:54:39.929+0000</time>
<time>2011-11-18 14:54+00:00</time>
<time>2011-11-18 14:54:39+00:00</time>
<time>2011-11-18 14:54:39.929+00:00</time>
<time>2011-11-18 06:54-0800</time>
<time>2011-11-18 06:54:39-0800</time>
<time>2011-11-18 06:54:39.929-0800</time>
<time>2011-11-18 06:54-08:00</time>
<time>2011-11-18 06:54:39-08:00</time>
<time>2011-11-18 06:54:39.929-08:00</time>
Times with dates and a time zone offset are useful for specifying specific events, or recurring virtual events where the time is not anchored to a specific geographic location. For example, the precise time of an asteroid impact, or a particular meeting in a series of meetings held at 1400 UTC every day, regardless of whether any particular part of the world is observing daylight savings time or not. For events where the precise time varies by the local time zone offset of a specific geographic location, a valid local date and time string combined with that geographic location is likely more useful.
<time>2011-W47</time>
<time>2011</time>
<time>0001</time>
<time>PT4H18M3S</time>
<time>4h 18m 3s</time>
The machine-readable equivalent of the element's contents must be obtained from the element's datetime value by using the following algorithm:
If parsing a month string from the element's datetime value returns a month, that is the machine-readable equivalent; abort these steps.
If parsing a date string from the element's datetime value returns a date, that is the machine-readable equivalent; abort these steps.
If parsing a yearless date string from the element's datetime value returns a yearless date, that is the machine-readable equivalent; abort these steps.
If parsing a time string from the element's datetime value returns a time, that is the machine-readable equivalent; abort these steps.
If parsing a local date and time string from the element's datetime value returns a local date and time, that is the machine-readable equivalent; abort these steps.
If parsing a time-zone offset string from the element's datetime value returns a time-zone offset, that is the machine-readable equivalent; abort these steps.
If parsing a global date and time string from the element's datetime value returns a global date and time, that is the machine-readable equivalent; abort these steps.
If parsing a week string from the element's datetime value returns a week, that is the machine-readable equivalent; abort these steps.
If the element's datetime value consists of only ASCII digits, at least one of which is not U+0030 DIGIT ZERO (0), then the machine-readable equivalent is the base-ten interpretation of those digits, representing a year; abort these steps.
If parsing a duration string from the element's datetime value returns a duration, that is the machine-readable equivalent; abort these steps.
There is no machine-readable equivalent.
The algorithms referenced above are intended to be designed such that for any arbitrary string s, only one of the algorithms returns a value. A more efficient approach might be to create a single algorithm that parses all these data types in one pass; developing such an algorithm is left as an exercise to the reader.
The dateTime
IDL attribute must
reflect the element's datetime
content
attribute.
The time
element can be used to encode dates, for example in microformats. The
following shows a hypothetical way of encoding an event using a variant on hCalendar that uses
the time
element:
<div class="vevent"> <a class="url" href="http://www.web2con.com/">http://www.web2con.com/</a> <span class="summary">Web 2.0 Conference</span>: <time class="dtstart" datetime="2005-10-05">October 5</time> - <time class="dtend" datetime="2005-10-07">7</time>, at the <span class="location">Argent Hotel, San Francisco, CA</span> </div>
Here, a fictional microdata vocabulary based on the Atom vocabulary is used with the
time
element to mark up a blog post's publication date.
<article itemscope itemtype="http://n.example.org/rfc4287"> <h1 itemprop="title">Big tasks</h1> <footer>Published <time itemprop="published" datetime="2009-08-29">two days ago</time>.</footer> <p itemprop="content">Today, I went out and bought a bike for my kid.</p> </article>
In this example, another article's publication date is marked up using time
, this
time using the schema.org microdata vocabulary:
<article itemscope itemtype="http://schema.org/BlogPosting"> <h1 itemprop="headline">Small tasks</h1> <footer>Published <time itemprop="datePublished" datetime="2009-08-30">yesterday</time>.</footer> <p itemprop="articleBody">I put a bike bell on his bike.</p> </article>
In the following snippet, the time
element is used to encode a date in the
ISO8601 format, for later processing by a script:
<p>Our first date was <time datetime="2006-09-23">a Saturday</time>.</p>
In this second snippet, the value includes a time:
<p>We stopped talking at <time datetime="2006-09-24T05:00-07:00">5am the next morning</time>.</p>
A script loaded by the page (and thus privy to the page's internal convention of marking up
dates and times using the time
element) could scan through the page and look at all
the time
elements therein to create an index of dates and times.
For example, this element conveys the string "Tuesday" with the additional semantic that the 18th of November 2011 is the meaning that corresponds to "Tuesday":
Today is <time datetime="2011-11-18">Tuesday</time>.
In this example, a specific time in the Pacific Standard Time timezone is specified:
Your next meeting is at <time datetime="2011-11-18T15:00-08:00">3pm</time>.
code
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The code
element represents a fragment of computer code. This could
be an XML element name, a file name, a computer program, or any other string that a computer would
recognize.
There is no formal way to indicate the language of computer code being marked up. Authors who
wish to mark code
elements with the language used, e.g. so that syntax highlighting
scripts can use the right rules, can use the class
attribute, e.g.
by adding a class prefixed with "language-
" to the element.
The following example shows how the element can be used in a paragraph to mark up element names and computer code, including punctuation.
<p>The <code>code</code> element represents a fragment of computer code.</p> <p>When you call the <code>activate()</code> method on the <code>robotSnowman</code> object, the eyes glow.</p> <p>The example below uses the <code>begin</code> keyword to indicate the start of a statement block. It is paired with an <code>end</code> keyword, which is followed by the <code>.</code> punctuation character (full stop) to indicate the end of the program.</p>
The following example shows how a block of code could be marked up using the pre
and code
elements.
<pre><code class="language-pascal">var i: Integer; begin i := 1; end.</code></pre>
A class is used in that example to indicate the language used.
See the pre
element for more details.
var
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The var
element represents a variable. This could be an actual
variable in a mathematical expression or programming context, an identifier representing a
constant, a symbol identifying a physical quantity, a function parameter, or just be a term used
as a placeholder in prose.
In the paragraph below, the letter "n" is being used as a variable in prose:
<p>If there are <var>n</var> pipes leading to the ice cream factory then I expect at <em>least</em> <var>n</var> flavors of ice cream to be available for purchase!</p>
For mathematics, in particular for anything beyond the simplest of expressions, MathML is more
appropriate. However, the var
element can still be used to refer to specific
variables that are then mentioned in MathML expressions.
In this example, an equation is shown, with a legend that references the variables in the
equation. The expression itself is marked up with MathML, but the variables are mentioned in the
figure's legend using var
.
<figure> <math> <mi>a</mi> <mo>=</mo> <msqrt> <msup><mi>b</mi><mn>2</mn></msup> <mi>+</mi> <msup><mi>c</mi><mn>2</mn></msup> </msqrt> </math> <figcaption> Using Pythagoras' theorem to solve for the hypotenuse <var>a</var> of a triangle with sides <var>b</var> and <var>c</var> </figcaption> </figure>
Here, the equation describing mass-energy equivalence is used in a sentence, and the
var
element is used to mark the variables and constants in that equation:
<p>Then he turned to the blackboard and picked up the chalk. After a few moment's thought, he wrote <var>E</var> = <var>m</var> <var>c</var><sup>2</sup>. The teacher looked pleased.</p>
samp
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The samp
element represents sample or quoted output from another
program or computing system.
See the pre
and kbd
elements for more details.
This element can be contrasted with the output
element, which can be
used to provide immediate output in a Web application.
This example shows the samp
element being used
inline:
<p>The computer said <samp>Too much cheese in tray two</samp> but I didn't know what that meant.</p>
This second example shows a block of sample output. Nested samp
and
kbd
elements allow for the styling of specific elements of the sample output using a
style sheet. There's also a few parts of the samp
that are annotated with even more
detailed markup, to enable very precise styling. To achieve this, span
elements are
used.
<pre><samp><span class="prompt">jdoe@mowmow:~$</span> <kbd>ssh demo.example.com</kbd> Last login: Tue Apr 12 09:10:17 2005 from mowmow.example.com on pts/1 Linux demo 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189 #1 SMP Tue Feb 1 11:22:36 PST 2005 i686 unknown <span class="prompt">jdoe@demo:~$</span> <span class="cursor">_</span></samp></pre>
kbd
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The kbd
element represents user input (typically keyboard input,
although it may also be used to represent other input, such as voice commands).
When the kbd
element is nested inside a samp
element, it represents
the input as it was echoed by the system.
When the kbd
element contains a samp
element, it represents
input based on system output, for example invoking a menu item.
When the kbd
element is nested inside another kbd
element, it
represents an actual key or other single unit of input as appropriate for the input mechanism.
Here the kbd
element is used to indicate keys to press:
<p>To make George eat an apple, press <kbd><kbd>Shift</kbd>+<kbd>F3</kbd></kbd></p>
In this second example, the user is told to pick a particular menu item. The outer
kbd
element marks up a block of input, with the inner kbd
elements
representing each individual step of the input, and the samp
elements inside them
indicating that the steps are input based on something being displayed by the system, in this
case menu labels:
<p>To make George eat an apple, select <kbd><kbd><samp>File</samp></kbd>|<kbd><samp>Eat Apple...</samp></kbd></kbd> </p>
Such precision isn't necessary; the following is equally fine:
<p>To make George eat an apple, select <kbd>File | Eat Apple...</kbd></p>
sub
and sup
elementsaria-*
attributes
applicable to the allowed roles.HTMLElement
.The sup
element represents a superscript and the sub
element represents a subscript.
These elements must be used only to mark up typographical conventions with specific meanings,
not for typographical presentation for presentation's sake. For example, it would be inappropriate
for the sub
and sup
elements to be used in the name of the LaTeX
document preparation system. In general, authors should use these elements only if the
absence of those elements would change the meaning of the content.
In certain languages, superscripts are part of the typographical conventions for some abbreviations.
<p>The most beautiful women are <span lang="fr"><abbr>M<sup>lle</sup></abbr> Gwendoline</span> and <span lang="fr"><abbr>M<sup>me</sup></abbr> Denise</span>.</p>
The sub
element can be used inside a var
element, for variables that
have subscripts.
Here, the sub
element is used to represent the subscript that identifies the
variable in a family of variables:
<p>The coordinate of the <var>i</var>th point is (<var>x<sub><var>i</var></sub></var>, <var>y<sub><var>i</var></sub></var>). For example, the 10th point has coordinate (<var>x<sub>10</sub></var>, <var>y<sub>10</sub></var>).</p>
Mathematical expressions often use subscripts and superscripts. Authors are encouraged to use
MathML for marking up mathematics, but authors may opt to use sub
and
sup
if detailed mathematical markup is not desired. [MATHML]
<var>E</var>=<var>m</var><var>c</var><sup>2</sup>
f(<var>x</var>, <var>n</var>) = log<sub>4</sub><var>x</var><sup><var>n</var></sup>
i
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The i
element represents a span of text in an alternate voice or
mood, or otherwise offset from the normal prose in a manner indicating a different quality of
text, such as a taxonomic designation, a technical term, an idiomatic phrase from another
language, transliteration, a thought, or a ship name in Western texts.
Terms in languages different from the main text should be annotated with lang
attributes (or, in XML, lang
attributes in the XML namespace).
The examples below show uses of the i
element:
<p>The <i class="taxonomy">Felis silvestris catus</i> is cute.</p> <p>The term <i>prose content</i> is defined above.</p> <p>There is a certain <i lang="fr">je ne sais quoi</i> in the air.</p>
In the following example, a dream sequence is marked up using
i
elements.
<p>Raymond tried to sleep.</p> <p><i>The ship sailed away on Thursday</i>, he dreamt. <i>The ship had many people aboard, including a beautiful princess called Carey. He watched her, day-in, day-out, hoping she would notice him, but she never did.</i></p> <p><i>Finally one night he picked up the courage to speak with her—</i></p> <p>Raymond woke with a start as the fire alarm rang out.</p>
Authors can use the class
attribute on the i
element to identify why the element is being used, so that if the style of a particular use (e.g.
dream sequences as opposed to taxonomic terms) is to be changed at a later date, the author
doesn't have to go through the entire document (or series of related documents) annotating each
use.
Authors are encouraged to consider whether other elements might be more applicable than the
i
element, for instance the em
element for marking up stress emphasis,
or the dfn
element to mark up the defining instance of a term.
Style sheets can be used to format i
elements, just like any other
element can be restyled. Thus, it is not the case that content in i
elements will
necessarily be italicized.
b
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The b
element represents a span of text to which attention is being
drawn for utilitarian purposes without conveying any extra importance and with no implication of
an alternate voice or mood, such as key words in a document abstract, product names in a review,
actionable words in interactive text-driven software, or an article lede.
The following example shows a use of the b
element to highlight key words without
marking them up as important:
<p>The <b>frobonitor</b> and <b>barbinator</b> components are fried.</p>
In the following example, objects in a text adventure are highlighted as being special by use
of the b
element.
<p>You enter a small room. Your <b>sword</b> glows brighter. A <b>rat</b> scurries past the corner wall.</p>
Another case where the b
element is appropriate is in marking up the lede (or
lead) sentence or paragraph. The following example shows how a BBC article about
kittens adopting a rabbit as their own could be marked up:
<article> <h2>Kittens 'adopted' by pet rabbit</h2> <p><b class="lede">Six abandoned kittens have found an unexpected new mother figure — a pet rabbit.</b></p> <p>Veterinary nurse Melanie Humble took the three-week-old kittens to her Aberdeen home.</p> [...]
As with the i
element, authors can use the class
attribute on the b
element to identify why the element is being used, so that if the
style of a particular use is to be changed at a later date, the author doesn't have to go through
annotating each use.
The b
element should be used as a last resort when no other element is more
appropriate. In particular, headings should use the h1
to h6
elements,
stress emphasis should use the em
element, importance should be denoted with the
strong
element, and text marked or highlighted should use the mark
element.
The following would be incorrect usage:
<p><b>WARNING!</b> Do not frob the barbinator!</p>
In the previous example, the correct element to use would have been strong
, not
b
.
Style sheets can be used to format b
elements, just like any other
element can be restyled. Thus, it is not the case that content in b
elements will
necessarily be boldened.
u
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The u
element represents a span of text with an unarticulated, though
explicitly rendered, non-textual annotation, such as labeling the text as being a proper name in
Chinese text (a Chinese proper name mark), or labeling the text as being misspelt.
In most cases, another element is likely to be more appropriate: for marking stress emphasis,
the em
element should be used; for marking key words or phrases either the
b
element or the mark
element should be used, depending on the context;
for marking book titles, the cite
element should be used; for labeling text with explicit textual annotations, the
ruby
element should be used; for labeling ship names in Western texts, the
i
element should be used.
The default rendering of the u
element in visual presentations
clashes with the conventional rendering of hyperlinks (underlining). Authors are encouraged to
avoid using the u
element where it could be confused for a hyperlink.
In this example, a u
element is used to mark a word as misspelt:
<p>The <u>see</u> is full of fish.</p>
mark
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The mark
element represents a run of text in one document marked or
highlighted for reference purposes, due to its relevance in another context. When used in a
quotation or other block of text referred to from the prose, it indicates a highlight that was not
originally present but which has been added to bring the reader's attention to a part of the text
that might not have been considered important by the original author when the block was originally
written, but which is now under previously unexpected scrutiny. When used in the main prose of a
document, it indicates a part of the document that has been highlighted due to its likely
relevance to the user's current activity.
This example shows how the mark
element can be used to bring attention to a
particular part of a quotation:
<p lang="en-US">Consider the following quote:</p> <blockquote lang="en-GB"> <p>Look around and you will find, no-one's really <mark>colour</mark> blind.</p> </blockquote> <p lang="en-US">As we can tell from the <em>spelling</em> of the word, the person writing this quote is clearly not American.</p>
(If the goal was to mark the element as misspelt, however, the u
element,
possibly with a class, would be more appropriate.)
Another example of the mark
element is highlighting parts of a document that are
matching some search string. If someone looked at a document, and the server knew that the user
was searching for the word "kitten", then the server might return the document with one paragraph
modified as follows:
<p>I also have some <mark>kitten</mark>s who are visiting me these days. They're really cute. I think they like my garden! Maybe I should adopt a <mark>kitten</mark>.</p>
In the following snippet, a paragraph of text refers to a specific part of a code fragment.
<p>The highlighted part below is where the error lies:</p> <pre><code>var i: Integer; begin i := <mark>1.1</mark>; end.</code></pre>
This is separate from syntax highlighting, for which span
is more
appropriate. Combining both, one would get:
<p>The highlighted part below is where the error lies:</p> <pre><code><span class=keyword>var</span> <span class=ident>i</span>: <span class=type>Integer</span>; <span class=keyword>begin</span> <span class=ident>i</span> := <span class=literal><mark>1.1</mark></span>; <span class=keyword>end</span>.</code></pre>
This is another example showing the use of mark
to highlight a part of quoted
text that was originally not emphasized. In this example, common typographic conventions have led
the author to explicitly style mark
elements in quotes to render in italics.
<article> <style scoped> blockquote mark, q mark { font: inherit; font-style: italic; text-decoration: none; background: transparent; color: inherit; } .bubble em { font: inherit; font-size: larger; text-decoration: underline; } </style> <h1>She knew</h1> <p>Did you notice the subtle joke in the joke on panel 4?</p> <blockquote> <p class="bubble">I didn't <em>want</em> to believe. <mark>Of course on some level I realised it was a known-plaintext attack.</mark> But I couldn't admit it until I saw for myself.</p> </blockquote> <p>(Emphasis mine.) I thought that was great. It's so pedantic, yet it explains everything neatly.</p> </article>
Note, incidentally, the distinction between the em
element in this example, which
is part of the original text being quoted, and the mark
element, which is
highlighting a part for comment.
The following example shows the difference between denoting the importance of a span
of text (strong
) as opposed to denoting the relevance of a span of text
(mark
). It is an extract from a textbook, where the extract has had the parts
relevant to the exam highlighted. The safety warnings, important though they may be, are
apparently not relevant to the exam.
<h3>Wormhole Physics Introduction</h3> <p><mark>A wormhole in normal conditions can be held open for a maximum of just under 39 minutes.</mark> Conditions that can increase the time include a powerful energy source coupled to one or both of the gates connecting the wormhole, and a large gravity well (such as a black hole).</p> <p><mark>Momentum is preserved across the wormhole. Electromagnetic radiation can travel in both directions through a wormhole, but matter cannot.</mark></p> <p>When a wormhole is created, a vortex normally forms. <strong>Warning: The vortex caused by the wormhole opening will annihilate anything in its path.</strong> Vortexes can be avoided when using sufficiently advanced dialing technology.</p> <p><mark>An obstruction in a gate will prevent it from accepting a wormhole connection.</mark></p>
bdi
elementdir
global attribute has special semantics on this element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The bdi
element represents a span of text that is to be isolated from
its surroundings for the purposes of bidirectional text formatting. [BIDI]
The dir
global attribute defaults to auto
on this element (it never inherits from the parent element like
with other elements).
This element has rendering requirements involving the bidirectional algorithm.
This element is especially useful when embedding user-generated content with an unknown directionality.
In this example, usernames are shown along with the number of posts that the user has
submitted. If the bdi
element were not used, the username of the Arabic user would
end up confusing the text (the bidirectional algorithm would put the colon and the number "3"
next to the word "User" rather than next to the word "posts").
<ul> <li>User <bdi>jcranmer</bdi>: 12 posts. <li>User <bdi>hober</bdi>: 5 posts. <li>User <bdi>إيان</bdi>: 3 posts. </ul>
bdo
elementdir
global attribute has special semantics on this element.aria-*
attributes
applicable to the allowed roles.HTMLElement
.The bdo
element represents explicit text directionality formatting
control for its children. It allows authors to override the Unicode bidirectional algorithm by
explicitly specifying a direction override. [BIDI]
Authors must specify the dir
attribute on this element, with the
value ltr
to specify a left-to-right override and with the value rtl
to
specify a right-to-left override. The auto
value must not be specified.
This element has rendering requirements involving the bidirectional algorithm.
span
elementaria-*
attributes
applicable to the allowed roles.interface HTMLSpanElement : HTMLElement {};
The span
element doesn't mean anything on its own, but can be useful when used
together with the global attributes, e.g. class
,
lang
, or dir
. It
represents its children.
In this example, a code fragment is marked up using span
elements and class
attributes so that its keywords and identifiers can be
colour-coded from CSS:
<pre><code class="lang-c"><span class="keyword">for</span> (<span class="ident">j</span> = 0; <span class="ident">j</span> < 256; <span class="ident">j</span>++) { <span class="ident">i_t3</span> = (<span class="ident">i_t3</span> & 0x1ffff) | (<span class="ident">j</span> << 17); <span class="ident">i_t6</span> = (((((((<span class="ident">i_t3</span> >> 3) ^ <span class="ident">i_t3</span>) >> 1) ^ <span class="ident">i_t3</span>) >> 8) ^ <span class="ident">i_t3</span>) >> 5) & 0xff; <span class="keyword">if</span> (<span class="ident">i_t6</span> == <span class="ident">i_t1</span>) <span class="keyword">break</span>; }</code></pre>
br
elementaria-*
attributes
applicable to the allowed roles.interface HTMLBRElement : HTMLElement { // also has obsolete members };
The br
element represents a line break.
While line breaks are usually represented in visual media by physically moving subsequent text to a new line, a style sheet or user agent would be equally justified in causing line breaks to be rendered in a different manner, for instance as green dots, or as extra spacing.
br
elements must be used only for line breaks that are actually part of the
content, as in poems or addresses.
The following example is correct usage of the br
element:
<p>P. Sherman<br> 42 Wallaby Way<br> Sydney</p>
br
elements must not be used for separating thematic groups in a paragraph.
The following examples are non-conforming, as they abuse the br
element:
<p><a ...>34 comments.</a><br> <a ...>Add a comment.</a></p>
<p><label>Name: <input name="name"></label><br> <label>Address: <input name="address"></label></p>
Here are alternatives to the above, which are correct:
<p><a ...>34 comments.</a></p> <p><a ...>Add a comment.</a></p>
<p><label>Name: <input name="name"></label></p> <p><label>Address: <input name="address"></label></p>
If a paragraph consists of nothing but a single br
element, it
represents a placeholder blank line (e.g. as in a template). Such blank lines must not be used for
presentation purposes.
Any content inside br
elements must not be considered part of the surrounding
text.
This element has rendering requirements involving the bidirectional algorithm.
wbr
elementaria-*
attributes
applicable to the allowed roles.HTMLElement
.The wbr
element represents a line break opportunity.
In the following example, someone is quoted as saying something which, for effect, is written
as one long word. However, to ensure that the text can be wrapped in a readable fashion, the
individual words in the quote are separated using a wbr
element.
<p>So then he pointed at the tiger and screamed "there<wbr>is<wbr>no<wbr>way<wbr>you<wbr>are<wbr>ever<wbr>going<wbr>to<wbr>catch<wbr>me"!</p>
Here, especially long lines of code in a program listing have suggested wrapping points given
using wbr
elements.
<pre>... Heading heading = Helm.HeadingFactory(HeadingCoordinates[1], <wbr>HeadingCoordinates[2], <wbr>HeadingCoordinates[3], <wbr>HeadingCoordinates[4]); Course course = Helm.CourseFactory(Heading, <wbr>Maps.MapFactoryFromHeading(heading), <wbr>Speeds.GetMaximumSpeed().ConvertToWarp()); ...</pre>
Any content inside wbr
elements must not be considered part of the surrounding
text.
var wbr = document.createElement("wbr"); wbr.textContent = "This is wrong"; document.body.appendChild(wbr);
This element has rendering requirements involving the bidirectional algorithm.
This section is non-normative.
Element | Purpose | Example |
---|---|---|
a
| Hyperlinks | Visit my <a href="drinks.html">drinks</a> page. |
em
| Stress emphasis | I must say I <em>adore</em> lemonade. |
strong
| Importance | This tea is <strong>very hot</strong>. |
small
| Side comments | These grapes are made into wine. <small>Alcohol is addictive.</small> |
s
| Inaccurate text | Price: <s>£4.50</s> £2.00! |
cite
| Titles of works | The case <cite>Hugo v. Danielle</cite> is relevant here. |
q
| Quotations | The judge said <q>You can drink water from the fish tank</q> but advised against it. |
dfn
| Defining instance | The term <dfn>organic food</dfn> refers to food produced without synthetic chemicals. |
abbr
| Abbreviations | Organic food in Ireland is certified by the <abbr title="Irish Organic Farmers and Growers Association">IOFGA</abbr>. |
ruby , rb , rp , rt , rtc
| Ruby annotations | <ruby> <rb>OJ <rp>(<rtc><rt>Orange Juice</rtc><rp>)</ruby> |
data
| Machine-readable equivalent | Available starting today! <data value="UPC:022014640201">North Coast Organic Apple Cider</data> |
time
| Machine-readable equivalent of date- or time-related data | Available starting on <time datetime="2011-11-12">November 12th</time>! |
code
| Computer code | The <code>fruitdb</code> program can be used for tracking fruit production. |
var
| Variables | If there are <var>n</var> fruit in the bowl, at least <var>n</var>÷2 will be ripe. |
samp
| Computer output | The computer said <samp>Unknown error -3</samp>. |
kbd
| User input | Hit <kbd>F1</kbd> to continue. |
sub
| Subscripts | Water is H<sub>2</sub>O. |
sup
| Superscripts | The Hydrogen in heavy water is usually <sup>2</sup>H. |
i
| Alternative voice | Lemonade consists primarily of <i>Citrus limon</i>. |
b
| Keywords | Take a <b>lemon</b> and squeeze it with a <b>juicer</b>. |
u
| Annotations | The mixture of apple juice and <u class="spelling">eldeflower</u> juice is very pleasant. |
mark
| Highlight | Elderflower cordial, with one <mark>part</mark> cordial to ten <mark>part</mark>s water, stands a<mark>part</mark> from the rest. |
bdi
| Text directionality isolation | The recommended restaurant is <bdi lang="">My Juice Café (At The Beach)</bdi>. |
bdo
| Text directionality formatting | The proposal is to write English, but in reverse order. "Juice" would become "<bdo dir=rtl>Juice</bdo>" |
span
| Other | In French we call it <span lang="fr">sirop de sureau</span>. |
br
| Line break | Simply Orange Juice Company<br>Apopka, FL 32703<br>U.S.A. |
wbr
| Line breaking opportunity | www.simply<wbr>orange<wbr>juice.com |
Links are a conceptual construct, created by a
, area
, and
link
elements, that represent a connection between
two resources, one of which is the current Document
. There are two kinds of links in
HTML:
These are links to resources that are to be used to augment the current document, generally automatically processed by the user agent.
These are links to other resources that are generally exposed to the user by the user agent so that the user can cause the user agent to navigate to those resources, e.g. to visit them in a browser or download them.
For link
elements with an href
attribute and a
rel
attribute, links must be created for the keywords of the
rel
attribute, as defined for those keywords in the link types section.
Similarly, for a
and area
elements with an href
attribute and a rel
attribute, links must be created for the keywords of the
rel
attribute as defined for those keywords in the link types section. Unlike link
elements, however,
a
and area
elements with an href
attribute that either do not have a rel
attribute, or
whose rel
attribute has no keywords that are defined as
specifying hyperlinks, must also create a hyperlink.
This implied hyperlink has no special meaning (it has no link type)
beyond linking the element's node document to the resource given by the element's href
attribute.
A hyperlink can have one or more hyperlink annotations that modify the processing semantics of that hyperlink.
a
and area
elementsThe href
attribute on a
and
area
elements must have a value that is a valid URL potentially surrounded by
spaces.
The href
attribute on a
and
area
elements is not required; when those elements do not have href
attributes they do not create hyperlinks.
The target
attribute, if present, must be
a valid browsing context name or keyword. It gives the name of the browsing
context that will be used. User agents use this name when
following hyperlinks.
When an a
or area
element's activation behaviour is
invoked, the user agent may allow the user to indicate a preference regarding whether the
hyperlink is to be used for navigation or whether the resource it
specifies is to be downloaded.
In the absence of a user preference, the default should be navigation if the element has no
download
attribute, and should be to download the
specified resource if it does.
Whether determined by the user's preferences or via the presence or absence of the attribute, if the decision is to use the hyperlink for navigation then the user agent must follow the hyperlink, and if the decision is to use the hyperlink to download a resource, the user agent must download the hyperlink. These terms are defined in subsequent sections below.
The download
attribute, if present,
indicates that the author intends the hyperlink to be used for downloading a resource. The
attribute may have a value; the value, if any, specifies the default file name that the author
recommends for use in labeling the resource in a local file system. There are no restrictions on
allowed values, but authors are cautioned that most file systems have limitations with regard to
what punctuation is supported in file names, and user agents are likely to adjust file names
accordingly.
The rel
attribute on a
and
area
elements controls what kinds of links the elements create. The attribute's value
must be a set of space-separated tokens. The allowed keywords
and their meanings are defined below.
The rel
attribute has no default value. If the
attribute is omitted or if none of the values in the attribute are recognised by the user agent,
then the document has no particular relationship with the destination resource other than there
being a hyperlink between the two.
The hreflang
attribute on
a
and area
elements that create hyperlinks, if present, gives the language of the linked resource. It is
purely advisory. The value must be a valid BCP 47 language tag. [BCP47]
User agents must not consider this attribute authoritative — upon
fetching the resource, user agents must use only language information associated with the resource
to determine its language, not metadata included in the link to the resource.
The type
attribute, if present, gives the
MIME type of the linked resource. It is purely advisory. The value must be a
valid MIME type. User agents must not consider the type
attribute authoritative — upon fetching the
resource, user agents must not use metadata included in the link to the resource to determine its
type.
a
and area
elements[NoInterfaceObject, Exposed=Window] interface HTMLHyperlinkElementUtils { stringifier attribute USVString href; attribute USVString origin; attribute USVString protocol; attribute USVString username; attribute USVString password; attribute USVString host; attribute USVString hostname; attribute USVString port; attribute USVString pathname; attribute USVString search; attribute USVString hash; };
toString()
href
Returns the hyperlink's URL.
Can be set, to change the URL.
origin
Returns the hyperlink's URL's origin.
protocol
Returns the hyperlink's URL's scheme.
Can be set, to change the URL's scheme.
username
Returns the hyperlink's URL's username.
Can be set, to change the URL's username.
password
Returns the hyperlink's URL's password.
Can be set, to change the URL's password.
host
Returns the hyperlink's URL's host and port (if different from the default port for the scheme).
Can be set, to change the URL's host and port.
hostname
Returns the hyperlink's URL's host.
Can be set, to change the URL's host.
port
Returns the hyperlink's URL's port.
Can be set, to change the URL's port.
pathname
Returns the hyperlink's URL's path.
Can be set, to change the URL's path.
search
Returns the hyperlink's URL's query (includes leading "?
" if
non-empty).
Can be set, to change the URL's query (ignores leading "?
").
hash
Returns the hyperlink's URL's fragment (includes leading "#
" if
non-empty).
Can be set, to change the URL's fragment (ignores leading "#
").
An element implementing the HTMLHyperlinkElementUtils
mixin has an associated url (null or a URL). It is initially null.
An element implementing the HTMLHyperlinkElementUtils
mixin has an associated set the url algorithm, which sets this
element's url to the resulting parsed URL
of resolving this element's href
content attribute value relative to this element. If
resolving was aborted with an error, set this element's url to null.
When elements implementing the HTMLHyperlinkElementUtils
mixin are created, and
whenever those elements have their href
content
attribute set, changed, or removed, the user agent must set the url.
This is only observable for blob:
URLs as parsing them involves the
structured clone algorithm.
An element implementing the HTMLHyperlinkElementUtils
mixin has an associated reinitialise url algorithm, which runs these steps:
If element's url is null or its non-relative flag is set, terminate these steps.
To update href
, set the element's href
content attribute's value to the element's url, serialised.
The href
attribute's getter must run these
steps:
Let url be this element's url.
If url is null and this element has no href
content attribute, return the empty string.
Otherwise, if url is null, return this element's href
content attribute's value.
Return url, serialised.
The href
attribute's setter must set this element's
href
content attribute's value to the given value.
The origin
attribute's getter must run
these steps:
If this element's url is null, return the empty string.
Return the Unicode serialization of this element's url's origin.
It returns the Unicode rather than the ASCII serialisation for
compatibility with MessageEvent
.
The protocol
attribute's getter must
run these steps:
If this element's url is null, return ":
".
The protocol
attribute's setter must run these
steps:
If this element's url is null, terminate these steps.
Basic URL parse the given value, followed by :
", with this element's url as
url and scheme start state as state override.
The username
attribute's getter must
run these steps:
If this element's url is null, return the empty string.
The username
attribute's setter must run these
steps:
Let url be this element's url.
If url or url's host is null, or url's non-relative flag is set, terminate these steps.
Set the username, given url and the given value.
The password
attribute's getter must
run these steps:
Let url be this element's url.
If url or url's password is null, return the empty string.
Return url's password.
The password
attribute's setter must run these
steps:
Let url be this element's url.
If url or url's host is null, or url's non-relative flag is set, terminate these steps.
Set the password, given url and the given value.
The host
attribute's getter must run these
steps:
Let url be this element's url.
If url or url's host is null, return the empty string.
If url's port is null, return url's host, serialised.
Return url's host, serialised, followed by ":
" and url's port, serialised.
The host
attribute's setter must run these steps:
Let url be this element's url.
If url is null or url's non-relative flag is set, terminate these steps.
Basic URL parse the given value, with url as url and host state as state override.
The hostname
attribute's getter must
run these steps:
Let url be this element's url.
If url or url's host is null, return the empty string.
Return url's host, serialised.
The hostname
attribute's setter must run these
steps:
Let url be this element's url.
If url is null or url's non-relative flag is set, terminate these steps.
Basic URL parse the given value, with url as url and hostname state as state override.
The port
attribute's getter must run these
steps:
Let url be this element's url.
If url or url's port is null, return the empty string.
Return url's port, serialised.
The port
attribute's setter must run these steps:
Let url be this element's url.
If url or url's host is null,
url's non-relative flag is set, or url's scheme is "file
", terminate these
steps.
Basic URL parse the given value, with url as url and port state as state override.
The pathname
attribute's getter must
run these steps:
Let url be this element's url.
If url is null, return the empty string.
If url's non-relative flag is set, return the first string in url's path.
Return "/
", followed by the strings in url's path (including empty strings), separated from each other by
"/
".
The pathname
attribute's setter must run these
steps:
Let url be this element's url.
If url is null or url's non-relative flag is set, terminate these steps.
Set url's path to the empty list.
Basic URL parse the given value, with url as url and path start state as state override.
The search
attribute's getter must run
these steps:
Let url be this element's url.
If url is null, or url's query is either null or the empty string, return the empty string.
Return "?
", followed by url's query.
The search
attribute's setter must run these
steps:
Let url be this element's url.
If url is null, terminate these steps.
If the given value is the empty string, set url's query to null.
Otherwise, run these substeps:
Let input be the given value with a single leading "?
"
removed, if any.
Set url's query to the empty string.
Basic URL parse input, with url as url and query state as state override, and this element's node document's document's character encoding as encoding override.
The hash
attribute's getter must run these
steps:
Let url be this element's url.
If url is null, or url's fragment is either null or the empty string, return the empty string.
Return "#
", followed by url's fragment.
The hash
attribute's setter must run these steps:
Let url be this element's url.
If url is null or url's scheme is "javascript
", terminate these
steps.
If the given value is the empty string, set url's fragment to null.
Otherwise, run these substeps:
Let input be the given value with a single leading "#
"
removed, if any.
Set url's fragment to the empty string.
Basic URL parse input, with url as url and fragment state as state override.
When a user follows a hyperlink created by an element subject, the user agent must run the following steps:
Let replace be false.
Let source be the browsing context that contains the
Document
object with which subject in question is
associated.
If the user indicated a specific browsing context when following the hyperlink, or if the user agent is configured to follow hyperlinks by navigating a particular browsing context, then let target be that browsing context. If this is a new top-level browsing context (e.g. when the user followed the hyperlink using "Open in New Tab"), then source must be set as the new browsing context's one permitted sandboxed navigator.
Otherwise, if subject is an a
or area
element
that has a target
attribute, then let target be the browsing context that is chosen by applying the
rules for choosing a browsing context given a browsing context name, using the value of
the target
attribute as the browsing context name. If
these rules result in the creation of a new browsing context, set replace to true.
Otherwise, if target is an a
or area
element
with no target
attribute, but the
Document
contains a base
element with a target
attribute, then let target be the
browsing context that is chosen by applying the rules for choosing a browsing
context given a browsing context name, using the value of the target
attribute of the first such base
element as
the browsing context name. If these rules result in the creation of a new browsing
context, set replace to true.
Otherwise, let target be the browsing context that subject itself is in.
Resolve the URL given by the href
attribute of that element, relative to that
element.
If that is successful, let URL be the resulting absolute URL.
Otherwise, if resolving the URL failed, the user agent may report the error to the user in a user-agent-specific manner, may queue a task to navigate the target browsing context to an error page to report the error, or may ignore the error and do nothing. In any case, the user agent must then abort these steps.
In the case of server-side image maps, append the hyperlink suffix to URL.
Queue a task to navigate the target browsing context to URL. If replace is true, the navigation must be performed with replacement enabled. The source browsing context must be source.
The task source for the tasks mentioned above is the DOM manipulation task source.
In some cases, resources are intended for later use rather than immediate viewing. To indicate
that a resource is intended to be downloaded for use later, rather than immediately used, the
download
attribute can be specified on the
a
or area
element that creates the hyperlink to that
resource.
The attribute can furthermore be given a value, to specify the file name that user agents are
to use when storing the resource in a file system. This value can be overridden by the `Content-Disposition
` HTTP header's filename parameters.
[RFC6266]
In cross-origin situations, the download
attribute has to be combined with the `Content-Disposition
` HTTP header, specifically with the
attachment
disposition type, to avoid the user being warned of possibly
nefarious activity. (This is to protect users from being made to download sensitive personal or
confidential information without their full understanding.)
When a user downloads a hyperlink created by an element, the user agent must run the following steps:
Resolve the URL given by the href
attribute of that element, relative to that
element.
If resolving the URL fails, the user agent may report the error to the user in a user-agent-specific manner, may navigate to an error page to report the error, or may ignore the error and do nothing. In either case, the user agent must abort these steps.
Otherwise, let URL be the resulting absolute URL.
In the case of server-side image maps, append the hyperlink suffix to URL.
Return to whatever algorithm invoked these steps and continue these steps in parallel.
Let request be a new request whose
url is URL,
client is entry settings object,
initiator is "download
",
destination is the empty string, and whose
omit-Origin
-header flag, synchronous flag, and
use-URL-credentials flag are all set.
Handle the result of fetching request as a download.
When a user agent is to handle a resource obtained from a fetch as a download, it should provide the user with a way to save the resource for later use, if a resource is successfully obtained; or otherwise should report any problems downloading the file to the user.
If the user agent needs a file name for a resource being handled as a download, it should select one using the following algorithm.
This algorithm is intended to mitigate security dangers involved in downloading files from untrusted sites, and user agents are strongly urged to follow it.
Let filename be the void value.
If the resource has a `Content-Disposition
`
header, that header specifies the attachment
disposition type, and the
header includes file name information, then let filename have the value
specified by the header, and jump to the step labeled sanitize below. [RFC6266]
Let interface origin be the origin of the
Document
in which the download or
navigate action resulting in the download was initiated, if any.
Let resource origin be the origin of the URL of the
resource being downloaded, unless that URL's scheme
component is data
, in which case let resource origin be
the same as the interface origin, if any.
If there is no interface origin, then let trusted operation be true. Otherwise, let trusted operation be true if resource origin is the same origin as interface origin, and false otherwise.
If trusted operation is true and the resource has a `Content-Disposition
` header and that header includes file
name information, then let filename have the value specified by the header,
and jump to the step labeled sanitize below. [RFC6266]
If the download was not initiated from a hyperlink created by an
a
or area
element, or if the element of the hyperlink from
which it was initiated did not have a download
attribute when the download was initiated, or if there was such an attribute but its value when
the download was initiated was the empty string, then jump to the step labeled no proposed
file name.
Let proposed filename have the value of the download
attribute of the element of the
hyperlink that initiated the download at the time the download was
initiated.
If trusted operation is true, let filename have the value of proposed filename, and jump to the step labeled sanitize below.
If the resource has a `Content-Disposition
`
header and that header specifies the attachment
disposition type, let filename have the value of proposed filename, and jump to the
step labeled sanitize below. [RFC6266]
No proposed file name: If trusted operation is true, or if the user indicated a preference for having the resource in question downloaded, let filename have a value derived from the URL of the resource in a user-agent-defined manner, and jump to the step labeled sanitize below.
Act in a user-agent-defined manner to safeguard the user from a potentially hostile cross-origin download. If the download is not to be aborted, then let filename be set to the user's preferred file name or to a file name selected by the user agent, and jump to the step labeled sanitize below.
If the algorithm reaches this step, then a download was begun from a different origin than
the resource being downloaded, and the origin did not mark the file as suitable for
downloading, and the download was not initiated by the user. This could be because a download
attribute was used to trigger the download, or
because the resource in question is not of a type that the user agent supports.
This could be dangerous, because, for instance, a hostile server could be trying to get a user to unknowingly download private information and then re-upload it to the hostile server, by tricking the user into thinking the data is from the hostile server.
Thus, it is in the user's interests that the user be somehow notified that the resource in question comes from quite a different source, and to prevent confusion, any suggested file name from the potentially hostile interface origin should be ignored.
Sanitize: Optionally, allow the user to influence filename. For example, a user agent could prompt the user for a file name, potentially providing the value of filename as determined above as a default value.
Adjust filename to be suitable for the local file system.
For example, this could involve removing characters that are not legal in file names, or trimming leading and trailing whitespace.
If the platform conventions do not in any way use extensions to determine the types of file on the file system, then return filename as the file name and abort these steps.
Let claimed type be the type given by the resource's Content-Type metadata, if any is known. Let named type be the type given by filename's extension, if any is known. For the purposes of this step, a type is a mapping of a MIME type to an extension.
If named type is consistent with the user's preferences (e.g. because the value of filename was determined by prompting the user), then return filename as the file name and abort these steps.
If claimed type and named type are the same type (i.e. the type given by the resource's Content-Type metadata is consistent with the type given by filename's extension), then return filename as the file name and abort these steps.
If the claimed type is known, then alter filename to add an extension corresponding to claimed type.
Otherwise, if named type is known to be potentially dangerous (e.g. it
will be treated by the platform conventions as a native executable, shell script, HTML
application, or executable-macro-capable document) then optionally alter filename to add a known-safe extension
(e.g. ".txt
").
This last step would make it impossible to download executables, which might not be desirable. As always, implementors are forced to balance security and usability in this matter.
Return filename as the file name.
For the purposes of this algorithm, a file extension
consists of any part of the file name that platform conventions dictate will be used for
identifying the type of the file. For example, many operating systems use the part of the file
name following the last dot (".
") in the file name to determine the type of
the file, and from that the manner in which the file is to be opened or executed.
User agents should ignore any directory or path information provided by the resource itself,
its URL, and any download
attribute, in
deciding where to store the resulting file in the user's file system.
The following table summarizes the link types that are defined by this specification. This table is non-normative; the actual definitions for the link types are given in the next few sections.
In this section, the term referenced document refers to the resource identified by the element representing the link, and the term current document refers to the resource within which the element representing the link finds itself.
To determine which link types apply to a link
, a
, or
area
element, the element's rel
attribute must be split on spaces. The resulting tokens are the link types
that apply to that element.
Except where otherwise specified, a keyword must not be specified more than once per rel
attribute.
Link types are always ASCII case-insensitive, and must be compared as such.
Thus, rel="next"
is the same as rel="NEXT"
.
Link type | Effect on... | Brief description | |
---|---|---|---|
link | a and area | ||
alternate | Hyperlink | Hyperlink | Gives alternate representations of the current document. |
author | Hyperlink | Hyperlink | Gives a link to the author of the current document or article. |
bookmark | not allowed | Hyperlink | Gives the permalink for the nearest ancestor section. |
help | Hyperlink | Hyperlink | Provides a link to context-sensitive help. |
icon | External Resource | not allowed | Imports an icon to represent the current document. |
license | Hyperlink | Hyperlink | Indicates that the main content of the current document is covered by the copyright license described by the referenced document. |
next | Hyperlink | Hyperlink | Indicates that the current document is a part of a series, and that the next document in the series is the referenced document. |
nofollow | not allowed | Annotation | Indicates that the current document's original author or publisher does not endorse the referenced document. |
noreferrer | not allowed | Annotation | Requires that the user agent not send an HTTP `Referer ` (sic) header if the user follows the hyperlink. |
prefetch | External Resource | External Resource | Specifies that the target resource should be preemptively cached. |
prev | Hyperlink | Hyperlink | Indicates that the current document is a part of a series, and that the previous document in the series is the referenced document. |
search | Hyperlink | Hyperlink | Gives a link to a resource that can be used to search through the current document and its related pages. |
stylesheet | External Resource | not allowed | Imports a stylesheet. |
tag | not allowed | Hyperlink | Gives a tag (identified by the given address) that applies to the current document. |
Some of the types described below list synonyms for these values. These are to be handled as specified by user agents, but must not be used in documents.
alternate
"The alternate
keyword may be used with link
,
a
, and area
elements.
The meaning of this keyword depends on the values of the other attributes.
link
element and the rel
attribute also contains the keyword stylesheet
The alternate
keyword modifies the meaning of the stylesheet
keyword in the way described for that keyword. The
alternate
keyword does not create a link of its own.
alternate
keyword is used with the type
attribute set to the value application/rss+xml
or the value application/atom+xml
The keyword creates a hyperlink referencing a syndication feed (though not necessarily syndicating exactly the same content as the current page).
The first link
, a
, or area
element in the document (in
tree order) with the alternate
keyword used with the type
attribute set to the value application/rss+xml
or the value application/atom+xml
must
be treated as the default syndication feed for the purposes of feed autodiscovery.
The following link
element gives the syndication
feed for the current page:
<link rel="alternate" type="application/atom+xml" href="data.xml">
The following extract offers various different syndication feeds:
<p>You can access the planets database using Atom feeds:</p> <ul> <li><a href="recently-visited-planets.xml" rel="alternate" type="application/atom+xml">Recently Visited Planets</a></li> <li><a href="known-bad-planets.xml" rel="alternate" type="application/atom+xml">Known Bad Planets</a></li> <li><a href="unexplored-planets.xml" rel="alternate" type="application/atom+xml">Unexplored Planets</a></li> </ul>
The keyword creates a hyperlink referencing an alternate representation of the current document.
The nature of the referenced document is given by the hreflang
, and type
attributes.
If the alternate
keyword is used with the hreflang
attribute, and that attribute's value differs
from the root element's language, it indicates that the referenced
document is a translation.
If the alternate
keyword is used with the type
attribute, it indicates that the referenced document is
a reformulation of the current document in the specified format.
The hreflang
and type
attributes can be combined when specified with the alternate
keyword.
For example, the following link is a French translation that uses the PDF format:
<link rel=alternate type=application/pdf hreflang=fr href=manual-fr>
This relationship is transitive — that is, if a document links to two other documents
with the link type "alternate
", then, in addition to implying
that those documents are alternative representations of the first document, it is also implying
that those two documents are alternative representations of each other.
author
"The author
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
For a
and area
elements, the author
keyword indicates that the referenced document provides further information about the author of
the nearest article
element ancestor of the element defining the hyperlink, if there
is one, or of the page as a whole, otherwise.
For link
elements, the author
keyword indicates
that the referenced document provides further information about the author for the page as a
whole.
The "referenced document" can be, and often is, a mailto:
URL giving the e-mail address of the author. [MAILTO]
Synonyms: For historical reasons, user agents must also treat
link
, a
, and area
elements that have a rev
attribute with the value "made
" as having the author
keyword specified as a link relationship.
bookmark
"The bookmark
keyword may be used with a
and
area
elements. This keyword creates a hyperlink.
The bookmark
keyword gives a permalink for the nearest
ancestor article
element of the linking element in question, or of the section the linking element is most closely associated with, if
there are no ancestor article
elements.
The following snippet has three permalinks. A user agent could determine which permalink applies to which part of the spec by looking at where the permalinks are given.
... <body> <h1>Example of permalinks</h1> <div id="a"> <h2>First example</h2> <p><a href="a.html" rel="bookmark">This permalink applies to only the content from the first H2 to the second H2</a>. The DIV isn't exactly that section, but it roughly corresponds to it.</p> </div> <h2>Second example</h2> <article id="b"> <p><a href="b.html" rel="bookmark">This permalink applies to the outer ARTICLE element</a> (which could be, e.g., a blog post).</p> <article id="c"> <p><a href="c.html" rel="bookmark">This permalink applies to the inner ARTICLE element</a> (which could be, e.g., a blog comment).</p> </article> </article> </body> ...
help
"The help
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
For a
and area
elements, the help
keyword indicates that the referenced document provides further help information for the parent of
the element defining the hyperlink, and its children.
In the following example, the form control has associated context-sensitive help. The user agent could use this information, for example, displaying the referenced document if the user presses the "Help" or "F1" key.
<p><label> Topic: <input name=topic> <a href="help/topic.html" rel="help">(Help)</a></label></p>
For link
elements, the help
keyword indicates that
the referenced document provides help for the page as a whole.
For a
and area
elements, on some browsers, the help
keyword causes the link to use a different cursor.
icon
"The icon
keyword may be used with link
elements.
This keyword creates an external resource link.
The specified resource is an icon representing the page or site, and should be used by the user agent when representing the page in the user interface.
Icons could be auditory icons, visual icons, or other kinds of icons. If
multiple icons are provided, the user agent must select the most appropriate icon according to the
type
, media
, and sizes
attributes. If there are multiple equally appropriate icons,
user agents must use the last one declared in tree order at the time that the user
agent collected the list of icons. If the user agent tries to use an icon but that icon is
determined, upon closer examination, to in fact be inappropriate (e.g. because it uses an
unsupported format), then the user agent must try the next-most-appropriate icon as determined by
the attributes.
User agents are not required to update icons when the list of icons changes, but are encouraged to do so.
There is no default type for resources given by the icon
keyword.
However, for the purposes of determining the type of the
resource, user agents must expect the resource to be an image.
The sizes
attribute gives the sizes of icons
for visual media. Its value, if present, is merely advisory. User agents may use the value to
decide which icon(s) to use if multiple icons are available.
If specified, the attribute must have a value that is an unordered set of unique
space-separated tokens which are ASCII case-insensitive. Each value must be
either an ASCII case-insensitive match for the string "any
", or a value that consists of two valid non-negative integers that do not have a leading U+0030 DIGIT
ZERO (0) character and that are separated by a single U+0078 LATIN SMALL LETTER X or U+0058 LATIN
CAPITAL LETTER X character.
The keywords represent icon sizes in raw pixels (as opposed to CSS pixels).
An icon that is 50 CSS pixels wide intended for displays with a device pixel density of two device pixels per CSS pixel (2x, 192dpi) would have a width of 100 raw pixels. This feature does not support indicating that a different resource is to be used for small high-resolution icons vs large low-resolution icons (e.g. 50×50 2x vs 100×100 1x).
To parse and process the attribute's value, the user agent must first split the attribute's value on spaces, and must then parse each resulting keyword to determine what it represents.
The any
keyword represents that the
resource contains a scalable icon, e.g. as provided by an SVG image.
Other keywords must be further parsed as follows to determine what they represent:
If the keyword doesn't contain exactly one U+0078 LATIN SMALL LETTER X or U+0058 LATIN CAPITAL LETTER X character, then this keyword doesn't represent anything. Abort these steps for that keyword.
Let width string be the string before the "x
" or
"X
".
Let height string be the string after the "x
" or
"X
".
If either width string or height string start with a U+0030 DIGIT ZERO (0) character or contain any characters other than ASCII digits, then this keyword doesn't represent anything. Abort these steps for that keyword.
Apply the rules for parsing non-negative integers to width string to obtain width.
Apply the rules for parsing non-negative integers to height string to obtain height.
The keyword represents that the resource contains a bitmap icon with a width of width device pixels and a height of height device pixels.
The keywords specified on the sizes
attribute must not
represent icon sizes that are not actually available in the linked resource.
In the absence of a link
with the icon
keyword, for
Document
objects obtained over HTTP or HTTPS, user agents may instead run these
steps in parallel:
Let request be a new request whose
url is the absolute URL obtained by
resolving the URL "/favicon.ico
" against the document's
address, client is the Document
object's Window
object's environment settings object, type is "image
", destination is "subresource
",
synchronous flag is set, credentials
mode is "include
", and whose use-URL-credentials flag
is set.
Let response be the result of fetching request.
Use response's unsafe response as an icon as if it had been
declared using the icon
keyword.
The following snippet shows the top part of an application with several icons.
<!DOCTYPE HTML> <html> <head> <title>lsForums — Inbox</title> <link rel=icon href=favicon.png sizes="16x16" type="image/png"> <link rel=icon href=windows.ico sizes="32x32 48x48" type="image/vnd.microsoft.icon"> <link rel=icon href=mac.icns sizes="128x128 512x512 8192x8192 32768x32768"> <link rel=icon href=iphone.png sizes="57x57" type="image/png"> <link rel=icon href=gnome.svg sizes="any" type="image/svg+xml"> <link rel=stylesheet href=lsforums.css> <script src=lsforums.js></script> <meta name=application-name content="lsForums"> </head> <body> ...
For historical reasons, the icon
keyword may be preceded by the
keyword "shortcut
". If the "shortcut
" keyword is
present, the rel
attribute's entire value must be an
ASCII case-insensitive match for the string "shortcut icon
" (with a single U+0020 SPACE character between the tokens and
no other space characters).
license
"The license
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
The license
keyword indicates that the referenced document
provides the copyright license terms under which the main content of the current document is
provided.
This specification defines the main content of a document and content that
is not deemed to be part of that main content via the main
element.
The distinction should be made clear to the user.
Consider a photo sharing site. A page on that site might describe and show a photograph, and the page might be marked up as follows:
<!DOCTYPE HTML> <html lang="en"> <head> <title>Exampl Pictures: Kissat</title> <link rel="stylesheet" href="/style/default"> </head> <body> <h1>Kissat</h1> <nav> <a href="../">Return to photo index</a> </nav> <main> <figure> <img src="/pix/39627052_fd8dcd98b5.jpg"> <figcaption>Kissat</figcaption> </figure> <p>One of them has six toes!</p> <p><small>This photograph is <a rel="license" href="http://www.opensource.org/licenses/mit-license.php">MIT Licensed</a></small></p> </main> <footer> <a href="/">Home</a> | <a href="../">Photo index</a> <p><small>© copyright 2009 Exampl Pictures. All Rights Reserved.</small></p> </footer> </body> </html>
In this case the license
applies to just the photo (the main content of the document), not
the whole document. In particular not the design of the page
itself, which is covered by the copyright given at the bottom of
the document. This should be made clear in the text referencing the licensing
link and could also be made clearer in the styling
(e.g. making the license link prominently positioned near the
photograph, while having the page copyright in small text at
the foot of the page, or adding a border to the main
element.)
Synonyms: For historical reasons, user agents must also treat the keyword
"copyright
" like the license
keyword.
nofollow
"The nofollow
keyword may be used with a
and
area
elements. This keyword does not create a hyperlink, but annotates any other hyperlinks created by the element (the
implied hyperlink, if no other keywords create one).
The nofollow
keyword indicates that the link is not endorsed
by the original author or publisher of the page, or that the link to the referenced document was
included primarily because of a commercial relationship between people affiliated with the two
pages.
noreferrer
"The noreferrer
keyword may be used with a
and
area
elements. This keyword does not create a hyperlink, but annotates any other hyperlinks created by the element (the
implied hyperlink, if no other keywords create one).
It indicates that no referrer information is to be leaked when following the link.
If a user agent follows a link defined by an a
or area
element that
has the noreferrer
keyword, the user agent must set their
request's referrer to "no-referrer
".
This keyword also causes the opener
attribute to remain null if the hyperlink creates a new browsing context.
prefetch
"The prefetch
keyword may be used with link
,
a
, and area
elements. This keyword creates an external resource link.
The prefetch
keyword indicates that preemptively fetching and
caching the specified resource is likely to be beneficial, as it is highly likely that the user
will require this resource.
There is no default type for resources given by the prefetch
keyword.
search
"The search
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
The search
keyword indicates that the referenced document
provides an interface specifically for searching the document and its related resources.
OpenSearch description documents can be used with link
elements and
the search
link type to enable user agents to autodiscover search
interfaces. [OPENSEARCH]
stylesheet
"The stylesheet
keyword may be used with link
elements. This keyword creates an external resource
link that contributes to the styling processing model.
The specified resource is a resource that describes how to present the document. Exactly how the resource is to be processed depends on the actual type of the resource.
If the alternate
keyword is also specified on the
link
element, then the link is an alternative stylesheet; in this case,
the title
attribute must be specified on the link
element, with a non-empty value.
The default type for resources given by the stylesheet
keyword is text/css
.
The appropriate times to obtain the resource are:
When the external resource link is created on a link
element
that is already in a Document
.
When the external resource link's link
element is inserted into a document.
When the href
attribute of the link
element of an external resource link that is already in a
Document
is changed.
When the crossorigin
attribute of the
link
element of an external resource
link that is already in a Document
is set, changed, or
removed.
When the type
attribute of the link
element of an external resource link that is already in a
Document
is set or changed to a value that does not or no longer matches the
Content-Type metadata of the previous obtained external
resource, if any.
When the type
attribute of the link
element of an external resource link that is already in a
Document
but was previously not obtained due to the type
attribute specifying an unsupported type is set, removed, or
changed.
When the external resource link changes from being an alternative stylesheet to not being one, or vice versa.
Quirk: If the document has been set to quirks mode, has the
same origin as the URL of the external resource,
and the Content-Type metadata of the external resource is not a
supported style sheet type, the user agent must instead assume it to be text/css
.
Once a resource has been obtained, if its Content-Type metadata is text/css
, the user
agent must run these steps:
Let element be the link
element that created the
external resource link.
If element has an associated CSS style sheet, remove the CSS style sheet in question.
If element no longer creates an external resource link that contributes to the styling processing model, or if, since the resource in question was obtained, it has become appropriate to obtain it again (meaning this algorithm is about to be invoked again for a newly obtained resource), then abort these steps.
Create a CSS style sheet with the following properties:
text/css
The resulting absolute URL determined during the obtain algorithm.
This is before any redirects get applied.
element
The media
attribute of element.
This is a reference to the (possibly absent at this time) attribute, rather than a copy of the attribute's current value. The CSSOM specification defines what happens when the attribute is dynamically set, changed, or removed.
The title
attribute of element.
This is similarly a reference to the attribute, rather than a copy of the attribute's current value.
Set if the link is an alternative stylesheet; unset otherwise.
Set if the resource is CORS-same-origin; unset otherwise.
null
Left at its default value.
Left uninitialised.
The CSS environment encoding is the result of running the following steps: [CSSSYNTAX]
If the element has a charset
attribute, get an encoding from that attribute's value. If that
succeeds, return the resulting encoding and abort these steps. [ENCODING]
Otherwise, return the document's character encoding. [DOM]
tag
"The tag
keyword may be used with a
and
area
elements. This keyword creates a hyperlink.
The tag
keyword indicates that the tag that the
referenced document represents applies to the current document.
Since it indicates that the tag applies to the current document, it would be inappropriate to use this keyword in the markup of a tag cloud, which lists the popular tags across a set of pages.
This document is about some gems, and so it is tagged with "https://en.wikipedia.org/wiki/Gemstone
" to unambiguously categorise it as applying
to the "jewel" kind of gems, and not to, say, the towns in the US, the Ruby package format, or
the Swiss locomotive class:
<!DOCTYPE HTML> <html> <head> <title>My Precious</title> </head> <body> <header><h1>My precious</h1> <p>Summer 2012</p></header> <p>Recently I managed to dispose of a red gem that had been bothering me. I now have a much nicer blue sapphire.</p> <p>The red gem had been found in a bauxite stone while I was digging out the office level, but nobody was willing to haul it away. The same red gem stayed there for literally years.</p> <footer> Tags: <a rel=tag href="https://en.wikipedia.org/wiki/Gemstone">Gemstone</a> </footer> </body> </html>
In this document, there are two articles. The "tag
"
link, however, applies to the whole page (and would do so wherever it was placed, including if it
was within the article
elements).
<!DOCTYPE HTML> <html> <head> <title>Gem 4/4</title> </head> <body> <article> <h1>801: Steinbock</h1> <p>The number 801 Gem 4/4 electro-diesel has an ibex and was rebuilt in 2002.</p> </article> <article> <h1>802: Murmeltier</h1> <figure> <img src="https://upload.wikimedia.org/wikipedia/commons/b/b0/Trains_de_la_Bernina_en_hiver_2.jpg" alt="The 802 was red with pantographs and tall vents on the side."> <figcaption>The 802 in the 1980s, above Lago Bianco.</figcaption> </figure> <p>The number 802 Gem 4/4 electro-diesel has a marmot and was rebuilt in 2003.</p> </article> <p class="topic"><a rel=tag href="https://en.wikipedia.org/wiki/Rhaetian_Railway_Gem_4/4">Gem 4/4</a></p> </body> </html>
Some documents form part of a sequence of documents.
A sequence of documents is one where each document can have a previous sibling and a next sibling. A document with no previous sibling is the start of its sequence, a document with no next sibling is the end of its sequence.
A document may be part of multiple sequences.
next
"The next
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
The next
keyword indicates that the document is part of a
sequence, and that the link is leading to the document that is the next logical document in the
sequence.
prev
"The prev
keyword may be used with link
,
a
, and area
elements. This keyword creates a hyperlink.
The prev
keyword indicates that the document is part of a
sequence, and that the link is leading to the document that is the previous logical document in
the sequence.
Synonyms: For historical reasons, user agents must also treat the keyword
"previous
" like the prev
keyword.
Extensions to the predefined set of link types may be registered in the microformats wiki existing-rel-values page. [MFREL]
Anyone is free to edit the microformats wiki existing-rel-values page at any time to add a type. Extension types must be specified with the following information:
The actual value being defined. The value should not be confusingly similar to any other defined value (e.g. differing only in case).
If the value contains a U+003A COLON character (:), it must also be an absolute URL.
link
One of the following:
link
elements.link
element; it creates a
hyperlink.link
element; it creates an external
resource link.a
and area
One of the following:
a
and area
elements.a
and area
elements; it creates a
hyperlink.a
and area
elements; it creates
an external resource link.a
and area
elements; it annotates other hyperlinks
created by the element.A short non-normative description of what the keyword's meaning is.
A link to a more detailed description of the keyword's semantics and requirements. It could be another page on the Wiki, or a link to an external page.
A list of other keyword values that have exactly the same processing requirements. Authors should not use the values defined to be synonyms, they are only intended to allow user agents to support legacy content. Anyone may remove synonyms that are not used in practice; only names that need to be processed as synonyms for compatibility with legacy content are to be registered in this way.
One of the following:
If a keyword is found to be redundant with existing values, it should be removed and listed as a synonym for the existing value.
If a keyword is registered in the "proposed" state for a period of a month or more without being used or specified, then it may be removed from the registry.
If a keyword is added with the "proposed" status and found to be redundant with existing values, it should be removed and listed as a synonym for the existing value. If a keyword is added with the "proposed" status and found to be harmful, then it should be changed to "discontinued" status.
Anyone can change the status at any time, but should only do so in accordance with the definitions above.
Conformance checkers may use the information given on the microformats wiki existing-rel-values page to establish if a value is allowed or not: values defined in this specification or marked as "proposed" or "ratified" must be accepted when used on the elements for which they apply as described in the "Effect on..." field, whereas values marked as "discontinued" or values not containing a U+003A COLON character but not listed in either this specification or on the aforementioned page must be rejected as invalid. The remaining values must be accepted as valid if they are absolute URLs containing US-ASCII characters only and rejected otherwise. Conformance checkers may cache this information (e.g. for performance reasons or to avoid the use of unreliable network connectivity).
Note: Even URL-valued link types are compared ASCII-case-insensitively. Validators might choose to warn about characters U+0041 (LATIN CAPITAL LETTER A) through U+005A (LATIN CAPITAL LETTER Z) (inclusive) in the pre-case-folded form of link types that contain a colon.
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 "proposed" status.
Types defined as extensions in the microformats
wiki existing-rel-values page with the status "proposed" or "ratified" may be used with the
rel
attribute on link
, a
, and area
elements in accordance to the "Effect on..." field. [MFREL]
The ins
and del
elements represent edits to the document.
ins
elementcite
— Link to the source of the quotation or more information about the editdatetime
— Date and (optionally) time of the changearia-*
attributes
applicable to the allowed roles.HTMLModElement
interface.The ins
element represents an addition to the document.
The following represents the addition of a single paragraph:
<aside> <ins> <p> I like fruit. </p> </ins> </aside>
As does the following, because everything in the aside
element here counts as
phrasing content and therefore there is just one paragraph:
<aside> <ins> Apples are <em>tasty</em>. </ins> <ins> So are pears. </ins> </aside>
ins
elements should not cross implied paragraph
boundaries.
The following example represents the addition of two paragraphs, the second of which was
inserted in two parts. The first ins
element in this example thus crosses a
paragraph boundary, which is considered poor form.
<aside> <!-- don't do this --> <ins datetime="2005-03-16 00:00Z"> <p> I like fruit. </p> Apples are <em>tasty</em>. </ins> <ins datetime="2007-12-19 00:00Z"> So are pears. </ins> </aside>
Here is a better way of marking this up. It uses more elements, but none of the elements cross implied paragraph boundaries.
<aside> <ins datetime="2005-03-16 00:00Z"> <p> I like fruit. </p> </ins> <ins datetime="2005-03-16 00:00Z"> Apples are <em>tasty</em>. </ins> <ins datetime="2007-12-19 00:00Z"> So are pears. </ins> </aside>
del
elementcite
— Link to the source of the quotation or more information about the editdatetime
— Date and (optionally) time of the changearia-*
attributes
applicable to the allowed roles.HTMLModElement
interface.The del
element represents a removal from the document.
del
elements should not cross implied paragraph
boundaries.
The following shows a "to do" list where items that have been done are crossed-off with the date and time of their completion.
<h1>To Do</h1> <ul> <li>Empty the dishwasher</li> <li><del datetime="2009-10-11T01:25-07:00">Watch Walter Lewin's lectures</del></li> <li><del datetime="2009-10-10T23:38-07:00">Download more tracks</del></li> <li>Buy a printer</li> </ul>
ins
and del
elementsThe cite
attribute may be used to specify the
address of a document that explains the change. When that document is long, for instance the
minutes of a meeting, authors are encouraged to include a fragment identifier pointing to the
specific part of that document that discusses the change.
If the cite
attribute is present, it must be a valid
URL potentially surrounded by spaces that explains the change. To obtain
the corresponding citation link, the value of the attribute must be resolved relative to the element. User agents may allow users to follow such
citation links, but they are primarily intended for private use (e.g. by server-side scripts
collecting statistics about a site's edits), not for readers.
The datetime
attribute may be used to specify
the time and date of the change.
If present, the datetime
attribute's value must be a
valid date string with optional time.
User agents must parse the datetime
attribute according
to the parse a date or time string algorithm. If that doesn't return a date or a global date and time,
then the modification has no associated timestamp (the value is non-conforming; it is not a
valid date string with optional time). Otherwise, the modification is marked as
having been made at the given date or global date and time. If the given value is a global date and time then user agents should use the associated
time-zone offset information to determine which time zone to present the given datetime in.
This value may be shown to the user, but it is primarily intended for private use.
The ins
and del
elements must implement the
HTMLModElement
interface:
interface HTMLModElement : HTMLElement { attribute DOMString cite; attribute DOMString dateTime; };
The cite
IDL attribute must reflect
the element's cite
content attribute. The dateTime
IDL attribute must reflect the
element's datetime
content attribute.
This section is non-normative.
Since the ins
and del
elements do not affect paragraphing, it is possible, in some cases where paragraphs are implied (without explicit p
elements), for an
ins
or del
element to span both an entire paragraph or other
non-phrasing content elements and part of another paragraph. For example:
<section> <ins> <p> This is a paragraph that was inserted. </p> This is another paragraph whose first sentence was inserted at the same time as the paragraph above. </ins> This is a second sentence, which was there all along. </section>
By only wrapping some paragraphs in p
elements, one can even get the end of one
paragraph, a whole second paragraph, and the start of a third paragraph to be covered by the same
ins
or del
element (though this is very confusing, and not considered
good practice):
<section> This is the first paragraph. <ins>This sentence was inserted. <p>This second paragraph was inserted.</p> This sentence was inserted too.</ins> This is the third paragraph in this example. <!-- (don't do this) --> </section>
However, due to the way implied paragraphs are defined, it is
not possible to mark up the end of one paragraph and the start of the very next one using the same
ins
or del
element. You instead have to use one (or two) p
element(s) and two ins
or del
elements, as for example:
<section> <p>This is the first paragraph. <del>This sentence was deleted.</del></p> <p><del>This sentence was deleted too.</del> That sentence needed a separate <del> element.</p> </section>
Partly because of the confusion described above, authors are strongly encouraged to always mark
up all paragraphs with the p
element, instead of having ins
or
del
elements that cross implied paragraphs
boundaries.
This section is non-normative.
The content models of the ol
and ul
elements do not allow
ins
and del
elements as children. Lists always represent all their
items, including items that would otherwise have been marked as deleted.
To indicate that an item is inserted or deleted, an ins
or del
element can be wrapped around the contents of the li
element. To indicate that an
item has been replaced by another, a single li
element can have one or more
del
elements followed by one or more ins
elements.
In the following example, a list that started empty had items added and removed from it over time. The bits in the example that have been emphasized show the parts that are the "current" state of the list. The list item numbers don't take into account the edits, though.
<h1>Stop-ship bugs</h1> <ol> <li><ins datetime="2008-02-12T15:20Z">Bug 225: Rain detector doesn't work in snow</ins></li> <li><del datetime="2008-03-01T20:22Z"><ins datetime="2008-02-14T12:02Z">Bug 228: Water buffer overflows in April</ins></del></li> <li><ins datetime="2008-02-16T13:50Z">Bug 230: Water heater doesn't use renewable fuels</ins></li> <li><del datetime="2008-02-20T21:15Z"><ins datetime="2008-02-16T14:25Z">Bug 232: Carbon dioxide emissions detected after startup</ins></del></li> </ol>
In the following example, a list that started with just fruit was replaced by a list with just colours.
<h1>List of <del>fruits</del><ins>colours</ins></h1> <ul> <li><del>Lime</del><ins>Green</ins></li> <li><del>Apple</del></li> <li>Orange</li> <li><del>Pear</del></li> <li><ins>Teal</ins></li> <li><del>Lemon</del><ins>Yellow</ins></li> <li>Olive</li> <li><ins>Purple</ins></li> </ul>
This section is non-normative.
The elements that form part of the table model have complicated content model requirements that
do not allow for the ins
and del
elements, so indicating edits to a
table can be difficult.
To indicate that an entire row or an entire column has been added or removed, the entire
contents of each cell in that row or column can be wrapped in ins
or del
elements (respectively).
Here, a table's row has been added:
<table> <thead> <tr> <th> Game name <th> Game publisher <th> Verdict <tbody> <tr> <td> Diablo 2 <td> Blizzard <td> 8/10 <tr> <td> Portal <td> Valve <td> 10/10 <tr> <td> <ins>Portal 2</ins> <td> <ins>Valve</ins> <td> <ins>10/10</ins> </table>
Here, a column has been removed (the time at which it was removed is given also, as is a link to the page explaining why):
<table> <thead> <tr> <th> Game name <th> Game publisher <th> <del cite="/edits/r192" datetime="2011-05-02 14:23Z">Verdict</del> <tbody> <tr> <td> Diablo 2 <td> Blizzard <td> <del cite="/edits/r192" datetime="2011-05-02 14:23Z">8/10</del> <tr> <td> Portal <td> Valve <td> <del cite="/edits/r192" datetime="2011-05-02 14:23Z">10/10</del> <tr> <td> Portal 2 <td> Valve <td> <del cite="/edits/r192" datetime="2011-05-02 14:23Z">10/10</del> </table>
Generally speaking, there is no good way to indicate more complicated edits (e.g. that a cell was removed, moving all subsequent cells up or to the left).
This section is non-normative.
To embed an image in HTML, when there is only a single image resource,
use the img
element and its src
attribute.
<h2>From today's featured article</h2> <img src="/uploads/100-marie-lloyd.jpg" alt="" width="100" height="150"> <p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922) was an English <a href="/wiki/Music_hall">music hall</a> singer, ...
However, there are a number of situations for which the author might wish to use multiple image resources that the user agent can choose from:
Different users might have different environmental characteristics:
The users' physical screen size might be different from one another.
A mobile phone's screen might be 4 inches diagonally, while a laptop's screen might be 14 inches diagonally.
This is only relevant when an image's rendered size depends on the viewport size.
The users' screen pixel density might be different from one another.
A mobile phone's screen might have three times as many physical pixels per inch compared to another mobile phone's screen, regardless of their physical screen size.
The users' zoom level might be different from one another, or might change for a single user over time.
A user might zoom in to a particular image to be able to get a more detailed look.
The zoom level and the screen pixel density (the previous point) can both affect the number of physical screen pixels per CSS pixel. This ratio is usually referred to as device-pixel-ratio.
The users' screen orientation might be different from one another, or might change for a single user over time.
A tablet can be held upright or rotated 90 degrees, so that the screen is either "portrait" or "landscape".
The users' network speed, network latency and bandwidth cost might be different from one another, or might change for a single user over time.
A user might be on a fast, low-latency and constant-cost connection while at work, on a slow, low-latency and constant-cost connection while at home, and on a variable-speed, high-latency and variable-cost connection anywhere else.
Authors might want to show the same image content but with different rendered size depending on, usually, the width of the viewport. This is usually referred to as viewport-based selection.
A Web page might have a banner at the top that always spans the entire viewport width. In this case, the rendered size of the image depends on the physical size of the screen (assuming a maximised browser window).
Another Web page might have images in columns, with a single column for screens with a small physical size, two columns for screens with medium physical size, and three columns for screens with big physical size, with the images varying in rendered size in each case to fill up the viewport. In this case, the rendered size of an image might be bigger in the one-column layout compared to the two-column layout, despite the screen being smaller.
Authors might want to show different image content depending on the rendered size of the image. This is usually referred to as art direction.
When a Web page is viewed on a screen with a large physical size (assuming a maximised browser window), the author might wish to include some less relevant parts surrounding the critical part of the image. When the same Web page is viewed on a screen with a small physical size, the author might wish to show only the critical part of the image.
Authors might want to show the same image content but using different image formats, depending on which image formats the user agent supports. This is usually referred to as image format-based selection.
A Web page might have some images in the JPEG, WebP and JPEG XR image formats, with the latter two having better compression abilities compared to JPEG. Since different user agents can support different image formats, with some formats offering better compression ratios, the author would like to serve the better formats to user agents that support them, while providing JPEG fallback for user agents that don't.
The above situations are not mutually exclusive. For example, it is reasonable to combine different resources for different device-pixel-ratio with different resources for art direction.
While it is possible to solve these problems using scripting, doing so introduces some other problems:
Some user agents aggressively download images specified in the HTML markup, before scripts have had a chance to run, so that Web pages complete loading sooner. If a script changes which image to download, the user agent will potentially start two separate downloads, which can instead cause worse page loading performance.
If the author avoids specifying any image in the HTML markup and instead instantiates a single download from script, that avoids the double download problem above but then no image will be downloaded at all for users with scripting disabled and the aggressive image downloading optimisation will also be disabled.
With this in mind, this specification introduces a number of features to address the above problems in a declarative manner.
The src
and srcset
attributes on the img
element can be used,
using the x
descriptor,
to provide multiple images that only vary in their size
(the smaller image is a scaled-down version of the bigger image).
The x
descriptor is not appropriate when the
rendered size of the image depends on the viewport width (viewport-based selection),
but can be used together with art direction.
<h2>From today's featured article</h2> <img src="/uploads/100-marie-lloyd.jpg" srcset="/uploads/150-marie-lloyd.jpg 1.5x, /uploads/200-marie-lloyd.jpg 2x" alt="" width="100" height="150"> <p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922) was an English <a href="/wiki/Music_hall">music hall</a> singer, ...
The user agent can choose any of the given resources depending on the user's screen's pixel density, zoom level, and possibly other factors such as the user's network conditions.
For backwards compatibility with older user agents that
don't yet understand the srcset
attribute,
one of the URLs is specified in the img
element's src
attribute.
This will result in something useful (though perhaps lower-resolution than the user would like)
being displayed even in older user agents.
For new user agents, the src
attribute participates in the resource selection,
as if it was specified in srcset
with a 1x
descriptor.
The image's rendered size is given in the
width
and height
attributes,
which allows the user agent to allocate space for the image before it is downloaded.
The srcset
and sizes
attributes can be used,
using the w
descriptor,
to provide multiple images that only vary in their size
(the smaller image is a scaled-down version of the bigger image).
In this example, a banner image takes up the entire viewport width (using appropriate CSS).
<h1><img sizes="100vw" srcset="wolf-400.jpg 400w, wolf-800.jpg 800w, wolf-1600.jpg 1600w" src="wolf-400.jpg" alt="The rad wolf"></h1>
The user agent will calculate the effective pixel density of each image
from the specified w
descriptors and the specified rendered size in the sizes
attribute.
It can then choose any of the given resources depending on
the user's screen's pixel density, zoom level, and possibly other factors such as the user's network conditions.
If the user's screen is 320 CSS pixels wide, this is equivalent to specifying
wolf-400.jpg 1.25x, wolf-800.jpg 2.5x, wolf-1600.jpg 5x
.
On the other hand, if the user's screen is 1200 CSS pixels wide,
this is equivalent to specifying
wolf-400.jpg 0.33x, wolf-800.jpg 0.67x, wolf-1600.jpg 1.33x
.
By using the w
descriptors and the sizes
attribute,
the user agent can choose the correct image source to download regardless of how large the user's device is.
For backwards compatibility,
one of the URLs is specified in the img
element's src
attribute.
In new user agents, the src
attribute is ignored
when the srcset
attribute uses w
descriptors.
In this example, the Web page has three layouts depending on the width of the viewport.
The narrow layout has one column of images (the width of each image is about 100%),
the middle layout has two columns of images (the width of each image is about 50%),
and the widest layout has three columns of images, and some page margin (the width of each image is about 33%).
It breaks between these layouts when the viewport is 30em
wide and 50em
wide, respectively.
<img sizes="(max-width: 30em) 100vw, (max-width: 50em) 50vw, calc(33vw - 100px)" srcset="swing-200.jpg 200w, swing-400.jpg 400w, swing-800.jpg 800w, swing-1600.jpg 1600w" src="swing-400.jpg" alt="Kettlebell Swing">
The sizes
attribute sets up the
layout breakpoints at 30em
and 50em
,
and declares the image sizes between these breakpoints to be
100vw
, 50vw
, or calc(33vw - 100px)
.
These sizes do not necessarily have to match up exactly with the actual image width as specified in the CSS.
The user agent will pick a width from the sizes
attribute,
using the first item with a <media-condition> (the part in parentheses) that evaluates to true,
or using the last item (calc(33vw - 100px)
) if they all evaluate to false.
For example, if the viewport width is 29em
,
then (max-width: 30em)
evaluates to true and 100vw
is used,
so the image size, for the purpose of resource selection, is 29em
.
If the viewport width is instead 32em
,
then (max-width: 30em)
evaluates to false,
but (max-width: 50em)
evaluates to true and 50vw
is used,
so the image size, for the purpose of resource selection, is 16em
(half the viewport width).
Notice that the slightly wider viewport results in a smaller image because of the different layout.
The user agent can then calculate the effective pixel density and choose an appropriate resource similarly to the previous example.
The picture
element and the source
element,
together with the media
attribute,
can be used, to provide multiple images that vary the image content
(for instance the smaller image might be a cropped version of the bigger image).
<picture> <source media="(min-width: 45em)" srcset="large.jpg"> <source media="(min-width: 32em)" srcset="med.jpg"> <img src="small.jpg" alt="The president giving an award."> </picture>
The user agent will choose the first source
element
for which the media query in the media
attribute matches,
and then choose an appropriate URL from its srcset
attribute.
The rendered size of the image varies depending on which resource is chosen. To specify dimensions that the user agent can use before having downloaded the image, CSS can be used.
img { width: 300px; height: 300px } @media (min-width: 32em) { img { width: 500px; height:300px } } @media (min-width: 45em) { img { width: 700px; height:400px } }
This example combines art direction- and device-pixel-ratio-based selection. A banner that takes half the viewport is provided in two versions, one for wide screens and one for narrow screens.
<h1> <picture> <source media="(max-width: 500px)" srcset="banner-phone.jpeg, banner-phone-HD.jpeg 2x"> <img src="banner.jpeg" srcset="banner-HD.jpeg 2x" alt="The Breakfast Combo"> </picture> </h1>
The type
attribute
on the source
element can be used,
to provide multiple images in different formats.
<h2>From today's featured article</h2> <picture> <source srcset="/uploads/100-marie-lloyd.webp" type="image/webp"> <source srcset="/uploads/100-marie-lloyd.jxr" type="image/vnd.ms-photo"> <img src="/uploads/100-marie-lloyd.jpg" alt="" width="100" height="150"> </picture> <p><b><a href="/wiki/Marie_Lloyd">Marie Lloyd</a></b> (1870–1922) was an English <a href="/wiki/Music_hall">music hall</a> singer, ...
In this example, the user agent will choose the first source that has
a type
attribute with a supported MIME type.
If the user agent supports WebP images,
the first source
element will be chosen.
If not, but the user agent does support JPEG XR images,
the second source
element will be chosen.
If neither of those formats are supported,
the img
element will be chosen.
This section is non-normative.
CSS and media queries can be used to construct graphical page layouts that adapt dynamically to
the user's environment, in particular to different viewport dimensions and pixel densities. For
content, however, CSS does not help; instead, we have the img
element's srcset
attribute and the picture
element.
This section walks through a sample case showing how to use these features.
Consider a situation where on wide screens (wider than 600 CSS pixels) a 300×150 image
named a-rectangle.png
is to be used, but on smaller screens (600 CSS pixels
and less), a smaller 100×100 image called a-square.png
is to be used.
The markup for this would look like this:
<figure> <picture> <source srcset="a-square.png" media="(max-width: 600px)"> <img src="a-rectangle.png" alt="Barney Frank wears a suit and glasses."> </picture> <figcaption>Barney Frank, 2011</figcaption> </figure>
For details on what to put in the alt
attribute,
see the Requirements for providing text to act as an alternative for images section.
The problem with this is that the user agent does not necessarily know what dimensions to use for the image when the image is loading. To avoid the layout having to be reflowed multiple times as the page is loading, CSS and CSS media queries can be used to provide the dimensions:
<figure> <style scoped> #a { width: 300px; height: 150px; } @media (max-width: 600px) { #a { width: 100px; height: 100px; } } </style> <picture> <source srcset="a-square.png" media="(max-width: 600px)"> <img src="a-rectangle.png" alt="Barney Frank wears a suit and glasses." id="a"> </picture> <figcaption>Barney Frank, 2011</figcaption> </figure>
Alternatively, the width
and height
attributes can be used to provide the width for legacy user
agents, using CSS just for the user agents that support picture
:
<figure> <style scoped media="(max-width: 600px)"> #a { width: 100px; height: 100px; } </style> <picture> <source srcset="a-square.png" media="(max-width: 600px)"> <img src="a-rectangle.png" width="300" height="150" alt="Barney Frank wears a suit and glasses." id="a"> </picture> <figcaption>Barney Frank, 2011</figcaption> </figure>
The img
element is used with the src
attribute, which gives the URL of the image to use for legacy user
agents that do not support the picture
element. This leads
to a question of which image to provide in the src
attribute.
If the author wants the biggest image in legacy user agents, the markup could be as follows:
<picture> <source srcset="pear-mobile.jpeg" media="(max-width: 720px)"> <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)"> <img src="pear-desktop.jpeg" alt="The pear is juicy."> </picture>
However, if legacy mobile user agents are more important, one can list all three images in the
source
elements, overriding the src
attribute entirely.
<picture> <source srcset="pear-mobile.jpeg" media="(max-width: 720px)"> <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)"> <source srcset="pear-desktop.jpeg"> <img src="pear-mobile.jpeg" alt="The pear is juicy."> </picture>
Since at this point the src
attribute is actually being
ignored entirely by picture
-supporting user agents, the src
attribute can default to any image, including one that is neither
the smallest nor biggest:
<picture> <source srcset="pear-mobile.jpeg" media="(max-width: 720px)"> <source srcset="pear-tablet.jpeg" media="(max-width: 1280px)"> <source srcset="pear-desktop.jpeg"> <img src="pear-tablet.jpeg" alt="The pear is juicy."> </picture>
Above the max-width
media feature is used, giving the maximum
(viewport) dimensions that an image is intended for.
It is also possible to use min-width
instead.
<picture> <source srcset="pear-desktop.jpeg" media="(min-width: 1281px)"> <source srcset="pear-tablet.jpeg" media="(min-width: 721px)"> <img src="pear-mobile.jpeg" alt="The pear is juicy."> </picture>
picture
elementsource
elements, followed by one img
element, optionally intermixed with script-supporting elements.interface HTMLPictureElement : HTMLElement {};
The picture
element is a container
which provides multiple sources to its contained img
element
to allow authors to declaratively control or give hints to the user agent about which image resource to use,
based on the screen pixel density, viewport size, image format, and other factors. It represents its children.
The picture
element is somewhat different
from the similar-looking video
and audio
elements.
While all of them contain source
elements,
the source
element's src
attribute has no meaning
when the element is nested within a picture
element,
and the resource selection algorithm is different.
As well, the picture
element itself does not display anything;
it merely provides a context for its contained img
element
that enables it to choose from multiple URLs.
source
element when used with the picture
elementsource
element.picture
element, before the img
element.source
element.srcset
sizes
media
type
partial interface HTMLSourceElement { attribute DOMString srcset; attribute DOMString sizes; attribute DOMString media; };
The authoring requirements in this section only apply if the source
element has
a parent that is a picture
element.
The source
element allows authors to specify multiple alternative
source sets for img
elements.
It does not represent anything on its own.
The srcset
attribute must be present,
and must consist of one or more image candidate strings,
each separated from the next by a U+002C COMMA character (,).
If an image candidate string contains no descriptors
and no space characters after the URL,
the following image candidate string, if there is one,
must begin with one or more space characters.
If the srcset
attribute has any
image candidate strings using a width descriptor,
the sizes
attribute must also be present,
and the value must be a valid source size list.
The media
attributes may also be present.
If present, the value must contain a valid media query list.
The type
attribute may also be present.
If present, the value must be a valid MIME type.
It gives the type of the images in the source set,
to allow the user agent to skip to the next source
element
if it does not support the given type.
If the type
attribute
is not specified, the user agent will not select a different
source
element if it finds that it does not support
the image format after fetching it.
When a source
element has a following sibling
source
element or img
element with a
srcset
attribute specified, it must have
at least one of the following:
A media
attribute specified with a value that,
after stripping leading and trailing whitespace,
is not the empty string and is not an ASCII case-insensitive match for the string "all
".
A type
attribute specified.
The src
attribute must not be present.
The IDL attributes srcset
,
sizes
and
media
must reflect the
respective content attributes of the same name.
img
elementusemap
attribute: Interactive content.alt
— Replacement text for use when images are not availablesrc
— Address of the resourcesrcset
— Images to use in different situations (e.g. high-resolution displays, small monitors, etc)sizes
crossorigin
— How the element handles crossorigin requestsusemap
— Name of image map to useismap
— Whether the image is a server-side image mapwidth
— Horizontal dimensionheight
— Vertical dimensionpresentation
role only, for an
img
element whose alt
attribute's value is empty (alt=""
), otherwise
any role value.aria-*
attributes
applicable to the allowed roles.[NamedConstructor=Image(optional unsigned long width, optional unsigned long height)] interface HTMLImageElement : HTMLElement { attribute DOMString alt; attribute DOMString src; attribute DOMString srcset; attribute DOMString sizes; attribute DOMString? crossOrigin; attribute DOMString useMap; attribute boolean isMap; attribute unsigned long width; attribute unsigned long height; readonly attribute unsigned long naturalWidth; readonly attribute unsigned long naturalHeight; readonly attribute boolean complete; readonly attribute DOMString currentSrc; // also has obsolete members };
An img
element represents an image.
The image given by the src
and srcset
attributes,
and any previous sibling source
elements'
srcset
attributes if the parent is a picture
element,
is the embedded content; the value of
the alt
attribute provides equivalent content for
those who cannot process images or who have image loading disabled (i.e. it is the
img
element's fallback content).
The requirements on the alt
attribute's value are described
in the next section.
The src
attribute must be present, and must contain a
valid non-empty URL potentially surrounded by spaces referencing a non-interactive,
optionally animated, image resource that is neither paged nor scripted.
The srcset
attribute may also be present.
If present, its value must consist of one or more
image candidate strings,
each separated from the next by a U+002C COMMA character (,).
If an image candidate string contains no descriptors
and no space characters after the URL,
the following image candidate string, if there is one,
must begin with one or more space characters.
An image candidate string consists of the following components, in order, with the further restrictions described below this list:
Zero or more space characters.
A valid non-empty URL that does not start or end with a U+002C COMMA character (,), referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.
Zero or more space characters.
Zero or one of the following:
A width descriptor, consisting of: a space character, a valid non-negative integer giving a number greater than zero representing the width descriptor value, and a U+0077 LATIN SMALL LETTER W character.
A pixel density descriptor, consisting of: a space character, a valid floating-point number giving a number greater than zero representing the pixel density descriptor value, and a U+0078 LATIN SMALL LETTER X character.
Zero or more space characters.
There must not be an image candidate string for an element that has the same width descriptor value as another image candidate string's width descriptor value for the same element.
There must not be an image candidate string for an element that
has the same pixel density descriptor value as another
image candidate string's pixel density descriptor value for the same element.
For the purpose of this requirement,
an image candidate string with no descriptors is equivalent to
an image candidate string with a 1x
descriptor.
If a source
element has a sizes
attribute present
or an img
element has a sizes
attribute present,
all image candidate strings for that
element must have the width descriptor specified.
If an image candidate string for a source
or
img
element has the width descriptor specified, all other
image candidate strings for that element must also
have the width descriptor specified.
The specified width in an image candidate string's width descriptor must match the intrinsic width in the resource given by the image candidate string's URL, if it has an intrinsic width.
The requirements above imply that images can be static bitmaps (e.g. PNGs, GIFs, JPEGs), single-page vector documents (single-page PDFs, XML files with an SVG root element), animated bitmaps (APNGs, animated GIFs), animated vector graphics (XML files with an SVG root element that use declarative SMIL animation), and so forth. However, these definitions preclude SVG files with script, multipage PDF files, interactive MNG files, HTML documents, plain text documents, and so forth. [PNG] [GIF] [JPEG] [PDF] [XML] [APNG] [SVG] [MNG]
If the srcset
attribute is present and has any
image candidate strings using a width descriptor,
the sizes
attribute must also be present,
and the value must be a valid source size list.
A valid source size list is a string that matches the following grammar: [CSSVALUES] [MQ]
<source-size-list> = [ <source-size># , ]? <source-size-value> <source-size> = <media-condition> <source-size-value> <source-size-value> = <length>
A <source-size-value> must not be negative.
Percentages are not allowed in a <source-size-value>,
to avoid confusion about what it would be relative to.
The vw
unit can be used for sizes relative to the viewport width.
The img
element must not be used as a layout tool. In particular, img
elements should not be used to display transparent images, as such images rarely convey meaning and
rarely add anything useful to the document.
The crossorigin
attribute is a CORS
settings attribute. Its purpose is to allow images from third-party sites that allow
cross-origin access to be used with canvas
.
An img
element has a current request and a pending request.
The current request is initially set to a new image request.
The pending request is initially set to null.
The current request is usually referred to as the img
element itself.
An image request has a state, current URL and image data.
An image request's state is one of the following:
An image request's current URL is initially the empty string.
An image request's image data is the decoded image data.
When an image request is either in the partially available state or in the completely available state, it is said to be available.
An image request is initially unavailable.
When an img
element is available,
it provides a paint source
whose width is the image's density-corrected intrinsic width (if any),
whose height is the image's density-corrected intrinsic height (if any),
and whose appearance is the intrinsic appearance of the image.
In a browsing context where scripting is disabled, user agents may obtain images immediately or on demand. In a browsing context where scripting is enabled, user agents must obtain images immediately.
A user agent that obtains images immediately must synchronously
update the image data of an img
element,
with the restart animation flag set if so stated,
whenever that element is created or has experienced relevant mutations.
A user agent that obtains images on demand must update the image data of an
img
element whenever it needs the image data (i.e. on demand),
but only if the img
element is in the
unavailable state. When an img
element
has experienced relevant mutations, if the user
agent only obtains images on demand, the img
element must return to the unavailable state.
The relevant mutations for an img
element are as follows:
The element's src
, srcset
, width
, or sizes
attributes are set, changed, or removed.
The element's src
attribute is set to the same value as the previous value.
This must set the restart animation flag for the update the image data algorithm.
The element's crossorigin
attribute's state is changed.
The element is inserted into or
removed from a picture
parent element.
The element's parent is a picture
element and a
source
element is inserted as a previous sibling.
The element's parent is a picture
element and a
source
element that was a previous sibling is removed.
The element's parent is a picture
element and a
source
element that is a previous sibling has its
srcset
,
sizes
,
media
or type
attributes set, changed, or removed.
The element's adopting steps are run.
Each img
element has a last selected source, which must initially be
null.
Each image request has a current pixel density, which must initially be undefined.
When an img
element has a current pixel density that is not 1.0, the
element's image data must be treated as if its resolution, in device pixels per CSS pixels, was
the current pixel density.
The image's density-corrected intrinsic width and height are the intrinsic width and height
after taking into account the current pixel density.
For example, if the current pixel density is 3.125, that means that there are 300 device pixels per CSS inch, and thus if the image data is 300x600, it has intrinsic dimensions of 96 CSS pixels by 192 CSS pixels.
Each Document
object must have a list of available images. Each image
in this list is identified by a tuple consisting of an absolute URL, a CORS
settings attribute mode, and, if the mode is not No
CORS, an origin.
Each image furthermore has an ignore higher-layer caching flag.
User agents may copy entries from one Document
object's list of available images to another at any time (e.g. when the
Document
is created, user agents can add to it all the images that are loaded in
other Document
s), but must not change the keys of entries copied in this way when
doing so, and must unset the ignore higher-layer caching flag for the copied entry.
User agents may also remove images from such lists at any time (e.g. to save
memory).
User agents must remove entries in the list of available images as appropriate
given higher-layer caching semantics for the resource (e.g. the HTTP `Cache-Control
` response header) when the ignore higher-layer caching
flag is unset.
The list of available images is intended to enable synchronous
switching when changing the src
attribute to a URL that has
previously been loaded, and to avoid re-downloading images in the same document even when they
don't allow caching per HTTP. It is not used to avoid re-downloading the same image while the
previous image is still loading.
The user agent can also store the image data separately from the list of available images.
For example, if a resource has the HTTP response header
`Cache-Control: must-revalidate
`, and its ignore higher-layer
caching flag is unset, the user agent would remove it from the list of available
images but could keep the image data separately, and use that if the server responds with a
304 Not Modified
status.
When the user agent is to update the image data of an img
element,
optionally with the restart animations flag set,
it must run the following steps:
If the element's node document is not the active document, then run these substeps:
Continue running this algorithm in parallel.
Wait until the element's node document is the active document.
If another instance of this algorithm for this img
element was started after this instance
(even if it aborted and is no longer running), then abort these steps.
Queue a microtask to continue this algorithm.
If the user agent cannot support images, or its support for images has been disabled, then abort the image request for the current request and the pending request, set current request to the unavailable state, let pending request be null, and abort these steps.
If the element does not have a srcset
attribute specified and
it does not have a parent or it has a parent but it is not a picture
element,
and it has a src
attribute specified and
its value is not the empty string, let selected source be the value of the
element's src
attribute, and selected pixel
density be 1.0. Otherwise, let selected source be null and selected pixel density be undefined.
Let the img
element's last selected source be selected source.
If selected source is not null, run these substeps:
Resolve selected source, relative to the element, and let the result be absolute URL. If that is not successful, then abort these inner set of steps.
Let key be a tuple consisting of the resulting absolute
URL, the img
element's crossorigin
attribute's mode, and, if that mode is not No CORS,
the node document's origin.
If the list of available images contains an entry for key, then
set the ignore higher-layer caching flag for that entry,
abort the image request for the current request and the pending request,
let pending request be null,
let current request be a new image request whose image data is that of the entry
and whose state is set to the completely available state,
update the presentation of the image appropriately,
let the current request's current pixel density be selected pixel density,
queue a task to restart the animation if restart animation is set,
change current request's current URL to absolute URL,
and then fire a simple event named load
at the img
element,
and abort these steps.
Await a stable state, allowing the task that invoked this algorithm to continue. The synchronous section consists of all the remaining steps of this algorithm until the algorithm says the synchronous section has ended. (Steps in synchronous sections are marked with ⌛.)
⌛ If another instance of this algorithm for this img
element was started
after this instance (even if it aborted and is no longer running), then abort these steps.
Only the last instance takes effect, to avoid multiple requests when, for
example, the src
, srcset
,
and crossorigin
attributes are all set in
succession.
⌛ Let selected source and selected pixel density be the URL and pixel density that results from selecting an image source, respectively.
⌛ If selected source is null, run these substeps:
⌛ Set the current request to the broken state, abort the image request for the current request and the pending request, and let pending request be null.
⌛ Queue a task to change the current request's current URL to the empty string,
and then, if the element has a src
attribute
or a srcset
attribute
or a parent that is a picture
element,
fire a simple event named error
at the img
element.
⌛ Abort this algorithm.
⌛ Queue a task to fire a progress event named loadstart
at
the img
element.
⌛ Resolve selected source, relative
to the element, and let the result be absolute URL. If that is not successful, then
abort the image request for the current request and the pending request,
set the current request to the broken state,
let pending request be null,
queue a task to
change the current request's current URL to absolute URL,
fire a simple event named error
at the img
element
and then fire a simple event named loadend
at the img
element,
and abort these steps.
⌛ If the pending request is not null, and absolute URL is the same as the pending request's current URL, then abort these steps.
⌛ If absolute URL is the same as the current request's current URL, and current request is in the partially available state, then abort the image request for the pending request, queue a task to restart the animation if restart animation is set, and abort these steps.
⌛ If the pending request is not null, abort the image request for the pending request.
⌛ Let image request be a new image request whose current URL is absolute URL.
⌛ If current request is in the unavailable state or the broken state, let the current request be image request. Otherwise, let the pending request be image request.
⌛ Let request be the result of creating a potential-CORS request given
absolute URL and the current state of the element's crossorigin
content attribute.
⌛ Set request's client to the
element's node document's Window
object's environment settings
object and type to "image
".
⌛ If the element has a srcset
attribute or a
parent that is a picture
element, set request's initiator to "imageset
".
⌛ Fetch request. Let this instance of the fetching algorithm be associated with image request.
The resource obtained in this fashion, if any, is image request's image data.
It can be either CORS-same-origin or CORS-cross-origin; this affects
the origin of the image itself (e.g. when used on a canvas
).
Fetching the image must delay the load event of the element's node document until the task that is queued by the networking task source once the resource has been fetched (defined below) has been run.
This, unfortunately, can be used to perform a rudimentary port scan of the user's local network (especially in conjunction with scripting, though scripting isn't actually necessary to carry out such an attack). User agents may implement cross-origin access control policies that are stricter than those described above to mitigate this attack, but unfortunately such policies are typically not compatible with existing Web content.
If the resource is CORS-same-origin, each task
that is queued by the networking task source
while the image is being fetched, if image request is the current
request, must fire a progress event named progress
at the img
element.
End the synchronous section, continuing the remaining steps in parallel, but without missing any data from fetching.
As soon as possible, jump to the first applicable entry from the following list:
multipart/x-mixed-replace
The next task that is queued by the networking task source while the image is being fetched must run the following steps:
If image request is the pending request and at least one body part has been completely decoded, abort the image request for the current request, upgrade the pending request to the current request.
Otherwise, if image request is the pending request and the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, abort the image request for the current request, upgrade the pending request to the current request and set the current request's state to broken.
Otherwise, if image request is the current request, it is in the unavailable state, and the user agent is able to determine image request's image's width and height, set the current request's state to partially available.
Otherwise, if image request is the current request, it is in the unavailable state, and the user agent is able to determine that image request's image is corrupted in some fatal way such that the image dimensions cannot be obtained, set the current request's state to broken.
Each task that is queued by the networking task source while the image is being
fetched must update the presentation of the image, but as each new body part comes in, it must
replace the previous image. Once one body part has been completely decoded, the user agent
must set the img
element to the completely
available state and queue a task to fire a simple event named
load
at the img
element.
The progress
and loadend
events are not fired for
multipart/x-mixed-replace
image streams.
The next task that is queued by the networking task source while the image is being fetched must run the following steps:
If the user agent is able to determine image request's image's width and height, and image request is pending request, set image request's state to partially available.
Otherwise, if the user agent is able to determine image request's image's width and height,
and image request is current request,
update the img
element's presentation appropriately
and set image request's state to partially available.
Otherwise, if the user agent is able to determine that image request's image
is corrupted in some fatal way such that the image dimensions cannot be obtained,
and image request is pending request,
abort the image request for the current request and the pending request,
upgrade the pending request to the current request,
set current request to the broken state,
fire a simple event named error
at the img
element,
fire a simple event named loadend
at the img
element,
and abort these steps.
Otherwise, if the user agent is able to determine that image request's image
is corrupted in some fatal way such that the image dimensions cannot be obtained,
and image request is current request,
abort the image request for image request,
fire a simple event named error
at the img
element,
fire a simple event named loadend
at the img
element,
and abort these steps.
That task, and each subsequent task, that is queued by the networking task source while the image is being fetched, if image request is the current request, must update the presentation of the image appropriately (e.g., if the image is a progressive JPEG, each packet can improve the resolution of the image).
Furthermore, the last task that is queued by the networking task source once the resource has been fetched must additionally run these steps:
If image request is the pending request,
abort the image request for the current request,
upgrade the pending request to the current request and
update the img
element's presentation appropriately.
Set image request to the completely available state.
Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set.
Fire a progress event or simple event named load
at the img
element, depending on the resource in image request.
Fire a progress event or simple event named loadend
at the img
element, depending on the resource in image request.
The image data is not in a supported file format; the user agent must set
image request to the broken state,
abort the image request for the current request and the pending request,
upgrade the pending request to the current request if image request is the pending request,
and then queue a task to first fire a simple event named error
at the img
element and then fire a simple
event named loadend
at the img
element.
To abort the image request for an image request image request means to run the following steps:
Forget image request's image data, if any.
Abort any instance of the fetching algorithm for image request, discarding any pending tasks generated by that algorithm.
To upgrade the pending request to the current request for an img
element means to run the following steps:
Let the img
element's current request be the pending request.
Let the img
element's pending request be null.
To fire a progress event or simple event named type at an element e, depending on resource r, means to fire a progress event named type at e if r is CORS-same-origin, and otherwise fire a simple event named type at e.
While a user agent is running the above algorithm for an element x, there
must be a strong reference from the element's node document to the element x,
even if that element is not in its Document
.
When an img
element is in the completely available
state and the user agent can decode the media data without errors, then the
img
element is said to be fully decodable.
Whether the image is fetched successfully or not (e.g. whether the response status was an ok status) must be ignored when determining the image's type and whether it is a valid image.
This allows servers to return images with error responses, and have them displayed.
The user agent should apply the image sniffing rules to determine the type of the image, with the image's associated Content-Type headers giving the official type. If these rules are not applied, then the type of the image must be the type given by the image's associated Content-Type headers.
User agents must not support non-image resources with the img
element (e.g. XML
files whose root element is an HTML element). User agents must not run executable code (e.g.
scripts) embedded in the image resource. User agents must only display the first page of a
multipage resource (e.g. a PDF file). User agents must not allow the resource to act in an
interactive fashion, but should honour any animation in the resource.
This specification does not specify which image types are to be supported.
An img
element is associated with a source set.
A source set is an ordered set of zero or more image sources and a source size.
An image source is a URL, and optionally either a density descriptor, or a width descriptor.
A source size is a <source-size-value>.
When a source size has a unit relative to the viewport,
it must be interpreted relative to the img
element's node document's viewport.
Other units must be interpreted the same as in Media Queries. [MQ]
A source size must not use CSS functions other than the calc()
function.
When asked to select an image source for a given img
element el,
user agents must do the following:
Update the source set for el.
If el's source set is empty, return null as the URL and undefined as the pixel density and abort these steps.
Otherwise, take el's source set and let it be source set.
If an entry b in source set has the same associated density descriptor as an earlier entry a in source set, then remove entry b. Repeat this step until none of the entries in source set have the same associated density descriptor as an earlier entry.
In a user agent-specific manner, choose one image source from source set. Let this be selected source.
Return selected source and its associated pixel density.
When asked to update the source set for a given img
element el,
user agents must do the following:
Set el's source set to an empty source set.
If el has a parent node and that is a picture
element,
let elements be an array containing el's parent node's child elements, retaining relative order.
Otherwise, let elements be array containing only el.
If el has a width
attribute, and parsing
that attribute's value using the rules for parsing dimension values doesn't generate
an error or a percentage value, then let width be the returned integer value.
Otherwise, let width be null.
Iterate through elements, doing the following for each item child:
If child is el:
If child has a srcset
attribute,
parse child's srcset attribute
and let the returned source set be source set.
Otherwise, let source set be an empty source set.
Parse child's sizes attribute with the fallback width width, and let source set's source size be the returned value.
If child has a src
attribute
whose value is not the empty string
and source set does not contain an
image source with a density descriptor value of 1,
and no image source with a width descriptor,
append child's src
attribute value to source set.
Normalise the source densities of source set.
Let el's source set be source set.
Abort this algorithm.
If child is not a source
element,
continue to the next child.
Otherwise, child is a source
element.
If child does not have a srcset
attribute,
continue to the next child.
Parse child's srcset attribute and let the returned source set be source set.
If source set has zero image sources, continue to the next child.
If child has a media
attribute,
and its value does not match the environment,
continue to the next child.
Parse child's sizes attribute with the fallback width width, and let source set's source size be the returned value.
If child has a type
attribute,
and its value is an unknown or unsupported MIME type,
continue to the next child.
Normalise the source densities of source set.
Let el's source set be source set.
Abort this algorithm.
Each img
element independently considers
its previous sibling source
elements
plus the img
element itself
for selecting an image source, ignoring any other (invalid) elements,
including other img
elements in the same picture
element,
or source
elements that are following siblings
of the relevant img
element.
When asked to parse a srcset attribute from an element,
parse the value of the element's srcset
attribute as follows:
Let input be the value passed to this algorithm.
Let position be a pointer into input, initially pointing at the start of the string.
Let candidates be an initially empty source set.
Splitting loop: Collect a sequence of characters that are space characters or U+002C COMMA characters. If any U+002C COMMA characters were collected, that is a parse error.
If position is past the end of input, return candidates and abort these steps.
Collect a sequence of characters that are not space characters, and let that be url.
Let descriptors be a new empty list.
If url ends with a U+002C COMMA character (,), follow these substeps:
Remove all trailing U+002C COMMA characters from url. If this removed more than one character, that is a parse error.
Otherwise, follow these substeps:
Descriptor tokeniser: Skip whitespace
Let current descriptor be the empty string.
Let state be in descriptor.
Let c be the character at position. Do the following depending on the value of state. For the purpose of this step, "EOF" is a special character representing that position is past the end of input.
Do the following, depending on the value of c:
If current descriptor is not empty, append current descriptor to descriptors and let current descriptor be the empty string. Set state to after descriptor.
Advance position to the next character in input. If current descriptor is not empty, append current descriptor to descriptors. Jump to the step labeled descriptor parser.
Append c to current descriptor. Set state to in parens.
If current descriptor is not empty, append current descriptor to descriptors. Jump to the step labeled descriptor parser.
Append c to current descriptor.
Do the following, depending on the value of c:
Append c to current descriptor. Set state to in descriptor.
Append current descriptor to descriptors. Jump to the step labeled descriptor parser.
Append c to current descriptor.
Do the following, depending on the value of c:
Stay in this state.
Jump to the step labeled descriptor parser.
Set state to in descriptor. Set position to the previous character in input.
Advance position to the next character in input. Repeat this substep.
In order to be compatible with future additions, this algorithm supports multiple descriptors and descriptors with parens.
Descriptor parser: Let error be no.
Let width be absent.
Let density be absent.
Let future-compat-h be absent.
For each descriptor in descriptors, run the appropriate set of steps from the following list:
If the user agent does not support the sizes
attribute,
let error be yes.
A conforming user agent will support the sizes
attribute.
However, user agents typically implement and ship features in an incremental manner in practice.
If width and density are not both absent, then let error be yes.
Apply the rules for parsing non-negative integers to the descriptor. If the result is zero, let error be yes. Otherwise, let width be the result.
If width, density and future-compat-h are not all absent, then let error be yes.
Apply the rules for parsing floating-point number values to the descriptor. If the result is less than zero, let error be yes. Otherwise, let density be the result.
If density is zero, the intrinsic dimensions will be infinite. User agents are expected to have limits in how big images can be rendered, which is allowed by the hardware limitations clause.
This is a parse error.
If future-compat-h and density are not both absent, then let error be yes.
Apply the rules for parsing non-negative integers to the descriptor. If the result is zero, let error be yes. Otherwise, let future-compat-h be the result.
Let error be yes.
If future-compat-h is not absent and width is absent, let error be yes.
If error is still no, then append a new image source to candidates whose URL is url, associated with a width width if not absent and a pixel density density if not absent. Otherwise, there is a parse error.
Return to the step labeled splitting loop.
When asked to parse a sizes attribute from an element, with a fallback width
width, parse a comma-separated list of component values from the value of
the element's sizes
attribute (or the empty string, if the attribute is
absent), and let unparsed sizes list be the result. [CSSSYNTAX]
For each unparsed size in unparsed sizes list:
Remove all consecutive <whitespace-token>s from the end of unparsed size. If unparsed size is now empty, that is a parse error; continue to the next iteration of this algorithm.
If the last component value in unparsed size
is a valid non-negative <source-size-value>,
let size be its value
and remove the component value from unparsed size.
Any CSS function other than the calc()
function is invalid.
Otherwise, there is a parse error;
continue to the next iteration of this algorithm.
Remove all consecutive <whitespace-token>s from the end of unparsed size. If unparsed size is now empty, return size and exit this algorithm. If this was not the last item in unparsed sizes list, that is a parse error.
Parse the remaining component values in unparsed size as a <media-condition>. If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue to the next iteration of this algorithm. [MQ]
Return size and exit this algorithm.
If the above algorithm exhausts unparsed sizes list without returning a size value, follow these steps:
If width is not null, return a <length> with the value
width and the unit px
.
Return 100vw
.
A parse error for the algorithms above indicates a non-fatal mismatch between input and requirements. User agents are encouraged to expose parse errors somehow.
While a valid source size list only contains a bare <source-size-value> (without an accompanying <media-condition>) as the last entry in the <source-size-list>, the parsing algorithm technically allows such at any point in the list, and will accept it immediately as the size if the preceding entries in the list weren't used. This is to enable future extensions, and protect against simple author errors such as a final trailing comma.
An image source can have a density descriptor, a width descriptor, or no descriptor at all accompanying its URL. Normalising a source set gives every image source a density descriptor.
When asked to normalise the source densities of a source set source set, the user agent must do the following:
Let source size be source set's source size.
For each image source in source set:
If the image source has a density descriptor, continue to the next image source.
Otherwise, if the image source has a width descriptor,
replace the width descriptor with a density descriptor
with a value of the width descriptor divided by the source size
and a unit of x
.
If the source size is zero, the density would be infinity, which results in the intrinsic dimensions being zero by zero.
Otherwise, give the image source a density descriptor of 1x
.
The user agent may at any time run the following algorithm to update an img
element's image in order to react to changes in the environment. (User agents are not
required to ever run this algorithm; for example, if the user is not looking at the page any
more, the user agent might want to wait until the user has returned to the page before determining
which image to use, in case the environment changes again in the meantime.)
User agents are encouraged to run this algorithm in particular when the user changes the viewport's size
(e.g. by resizing the window or changing the page zoom),
and when an img
element is inserted into a document,
so that the density-corrected intrinsic width and height match the new viewport,
and so that the correct image is chosen when art direction is involved.
Await a stable state. The synchronous section consists of all the remaining steps of this algorithm until the algorithm says the synchronous section has ended. (Steps in synchronous sections are marked with ⌛.)
⌛ If the img
element does not have a
srcset
attribute specified and
it either has no parent or it is not a picture
element,
it is not in a Document
,
has image data whose resource type is multipart/x-mixed-replace
,
or the pending request is not null,
then abort this algorithm.
⌛ Let selected source and selected pixel density be the URL and pixel density that results from selecting an image source, respectively.
⌛ If selected source is null, then abort these steps.
⌛ If selected source and selected pixel density are the same as the element's last selected source and current pixel density, then abort these steps.
⌛ Resolve selected source, relative to the element, and let the result be absolute URL. If that is not successful, abort these steps.
⌛ Let corsAttributeState be the state of the element's crossorigin
content attribute.
⌛ Let origin be the origin of the img
element's node document.
⌛ Let client be the img
element's node
document's Window
object's environment settings object.
⌛ Let key be a tuple consisting of absolute URL, corsAttributeState, and, if corsAttributeState is not No CORS, origin.
⌛ Let image request be a new image request whose current URL is absolute URL
⌛ Let the element's pending request be image request.
End the synchronous section, continuing the remaining steps in parallel.
If the list of available images contains an entry for key, then set image request's image data to that of the entry. Continue to the next step.
Otherwise, run these substeps:
Let request be the result of creating a potential-CORS request given absolute URL and corsAttributeState.
Set request's client to
client, type to "image
", and set request's synchronous flag.
Let response be the result of fetching request.
If response's unsafe response is a network error or
if the image format is unsupported (as determined by applying the image sniffing rules, again as mentioned earlier),
or if the user agent is able to determine that image request's image is corrupted in
some fatal way such that the image dimensions cannot be obtained, or if the resource type is
multipart/x-mixed-replace
, then let pending request be null and abort
these steps.
Otherwise, response's unsafe response is image
request's image data. It can be either
CORS-same-origin or CORS-cross-origin; this affects the
origin of the image itself (e.g., when used on a canvas
).
Queue a task to run the following substeps:
If the img
element has experienced relevant mutations
since this algorithm started, then let pending request be null and abort these steps.
Let the img
element's last selected source be selected source
and the img
element's current pixel density be selected pixel density.
Set image request to the completely available state.
Add the image to the list of available images using the key key, with the ignore higher-layer caching flag set.
Update the img
element's presentation appropriately.
Fire a simple event named load
at the
img
element.
The task source for the tasks queued by algorithms in this section is the DOM manipulation task source.
What an img
element represents depends on the src
attribute and the alt
attribute.
src
attribute is set and the alt
attribute is set to the empty stringThe image is either decorative or supplemental to the rest of the content, redundant with some other information in the document.
If the image is available and the user agent is configured to display that image, then the element represents the element's image data.
Otherwise, the element represents nothing, and may be omitted completely from the rendering. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.
src
attribute is set and the alt
attribute is set to a value that isn't emptyThe image is a key part of the content; the alt
attribute
gives a textual equivalent or replacement for the image.
If the image is available and the user agent is configured to display that image, then the element represents the element's image data.
Otherwise, the element represents the text given by the alt
attribute. User agents may provide the user with a notification
that an image is present but has been omitted from the rendering.
src
attribute is set and the alt
attribute is notThe image might be a key part of the content, and there is no textual equivalent of the image available.
In a conforming document, the absence of the alt
attribute indicates that the image is a key part of the content
but that a textual replacement for the image was not available when the image was generated.
If the image is available and the user agent is configured to display that image, then the element represents the element's image data.
Otherwise, the user agent should display some sort of indicator that there is an image that is not being rendered, and may, if requested by the user, or if so configured, or when required to provide contextual information in response to navigation, provide caption information for the image, derived as follows:
If the image has a title
attribute whose value is not
the empty string, then the value of that attribute is the caption information; abort these
steps.
If the image is a descendant of a figure
element that has a child
figcaption
element, and, ignoring the figcaption
element and its
descendants, the figure
element has no flow content descendants other
than inter-element whitespace and the img
element, then the contents of the first such
figcaption
element are the caption information; abort these steps.
There is no caption information.
src
attribute is not set and either the alt
attribute is set to the empty string or the alt
attribute is not set at allThe element represents nothing.
The element represents the text given by the alt
attribute.
The alt
attribute does not represent advisory information.
User agents must not present the contents of the alt
attribute
in the same way as content of the title
attribute.
User agents may always provide the user with the option to display any image, or to prevent any image from being displayed. User agents may also apply heuristics to help the user make use of the image when the user is unable to see it, e.g. due to a visual disability or because they are using a text terminal with no graphics capabilities. Such heuristics could include, for instance, optical character recognition (OCR) of text found within the image.
While user agents are encouraged to repair cases of missing alt
attributes, authors must not rely on such behaviour. Requirements for providing text to act as an alternative for images are described
in detail below.
The contents of img
elements, if any, are ignored for the purposes of
rendering.
The usemap
attribute,
if present, can indicate that the image has an associated
image map.
The ismap
attribute, when used on an element that is a descendant of an
a
element with an href
attribute, indicates by its
presence that the element provides access to a server-side image
map. This affects how events are handled on the corresponding
a
element.
The ismap
attribute is a
boolean attribute. The attribute must not be specified
on an element that does not have an ancestor a
element
with an href
attribute.
The usemap
and
ismap
attributes
can result in confusing behaviour when used together with
source
elements with the
media
attribute specified
in a picture
element.
The img
element supports dimension
attributes.
The alt
, src
, srcset
and sizes
IDL attributes must reflect the
respective content attributes of the same name.
The crossOrigin
IDL attribute must
reflect the crossorigin
content attribute.
The useMap
IDL attribute must
reflect the usemap
content attribute.
The isMap
IDL attribute must reflect
the ismap
content attribute.
width
[ = value ]height
[ = value ]These attributes return the actual rendered dimensions of the image, or zero if the dimensions are not known.
They can be set, to change the corresponding content attributes.
naturalWidth
naturalHeight
These attributes return the intrinsic dimensions of the image, or zero if the dimensions are not known.
complete
Returns true if the image has been completely downloaded or if no image is specified; otherwise, returns false.
currentSrc
Returns the image's absolute URL.
Image
( [ width [, height ] ] )Returns a new img
element, with the width
and height
attributes set to the values
passed in the relevant arguments, if applicable.
The IDL attributes width
and height
must return the rendered width and height of the
image, in CSS pixels, if the image is being rendered, and is being rendered to a
visual medium; or else the density-corrected intrinsic width and height
of the image, in CSS pixels, if the image has intrinsic dimensions and is
available but not being rendered to a visual medium; or else 0, if
the image is not available or does not have
intrinsic dimensions. [CSS]
On setting, they must act as if they reflected the respective content attributes of the same name.
The IDL attributes naturalWidth
and
naturalHeight
must return
the density-corrected intrinsic width and height
of the image, in CSS pixels, if the image has intrinsic dimensions and is
available, or else 0. [CSS]
The IDL attribute complete
must return true if
any of the following conditions is true:
src
attribute and the srcset
attribute are omitted.
srcset
attribute is omitted and the src
attribute's value is the empty string.
img
element is completely available.
img
element is broken.
Otherwise, the attribute must return false.
The value of complete
can thus change while
a script is executing.
The currentSrc
IDL attribute
must return the img
element's current request's current URL.
A constructor is provided for creating HTMLImageElement
objects (in addition to
the factory methods from DOM such as createElement()
): Image(width, height)
.
When invoked as a constructor, this must return a new HTMLImageElement
object (a new
img
element). If the width argument is present, the new object's
width
content attribute must be set to width. If the height argument is also present, the new object's
height
content attribute must be set to height.
The element's node document must be the active document of the
browsing context of the Window
object on which the interface object of
the invoked constructor is found.
A single image can have different appropriate alternative text depending on the context.
In each of the following cases, the same image is used, yet the alt
text is different each time. The image is the coat of arms of the
Carouge municipality in the canton Geneva in Switzerland.
Here it is used as a supplementary icon:
<p>I lived in <img src="carouge.svg" alt=""> Carouge.</p>
Here it is used as an icon representing the town:
<p>Home town: <img src="carouge.svg" alt="Carouge"></p>
Here it is used as part of a text on the town:
<p>Carouge has a coat of arms.</p> <p><img src="carouge.svg" alt="The coat of arms depicts a lion, sitting in front of a tree."></p> <p>It is used as decoration all over the town.</p>
Here it is used as a way to support a similar text where the description is given as well as, instead of as an alternative to, the image:
<p>Carouge has a coat of arms.</p> <p><img src="carouge.svg" alt=""></p> <p>The coat of arms depicts a lion, sitting in front of a tree. It is used as decoration all over the town.</p>
Here it is used as part of a story:
<p>He picked up the folder and a piece of paper fell out.</p> <p><img src="carouge.svg" alt="Shaped like a shield, the paper had a red background, a green tree, and a yellow lion with its tongue hanging out and whose tail was shaped like an S."></p> <p>He stared at the folder. S! The answer he had been looking for all this time was simply the letter S! How had he not seen that before? It all came together now. The phone call where Hector had referred to a lion's tail, the time Marco had stuck his tongue out...</p>
Here it is not known at the time of publication what the image will be, only that it will be a
coat of arms of some kind, and thus no replacement text can be provided, and instead only a brief
caption for the image is provided, in the title
attribute:
<p>The last user to have uploaded a coat of arms uploaded this one:</p> <p><img src="last-uploaded-coat-of-arms.cgi" title="User-uploaded coat of arms."></p>
Ideally, the author would find a way to provide real replacement text even in this case, e.g. by asking the previous user. Not providing replacement text makes the document more difficult to use for people who are unable to view images, e.g. blind users, or users or very low-bandwidth connections or who pay by the byte, or users who are forced to use a text-only Web browser.
Here are some more examples showing the same picture used in different contexts, with different appropriate alternate texts each time.
<article> <h1>My cats</h1> <h2>Fluffy</h2> <p>Fluffy is my favourite.</p> <img src="fluffy.jpg" alt="She likes playing with a ball of yarn."> <p>She's just too cute.</p> <h2>Miles</h2> <p>My other cat, Miles just eats and sleeps.</p> </article>
<article> <h1>Photography</h1> <h2>Shooting moving targets indoors</h2> <p>The trick here is to know how to anticipate; to know at what speed and what distance the subject will pass by.</p> <img src="fluffy.jpg" alt="A cat flying by, chasing a ball of yarn, can be photographed quite nicely using this technique."> <h2>Nature by night</h2> <p>To achieve this, you'll need either an extremely sensitive film, or immense flash lights.</p> </article>
<article> <h1>About me</h1> <h2>My pets</h2> <p>I've got a cat named Fluffy and a dog named Miles.</p> <img src="fluffy.jpg" alt="Fluffy, my cat, tends to keep itself busy."> <p>My dog Miles and I like go on long walks together.</p> <h2>music</h2> <p>After our walks, having emptied my mind, I like listening to Bach.</p> </article>
<article> <h1>Fluffy and the Yarn</h1> <p>Fluffy was a cat who liked to play with yarn. He also liked to jump.</p> <aside><img src="fluffy.jpg" alt="" title="Fluffy"></aside> <p>He would play in the morning, he would play in the evening.</p> </article>
Text alternatives, [WCAG] are a primary way of making visual information accessible, because they can be rendered through any sensory modality (for example, visual, auditory or tactile) to match the needs of the user. Providing text alternatives allows the information to be rendered in a variety of ways by a variety of user agents. For example, a person who cannot see a picture can have the text alternative read aloud using synthesized speech.
The alt
attribute on images is a very important accessibility attribute.
Authoring useful alt
attribute content requires the author to carefully consider the context in
which the image appears and the function that image may have in that context. The guidance included
here addresses the most common ways authors use images. Additional guidance and techniques are available in Resources on Alternative Text for Images.
Except where otherwise specified, the alt
attribute must be specified and its value must not be empty;
the value must be an appropriate functional replacement for the image. The specific requirements for the alt
attribute content
depend on the image's function in the page, as described in the following sections.
To determine an appropriate text alternative it is important to think about why an image is being included in a page. What is its purpose? Thinking like this will help you to understand what is important about the image for the intended audience. Every image has a reason for being on a page, because it provides useful information, performs a function, labels an interactive element, enhances aesthetics or is purely decorative. Therefore, knowing what the image is for, makes writing an appropriate text alternative easier.
When an a
element that is a hyperlink, or a button
element, has no text content
but contains one or more images, include text in the alt
attribute(s) that together convey the purpose of the link or button.
In this example, a portion of an editor interface is displayed. Each button has an icon representing an action a user can take on content they are editing. For users who cannot view the images, the action names are included within the alt
attributes of the images:
<ul> <li><button><img src="b.png" alt="Bold"></button></li> <li><button><img src="i.png" alt="Italics"></button></li> <li><button><img src="strike.png" alt="Strike through"></button></li> <li><button><img src="blist.png" alt="Bulleted list"></button></li> <li><button><img src="nlist.png" alt="Numbered list"></button></li> </ul>
In this example, a link contains a logo. The link points to the W3C web site from an external site. The text alternative is a brief description of the link target.
<a href="http://w3.org"> <img src="images/w3c_home.png" width="72" height="48" alt="W3C web site"> </a>
This example is the same as the previous example, except that the link is on the W3C web site. The text alternative is a brief description of the link target.
<a href="http://w3.org"> <img src="images/w3c_home.png" width="72" height="48" alt="W3C home"> </a>
Depending on the context in which an image of a logo is used it could be appropriate to provide an indication, as part of the text alternative, that the image is a logo. Refer to section 4.7.1.1.19 Logos, insignia, flags, or emblems.
In this example, a link contains a print preview icon. The link points to a version of the page with a print stylesheet applied. The text alternative is a brief description of the link target.
<a href="preview.html"> <img src="images/preview.png" width="32" height="30" alt="Print preview."> </a>
In this example, a button contains a search icon. The button submits a search form. The text alternative is a brief description of what the button does.
<button> <img src="images/search.png" width="74" height="29" alt="Search"> </button>
In this example, a company logo for the PIP Corporation has been split into the following two images,
the first containing the word PIP and the second with the abbreviated word CO. The images are the
sole content of a link to the PIPCO home page. In this case a brief description of the link target is provided.
As the images are presented to the user as a single entity the text alternative PIP CO home is in the
alt
attribute of the first image.
<a href="pipco-home.html"> <img src="pip.gif" alt="PIP CO home"><img src="co.gif" alt=""> </a>
Users can benefit when content is presented in graphical form, for example as a flowchart, a diagram, a graph, or a map showing directions. Users also benefit when content presented in a graphical form is also provided in a textual format, these users include those who are unable to view the image (e.g. because they have a very slow connection, or because they are using a text-only browser, or because they are listening to the page being read out by a hands-free automobile voice Web browser, or because they have a visual impairment and use an assistive technology to render the text to speech).
In the following example we have an image of a pie chart, with text in the alt
attribute
representing the data shown in the pie chart:
<img src="piechart.gif" alt="Pie chart: Browser Share - Internet Explorer 25%, Firefox 40%, Chrome 25%, Safari 6% and Opera 4%.">
In the case where an image repeats the previous paragraph in graphical form. The alt
attribute content labels the image.
<p>According to a recent study Firefox has a 40% browser share, Internet Explorer has 25%, Chrome has 25%, Safari has 6% and Opera has 4%.</p> <p><img src="piechart.gif" alt="Pie chart representing the data in the previous paragraph."></p>
It can be seen that when the image is not available, for example because the src
attribute value is incorrect, the text alternative provides the user with a brief description of the image content:
In cases where the text alternative is lengthy, more than a sentence or two, or would benefit from
the use of structured markup, provide a brief description or label using the alt
attribute, and an associated text alternative.
Here's an example of a flowchart image, with a short text alternative
included in the alt
attribute, in this case the text alternative is a description of the link target
as the image is the sole content of a link. The link points to a description, within the same document, of the
process represented in the flowchart.
<a href="#desc"><img src="flowchart.gif" alt="Flowchart: Dealing with a broken lamp."></a> ... ... <div id="desc"> <h2>Dealing with a broken lamp</h2> <ol> <li>Check if it's plugged in, if not, plug it in.</li> <li>If it still doesn't work; check if the bulb is burned out. If it is, replace the bulb.</li> <li>If it still doesn't work; buy a new lamp.</li> </ol> </div>
In this example, there is an image of a chart. It would be inappropriate to provide the information depicted in
the chart as a plain text alternative in an alt
attribute as the information is a data set. Instead a
structured text alternative is provided below the image in the form of a data table using the data that is represented
in the chart image.
Indications of the highest and lowest rainfall for each season have been included in the table, so trends easily identified in the chart are also available in the data table.
United Kingdom | Japan | Australia | |
---|---|---|---|
Spring | 5.3 (highest) | 2.4 | 2 (lowest) |
Summer | 4.5 (highest) | 3.4 | 2 (lowest) |
Autumn | 3.5 (highest) | 1.8 | 1.5 (lowest) |
Winter | 1.5 (highest) | 1.2 | 1 (lowest) |
<figure> <figcaption>Rainfall Data</figcaption> <img src="rainchart.gif" alt="Bar chart: Average rainfall in millimetres by Country and Season."> <table> <caption>Rainfall in millimetres by Country and Season.</caption> <tr><td><th scope="col">UK <th scope="col">Japan<th scope="col">Australia</tr> <tr><th scope="row">Spring <td>5.5 (highest)<td>2.4 <td>2 (lowest)</tr> <tr><th scope="row">Summer <td>4.5 (highest)<td>3.4<td>2 (lowest)</tr> <tr><th scope="row">Autumn <td>3.5 (highest) <td>1.8 <td>1.5 (lowest)</tr> <tr><th scope="row">Winter <td>1.5 (highest) <td>1.2 <td>1 lowest</tr> </table> </figure>
The figure
element is used to group the Bar Chart image and data table.
The figcaption
element provides a caption for the grouped content.
For any of the examples in this section the details
and summary
elements could be used so that the text descriptions for the images are only displayed on demand:
<figure> <img src="flowchart.gif" alt="Flowchart: Dealing with a broken lamp."> <details> <summary>Dealing with a broken lamp</summary> <ol> <li>Check if it's plugged in, if not, plug it in.</li> <li>If it still doesn't work; check if the bulb is burned out. If it is, replace the bulb.</li> <li>If it still doesn't work; buy a new lamp.</li> </ol> </details> </figure>
The details
and summary
elements are not currently well supported by browsers, until such times they are supported, if used, you will need to use scripting to provide the functionality. There are a number of scripted Polyfills and scripted custom controls avail