Edition for Web Developers — Last Updated 17 December 2024
html
elementSupport in all current engines.
head
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.HTMLHtmlElement
.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 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
elementSupport in all current engines.
html
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 ASCII whitespace or a
comment.HTMLHeadElement
.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 lang = en >
< head >
< title > A document with a short head</ title >
</ head >
< body >
...
Here is an example of a longer one:
<!DOCTYPE HTML>
< HTML LANG = "EN" >
< HEAD >
< META CHARSET = "UTF-8" >
< BASE HREF = "https://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 email when HTML
is used as an email authoring format, the title
element can be omitted.
title
elementSupport in all current engines.
head
element containing no other title
elements.HTMLTitleElement
.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.
title.text [ = value ]
Returns the child text content of the element.
Can be set, to replace the element's children with the given value.
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.
base
elementSupport in all current engines.
head
element containing no other base
elements.href
— Document base URL
target
— Default navigable for hyperlink navigation and form submission
HTMLBaseElement
.The base
element allows authors to specify the document base URL for
the purposes of parsing URLs, and the name of the default
navigable 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.
The target
attribute,
if specified, must contain a valid navigable target name or keyword, which specifies
which navigable 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.
In this example, a base
element is used to set the document base
URL:
<!DOCTYPE html>
< html lang = "en" >
< head >
< title > This is an example for the < base> element</ title >
< base href = "https://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 "https://www.example.com/news/archives.html
".
link
elementSupport in all current engines.
noscript
element that is a child of a head
element.href
— Address of the hyperlink
crossorigin
— How the element handles crossorigin requests
rel
— Relationship between the document containing the hyperlink and the destination resource
media
— Applicable media
integrity
— Integrity metadata used in Subresource Integrity checks [SRI]
hreflang
— Language of the linked resource
type
— Hint for the type of the referenced resource
referrerpolicy
— Referrer policy for fetches initiated by the element
sizes
— Sizes of the icons (for rel
="icon
")
imagesrcset
— Images to use in different situations, e.g., high-resolution displays, small monitors, etc. (for rel
="preload
")
imagesizes
— Image sizes for different page layouts (for rel
="preload
")
as
— Potential destination for a preload request (for rel
="preload
" and rel
="modulepreload
")
blocking
— Whether the element is potentially render-blocking
color
— Color to use when customizing a site's icon (for rel
="mask-icon
")
disabled
— Whether the link is disabled
fetchpriority
— Sets the priority for fetches initiated by the element
title
attribute has special semantics on this element: Title of the link; CSS style sheet set name
HTMLLinkElement
.The link
element allows authors to link their document to other resources.
The address of the link(s) is given by the href
attribute. If the href
attribute is present, then its value must be a valid
non-empty URL potentially surrounded by spaces. One or both of the href
or imagesrcset
attributes must be present.
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 unordered set of unique space-separated tokens. The allowed keywords and their meanings are defined in a later section.
A link
element must have either a rel
attribute or an itemprop
attribute, but not both.
If a link
element has an itemprop
attribute,
or has a rel
attribute that contains only keywords that are
body-ok, then the element is said to be allowed in the body. This means
that the element can be used where phrasing content is expected.
If the rel
attribute is used, the element can
only sometimes be used in the body
of the page. 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.
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.
Hyperlinks created with the link
element and its
rel
attribute apply to the whole document. 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.
Unlike those created by a
and area
elements, hyperlinks created by link
elements are not displayed as
part of the document by default, in user agents that support the suggested
default rendering. And even if they are force-displayed using CSS, they have no
activation behavior. Instead, they primarily provide semantic information which might
be used by the page or by other software that consumes the page's contents. Additionally, the user
agent can provide
its own UI for following such hyperlinks.
The exact behavior for links to external resources depends on the exact relationship, as defined for the relevant link type.
The crossorigin
attribute is a CORS settings attribute. It is intended for use with external resource links.
The media
attribute
says which media the resource applies to. The value must be a valid media query
list.
Support in all current engines.
The integrity
attribute represents the integrity
metadata for requests which this element is responsible for. The value is text. The
attribute must only be specified on link
elements that have a rel
attribute that contains the stylesheet
, preload
, or modulepreload
keyword. [SRI]
The hreflang
attribute on the link
element has the same semantics as the hreflang
attribute on the a
element.
The type
attribute
gives the MIME type of the linked resource. It is purely advisory. The value must be
a valid MIME type string.
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.
The referrerpolicy
attribute is a referrer policy
attribute. It is intended for use with external
resource links, where it helps set the referrer policy used when fetching and processing the linked resource.
[REFERRERPOLICY]
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 that are in a document tree, for which the title
attribute defines CSS
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 imagesrcset
attribute may be present, and is a srcset attribute.
The imagesrcset
and href
attributes (if width
descriptors are not used) together contribute the image
sources to the source set.
If the imagesrcset
attribute is present and has any
image candidate strings using a width
descriptor, the imagesizes
attribute must also be present, and is a
sizes attribute. The imagesizes
attribute
contributes the source size to the source set.
The imagesrcset
and imagesizes
attributes must only be specified on
link
elements that have both a rel
attribute that
specifies the preload
keyword, as well as an as
attribute in the "image
" state.
These attributes allow preloading the appropriate resource that is later used by an
img
element that has the corresponding values for its srcset
and sizes
attributes:
< link rel = "preload" as = "image"
imagesrcset = "wolf_400px.jpg 400w, wolf_800px.jpg 800w, wolf_1600px.jpg 1600w"
imagesizes = "50vw" >
<!-- ... later, or perhaps inserted dynamically ... -->
< img src = "wolf.jpg" alt = "A rad wolf"
srcset = "wolf_400px.jpg 400w, wolf_800px.jpg 800w, wolf_1600px.jpg 1600w"
sizes = "50vw" >
Note how we omit the href
attribute, as it would only
be relevant for browsers that do not support imagesrcset
, and in those cases it would likely cause the
incorrect image to be preloaded.
The imagesrcset
attribute can be combined with the
media
attribute to preload the appropriate resource
selected from a picture
element's sources, for art direction:
< link rel = "preload" as = "image"
imagesrcset = "dog-cropped-1x.jpg, dog-cropped-2x.jpg 2x"
media = "(max-width: 800px)" >
< link rel = "preload" as = "image"
imagesrcset = "dog-wide-1x.jpg, dog-wide-2x.jpg 2x"
media = "(min-width: 801px)" >
<!-- ... later, or perhaps inserted dynamically ... -->
< picture >
< source srcset = "dog-cropped-1x.jpg, dog-cropped-2x.jpg 2x"
media = "(max-width: 800px)" >
< img src = "dog-wide-1x.jpg" srcset = "dog-wide-2x.jpg 2x"
alt = "An awesome dog" >
</ picture >
The sizes
attribute
gives the sizes of icons for visual media. Its value, if present, is merely advisory. 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 attribute must only be specified on link
elements
that have a rel
attribute that specifies the icon
keyword or the apple-touch-icon
keyword.
The apple-touch-icon
keyword is a registered extension to the predefined set of link types, but user
agents are not required to support it in any way.
The as
attribute
specifies the potential destination for a
preload request for the resource given by the href
attribute.
It is an enumerated attribute. Each potential destination is a keyword for this
attribute, mapping to a state of the same name. The attribute must be specified on
link
elements that have a rel
attribute that
contains the preload
keyword. It may be specified on
link
elements that have a rel
attribute that
contains the modulepreload
keyword; in such cases it must
have a value which is a script-like
destination. For other link
elements, it must not be specified.
The attribute does not have a missing value
default or invalid value default, meaning that invalid
or missing values for the attribute map to no state. This is accounted for in the processing
model. For preload
links, both conditions are an error; for
modulepreload
links, a missing value will be treated as
"script
".
The blocking
attribute is a blocking attribute. It is used by link types stylesheet
and expect
, and it must only be specified on link elements
that have a rel
attribute containing those keywords.
The color
attribute is
used with the mask-icon
link type. The attribute must only be specified on
link
elements that have a rel
attribute that
contains the mask-icon
keyword. The value must be a string that matches the
CSS <color> production, defining a suggested color that user agents can use to
customize the display of the icon that the user sees when they pin your site.
This specification does not have any user agent requirements for the color
attribute.
The mask-icon
keyword is a registered extension to the predefined set of link types, but user
agents are not required to support it in any way.
link
elements have an associated explicitly enabled boolean. It is
initially false.
The disabled
attribute is a boolean attribute that is used with the stylesheet
link type. The attribute must only be specified on
link
elements that have a rel
attribute that
contains the stylesheet
keyword.
Whenever the disabled
attribute is removed, set the
link
element's explicitly enabled attribute to true.
Removing the disabled
attribute dynamically, e.g.,
using document.querySelector("link").removeAttribute("disabled")
, will
fetch and apply the style sheet:
< link disabled rel = "alternate stylesheet" href = "css/pooh" >
The fetchpriority
attribute is a fetch
priority attribute that is intended for use with external resource links, where it is used to set the priority used when fetching and processing the linked
resource.
link
elementInteractive user agents may provide users with a means to follow the hyperlinks created using the link
element, somewhere
within their user interface. Such invocations of the follow
the hyperlink algorithm must set the userInvolvement argument to "browser UI
". 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).
meta
elementSupport in all current engines.
itemprop
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 name
http-equiv
— Pragma directive
content
— Value of the element
charset
— Character encoding declaration
media
— Applicable media
HTMLMetaElement
.The meta
element represents various kinds of metadata that cannot be
expressed using the title
, base
, link
, style
,
and script
elements.
The meta
element can represent document-level metadata with the name
attribute, pragma directives with the http-equiv
attribute, and the file's character encoding
declaration when an HTML document is serialized to string form (e.g. for transmission over
the network or for disk storage) with the charset
attribute.
Exactly one of the name
, http-equiv
, 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, its value must
be an ASCII case-insensitive match for the string "utf-8
".
The charset
attribute on the
meta
element has no effect in XML documents, but is allowed in XML documents in order
to facilitate migration to and from XML.
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 media
attribute
says which media the metadata applies to. The value must be a valid media query list.
Unless the name
is theme-color
, the media
attribute has no effect on the processing model and must not be used by authors.
Support in all current engines.
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 where the name
attribute value is an
ASCII case-insensitive match for
application-name
per document.
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 where the name
attribute value
is an ASCII case-insensitive match for
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 lang = "en-GB" >
< 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.
referrer
The value must be a referrer policy, which defines the default referrer
policy for the Document
. [REFERRERPOLICY]
theme-color
The value must be a string that matches the CSS <color> production, defining a suggested color that user agents should use to customize the display of the page or of the surrounding user interface. For example, a browser might color the page's title bar with the specified value, or use it as a color highlight in a tab bar or task switcher.
Within an HTML document, the media
attribute value must
be unique amongst all the meta
elements with their name
attribute value set to an ASCII
case-insensitive match for theme-color
.
This standard itself uses "WHATWG green" as its theme color:
<!DOCTYPE HTML>
< title > HTML Standard</ title >
< meta name = "theme-color" content = "#3c790a" >
...
The media
attribute may be used to describe the context
in which the provided color should be used.
If we only wanted to use "WHATWG green" as this standard's theme color in dark mode,
we could use the prefers-color-scheme
media feature:
<!DOCTYPE HTML>
< title > HTML Standard</ title >
< meta name = "theme-color" content = "#3c790a" media = "(prefers-color-scheme: dark)" >
...
When using the theme color in UI, user agents may adjust it in implementation-specific ways to make it more suitable for the UI in question. For example, if a user agent intends to use the theme color as a background and display white text over it, it might use a darker variant of the theme color in that part of the UI, to ensure adequate contrast.
color-scheme
To aid user agents in rendering the page background with the desired color scheme immediately
(rather than waiting for all CSS in the page to load), a 'color-scheme' value can
be provided in a meta
element.
The value must be a string that matches the syntax for the CSS 'color-scheme' property value. It determines the page's supported color-schemes.
There must not be more than one meta
element with its name
attribute value set to an
ASCII case-insensitive match for color-scheme
per document.
The following declaration indicates that the page is aware of and can handle a color scheme with dark background colors and light foreground colors:
< meta name = "color-scheme" content = "dark" >
Because these rules check successive elements until they find a match, an author can provide multiple such values to handle fallback for legacy user agents. Opposite to how CSS fallback works for properties, the multiple meta elements needs to be arranged with the legacy values after the newer values.
Anyone can create and use their own extensions to the predefined set of metadata names. There is no requirement to register such extensions.
However, a new metadata name should not be created in any of the following cases:
If either the name is a URL, or the value of its accompanying content
attribute is a URL; in those cases,
registering it as an extension to the predefined set of
link types is encouraged (rather than creating a new metadata name).
If the name is for something expected to have processing requirements in user agents; in that case it ought to be standardized.
Also, before creating and using a new metadata name, consulting the WHATWG Wiki MetaExtensions page is encouraged — to avoid choosing a metadata name that's already in use, and to avoid duplicating the purpose of any metadata names that are already in use, and to avoid new standardized names clashing with your chosen name. [WHATWGWIKI]
Anyone is free to edit the WHATWG Wiki MetaExtensions page at any time to add a metadata name. New metadata names can 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 added in the "proposed" state for a period of a month or more without being used or specified, then it may be removed from the WHATWG Wiki MetaExtensions page.
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.
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 with the following keywords and states:
Keyword | State | Brief description |
---|---|---|
content-type
| Encoding declaration | An alternative form of setting the charset .
|
default-style
| Default style | Sets the name of the default CSS style sheet set. |
refresh
| Refresh | Acts as a timed redirect. |
x-ua-compatible
| X-UA-Compatible | In practice, encourages Internet Explorer to more closely follow the specifications. |
content-security-policy
| Content security policy | Enforces a Content Security
Policy on a Document .
|
http-equiv="content-type
"
)
The Encoding declaration state is
just an alternative form of setting the charset
attribute: it is a character encoding declaration.
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:
"text/html;
", optionally followed by any number of ASCII
whitespace, followed by "charset=utf-8
".
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
"
)
Support in one engine only.
This pragma sets the name of the default CSS style sheet set.
http-equiv="refresh
"
)
This pragma acts as a timed redirect.
A Document
object has an associated will declaratively
refresh (a boolean). It is initially false.
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 string
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="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]
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, but must not contain any report-uri
,
frame-ancestors
, or sandbox
directives.
The Content Security Policy given in the content
attribute will be enforced upon the current document. [CSP]
At the time of inserting the meta
element to the document, it is
possible that some resources have already been fetched. For example, images might be stored in
the list of available images prior to dynamically inserting a meta
element with an http-equiv
attribute in the Content security policy state.
Resources that have already been fetched are not guaranteed to be blocked by a Content
Security Policy that's enforced late.
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.
A character encoding declaration is a mechanism by which the character encoding used to store or transmit a document is specified.
The Encoding standard requires use of the UTF-8 character
encoding and requires use of the "utf-8
" encoding label
to identify it. Those requirements necessitate that the document's character encoding
declaration, if it exists, specifies an encoding label using an ASCII
case-insensitive match for "utf-8
". Regardless of whether a
character encoding declaration is present or not, the actual character encoding used to encode the document must be
UTF-8. [ENCODING]
The following restrictions also apply:
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 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 when all characters are in the ASCII range, 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.
Using non-UTF-8 encodings can have unexpected results on form submission and URL encodings, which use the document's character encoding by default.
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
.)
In XML, 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
elementSupport in all current engines.
noscript
element that is a child of a head
element.media
— Applicable media
blocking
— Whether the element is potentially render-blocking
title
attribute has special semantics on this element: CSS style sheet set name
HTMLStyleElement
.The style
element allows authors to embed CSS style sheets 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.
Support in all current engines.
The disabled
getter steps are:
If this does not have an associated CSS style sheet, return false.
If this's associated CSS style sheet's disabled flag is set, return true.
Return false.
The disabled
setter steps are:
If this does not have an associated CSS style sheet, return.
If the given value is true, set this's associated CSS style sheet's disabled flag. Otherwise, unset this's associated CSS style sheet's disabled flag.
Importantly, disabled
attribute assignments only take
effect when the style
element has an associated CSS style sheet:
const style = document. createElement( 'style' );
style. disabled = true ;
style. textContent = 'body { background-color: red; }' ;
document. body. append( style);
console. log( style. disabled); // false
The media
attribute
says which media the styles apply to. The value must be a valid media query list.
The default, if the media
attribute is omitted, is "all
", meaning that by default styles apply to all
media.
The blocking
attribute is a blocking attribute.
Support in one engine only.
The title
attribute on style
elements defines
CSS 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. If the style
element is not in a document tree, then the title
attribute is ignored. [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 child text content of a style
element must be that of a
conformant style sheet.
A style
element is implicitly potentially render-blocking if the
element was created by its node document's parser.
This specification does not specify a style system, but CSS is expected to be supported by most web browsers. [CSS]
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 >