1. 2 共通インフラ
    1. 2.1 用語
      1. 2.1.1 リソース
      2. 2.1.2 XML compatibility
      3. 2.1.3 DOMツリー
      4. 2.1.4 スクリプティング
      5. 2.1.5 プラグイン
      6. 2.1.6 文字エンコーディング
      7. 2.1.7 適合クラス
      8. 2.1.8 依存関係
      9. 2.1.9 拡張性
      10. 2.1.10 Interactions with XPath and XSLT
    2. 2.2 大文字・小文字区別と文字列の比較
    3. 2.3 共通マイクロ構文
      1. 2.3.1 共通パーサー語句
      2. 2.3.2 真偽属性
      3. 2.3.3 キーワードおよび列挙属性
      4. 2.3.4 数字
        1. 2.3.4.1 符号付き整数
        2. 2.3.4.2 非負整数
        3. 2.3.4.3 浮動小数点数
        4. 2.3.4.4 Percentages and lengths
        5. 2.3.4.5 Non-zero percentages and lengths
        6. 2.3.4.6 浮動小数点数のリスト
        7. 2.3.4.7 Lists of dimensions
      5. 2.3.5 日付および時刻
        1. 2.3.5.1 月
        2. 2.3.5.2 日付
        3. 2.3.5.3 年なし日付
        4. 2.3.5.4 時刻
        5. 2.3.5.5 ローカル日付および時刻
        6. 2.3.5.6 タイムゾーン
        7. 2.3.5.7 グローバル日付および時刻
        8. 2.3.5.8 週
        9. 2.3.5.9 継続時間
        10. 2.3.5.10 時刻における曖昧な瞬間
      6. 2.3.6 色
      7. 2.3.7 空白区切りトークン
      8. 2.3.8 コンマ区切りトークン
      9. 2.3.9 参考文献
      10. 2.3.10 メディアクエリー
    4. 2.4 URL
      1. 2.4.1 用語
      2. 2.4.2 Parsing URLs
      3. 2.4.3 Dynamic changes to base URLs
    5. 2.5 リソースを取得する
      1. 2.5.1 用語
      2. 2.5.2 Determining the type of a resource
      3. 2.5.3 Extracting character encodings from meta elements
      4. 2.5.4 CORS設定属性
      5. 2.5.5 リファラーポリシー属性
    6. 2.6 共通DOMインターフェイス
      1. 2.6.1 IDL属性におけるコンテンツ属性の反映
      2. 2.6.2 コレクション
        1. 2.6.2.1 HTMLAllCollectionインターフェイス
        2. 2.6.2.2 HTMLFormControlsCollectionインターフェイス
        3. 2.6.2.3 HTMLOptionsCollectionインターフェイス
      3. 2.6.3 The DOMStringList interface
      4. 2.6.4 Garbage collection
    7. 2.7 Safe passing of structured data
      1. 2.7.1 Cloneable objects
      2. 2.7.2 Transferable objects
      3. 2.7.3 StructuredCloneWithTransfer ( input, transferList, targetRealm )
      4. 2.7.4 StructuredClone ( input, targetRealm [ , memory ] )
      5. 2.7.5 IsTransferable ( O )
      6. 2.7.6 Transfer ( input, targetRealm )
      7. 2.7.7 Performing structured clones from other specifications
      8. 2.7.8 Monkey patch for Blob and FileList objects

2 共通インフラ

This specification depends on the WHATWG Infra standard. [INFRA]

2.1 用語

この仕様は、多くの場合、同じ文脈においてHTMLおよびXMLの属性とIDL属性の両方に言及する。どの属性について言及されているかが不明瞭な場合、HTMLおよびXML属性のコンテンツ属性、およびIDLインターフェイスに定義されるIDL属性として言及される。同様に、用語"プロパティ"は、JavaScriptのオブジェクトプロパティとCSSプロパティの両方に使用される。プロパティが不明瞭の場合、それぞれオブジェクトプロパティおよびCSSプロパティとして修飾される。

Generally, when the specification states that a feature applies to the HTML syntax or the XML syntax, it also includes the other. When a feature specifically only applies to one of the two languages, it is called out by explicitly stating that it does not apply to the other format, as in "for HTML, ... (this does not apply to XML)".

この仕様は、短い静的な文書からリッチなマルチメディアを伴う長いエッセイやレポートだけでなく、本格的な対話型アプリケーションにまで至る、HTMLの任意の用法を表す用語文書を使用する。The term is used to refer both to Document objects and their descendant DOM trees, and to serialized byte streams using the HTML syntax or the XML syntax, depending on context.

DOM構造の文脈において、用語HTML文書およびXML文書は、DOM仕様で定義されるとおりに使用され、Documentオブジェクトが自分自身を見つけることができる2つの異なるモードを表す。[DOM](このような用途は常に定義にハイパーリンクされる。)

バイトストリームの文脈において、用語HTML文書は、text/htmlとして分類されたリソースを指し、用語XML文書は、XML MIMEタイプで分類されるリソースを指す。


簡潔さのために、文書がユーザーに表示される方法を参照する際、(原文でいう)showndisplayedvisibleのような用語が時に使用されるかもしれない。これらの用語は、視覚メディアを意味するものではない。同等の方法で、他のメディアに適用されると考えなければならない。

When an algorithm B says to return to another algorithm A, it implies that A called B. Upon returning to A, the implementation must continue from where it left off in calling B. Some algorithms run in parallel; this means that the algorithm's subsequent steps are to be run, one after another, at the same time as other logic in the specification (e.g. at the same time as the event loop). This specification does not define the precise mechanism by which this is achieved, be it time-sharing cooperative multitasking, fibers, threads, processes, using different hyperthreads, cores, CPUs, machines, etc. By contrast, an operation that is to run immediately must interrupt the currently running task, run itself, and then resume the previously running task.

用語"透明な黒"は、赤、緑、青、およびアルファチャンネルをすべて0に設定した色を指す。

2.1.1 リソース

仕様は、ユーザーエージェントが外部リソースのセマンティックスをデコード可能な実装を持つかどうかを参照する場合に用語サポートされるを使用する。フォーマットまたはタイプは、重要なリソースの機能を無視されることなく、実装がそのフォーマットやタイプの外部リソースを処理できる場合はサポートされると言われる。特定のリソースがサポートされるかどうかは、リソースのフォーマットのどの機能が使用されるかに依存するだろう。

たとえば、たとえ実装の知らないうちに、画像がアニメーションデータを含む場合でも、画像のピクセルデータがデコードされレンダリングされるならば、PNG画像はサポートされるフォーマットであると見なされるだろう。

たとえ実装がファイルのメタデータからムービーの寸法を決定可能でも、使用される圧縮形式がサポートされていなかった場合、MPEG-4ビデオファイルはサポートされるフォーマットであるとみなされない。

特にHTTP仕様において、一部の仕様がrepresentationと表されるものは、この仕様でリソースとして表される。[HTTP]

リソースのクリティカルサブリソースは、リソースが正しく処理されるために使用できる状態にしておく必要があるものである。どのリソースがクリティカルかどうかとみなされるかは、リソースのフォーマットを定義する仕様によって定義されない。

2.1.2 XML compatibility

To ease migration from HTML to XML, UAs conforming to this specification will place elements in HTML in the http://www.w3.org/1999/xhtml namespace, at least for the purposes of the DOM and CSS. The term "HTML elements", when used in this specification, refers to any element in that namespace, even in XML documents.

他に記載される場合を除き、この仕様で定義または記載されるすべての要素はHTML名前空間("http://www.w3.org/1999/xhtml")であり、この仕様で定義または記載されるすべての属性は名前空間を持たない。

用語要素タイプは、与えられたローカル名と名前空間を持つ要素の集合を参照するために使用される。たとえば、button要素は要素型buttonをもつ要素であり、ローカル名"button"および(上で定義されるように暗黙のうちに)HTML名前空間を持つことを意味する。

属性名がXMLで定義されたName生成物と一致しかつ、U+003A COLON文字(:)を含まない場合、属性名はXML互換であると言われる。[XML]

2.1.3 DOMツリー

ノードが一部の要素または属性が無視されると言われる、または他の値として扱われる、または何か他のものであったかのように扱われる場合、これはDOMになった後の、ノードの処理のみを指す。ユーザーエージェントは、そのような状況でDOMを変化させてはならない。

新しい値が前の値と異なっている場合のみ、コンテンツ属性は値を変更すると言われる。既に持つ属性値を設定することは変更ではない。

The term empty, when used for an attribute value, Text node, or string, means that the length of the text is zero (i.e. not even containing spaces or control characters).

要素の子テキストコンテンツは、ツリー順に(コメントや要素などの任意の他のノードを無視して)要素の子であるすべてのTextノードのデータの連結である。

挿入手順が引数としてAで呼び出される場合かつAの新しい親がBであるので、ノードBノードAは挿入される。同様に、除去手順removedNode引数としてAにかつoldParent引数としてBに呼び出される場合に、ノードBからノードAは除去される

挿入手順が引数としてノードに呼び出されかつノードが現在文書ツリー内に存在する場合、ノードは文書内に挿入される。類似の方法で、除去手順が引数としてノードに呼び出されかつノードがもはや文書ツリー内に存在しない場合、ノードは文書から除去される

挿入手順が引数としてノードに呼び出されかつノードが現在接続される場合、ノードは接続される。類似の方法で、除去手順が引数としてノードに呼び出されかつノードがもはや接続されない場合、ノードは切断される

ノードは、ノードが接続されており、かつノードのシャドウを含むルートブラウジングコンテキストを持つ場合に、ブラウジングコンテキスト接続である。ノードは、挿入手順が引数として呼び出され、かつノードが今ブラウジングコンテキスト接続である場合に、ブラウジングコンテキスト接続になる。ノードは、除去手順が引数としてノードを呼び出され、かつノードがもはや現在ブラウジングコンテキスト接続でないか、ノードのシャドウを含むルートがもはやブラウジングコンテキストを持たないかのいずれかの場合、ブラウジングコンテキスト切断になる

2.1.4 スクリプティング

構造体"Fooオブジェクト"は、Fooが実際にインターフェイスである場合、時折より正確な"Fooインターフェイスを実装するオブジェクト"の代わりに使用される。

IDL属性は、その値が(著者のスクリプトなどによって)取得時に取得されると言われ、新しい値が割り当てられる際に設定されると言われる。

DOMオブジェクトがライブであると言われる場合、そのオブジェクトの属性とメソッドは、データのスナップショットではなく、実際の元となるデータを操作しなければならない。

2.1.5 プラグイン

用語プラグインは、Documentオブジェクトの属するユーザーエージェントのレンダリングに関与可能な、ユーザーエージェントによって使用されるコンテンツハンドラーの組に定義されるユーザーエージェントを参照するが、Document子ブラウジングコンテキストとして振る舞うことも、任意のNodeオブジェクトをDocumentのDOMに導入することもない。

通常、そのようなコンテンツハンドラーは、第三者によって提供される。もっともユーザーエージェントもまた、プラグインとしてビルトインコンテンツのハンドラーを指定できる。

ユーザーエージェントは、タイプtext/plainおよびapplication/octet-streamを登録されたプラグインを持つものとして考慮しなければならない。

プラグインの一例は、ユーザーがPDFファイルを操作するときにブラウジングコンテキストでインスタンスを生成されたPDFビューアーであろう。これは、実装されたPDFビューアーコンポーネントがユーザーエージェント自身に実装されたものと同じメーカーかどうかにかかわらず、プラグインとしてカウントされるだろう。しかし、ユーザーエージェント(同じインターフェイスを使用するのではない)とは別に起動するPDFビューアーアプリケーションは、この定義によるプラグインではない。

プラグインはユーザーエージェント固有かつプラットフォーム固有であることが予測されるので、この仕様はプラグインと情報交換するためのメカニズムを定義しない。一部のユーザーエージェントは、NetscapeプラグインAPIのようなプラグイン機構をサポートすることを選ぶかもしれない。他のユーザーエージェントは、リモートコンテンツコンバーターを使用するか、または特定の種類のビルトインサポートを持つかもしれない。実際に、この仕様はユーザーエージェントにプラグインのサポートを一切要求しない。[NPAPI]

sandbox属性のセマンティックスを受け取る場合、プラグインは保護されるだろう。

たとえば、保護されるプラグインは、プラグインがサンドボックス化されるiframe内部でインスタンス化される際、コンテンツがポップアップウィンドウを生成することから防ぐだろう。

Browsers should take extreme care when interacting with external content intended for plugins. When third-party software is run with the same privileges as the user agent itself, vulnerabilities in the third-party software become as dangerous as those in the user agent.

Since different users having different sets of plugins provides a fingerprinting vector that increases the chances of users being uniquely identified, user agents are encouraged to support the exact same set of plugins for each user. (This is a fingerprinting vector.)

2.1.6 文字エンコーディング

文字エンコーディング、すなわち曖昧でない箇所で単にエンコーディングは、WHATWGエンコーディング標準で定義されるように、バイトストリームとUnicode文字列との間の変換方法を定義する。エンコーディングは、エンコーディング仕様でエンコーディングの名前およびラベルとして参照される、エンコーディング名および1つ以上のエンコーディングラベルを持つ。[ENCODING]

UTF-16エンコーディングは、UTF-16BEまたはUTF-16LEである。[ENCODING]

ASCII互換エンコーディングは、UTF-16エンコーディングでない任意のエンコーディングである。[ENCODING]

WHATWGエンコーディング標準で定義されないエンコーディングのサポートは禁止されるため、UTF-16エンコーディングは、この仕様がASCII互換エンコーディングでないものとして処理するために必要となる唯一のエンコーディングである。

用語コード単位はWeb IDL仕様で定義されるとおり、16ビット符号なし整数、DOMStringの最小の基本コンポーネントとして使用される。(これは、Unicodeで使用されるものより狭い定義であり、コードポイントと同一ではない。)[WEBIDL]

用語Unicodeコードポイントは、可能であればUnicodeスカラー値を、そうでないならば孤立サロゲートコードポイントを意味する。適合要件が文字またはUnicodeコードポイントの用語で定義される場合、下位サロゲートに続く上位サロゲートから成るコード単位のペアは、サロゲートペアで表される単一のコードポイントとして扱われなければならないが、孤立したサロゲートは、サロゲートの値を持つ単一のコードポイントとしてそれぞれ扱われなければならない。[UNICODE]

この仕様において、用語文字は、Unicode文字として修飾されてい場合、用語Unicodeコードポイントと同義である。

用語Unicode文字は、Unicodeスカラー値(すなわち、サロゲートコードポイントでない任意のUnicodeコードポイント)を意味するために使用される。[UNICODE]

文字列のコード単位長さは、その文字列のコード単位の数である。

この複雑さは、Unicode文字の観点よりむしろ、16ビット(UTF-16)コード単位の観点でDOM APIを定義するための歴史的な決定に由来する。

2.1.7 適合クラス

This specification describes the conformance criteria for user agents (relevant to implementors) and documents (relevant to authors and authoring tool implementors).

Conforming documents are those that comply with all the conformance criteria for documents. For readability, some of these conformance requirements are phrased as conformance requirements on authors; such requirements are implicitly requirements on documents: by definition, all documents are assumed to have had an author. (In some cases, that author may itself be a user agent — such user agents are subject to additional rules, as explained below.)

For example, if a requirement states that "authors must not use the foobar element", it would imply that documents are not allowed to contain elements named foobar.

There is no implied relationship between document conformance requirements and implementation conformance requirements. User agents are not free to handle non-conformant documents as they please; the processing model described in this specification applies to implementations regardless of the conformity of the input documents.

User agents fall into several (overlapping) categories with different conformance requirements.

Web browsers and other interactive user agents

Web browsers that support the XML syntax must process elements and attributes from the HTML namespace found in XML documents as described in this specification, so that users can interact with them, unless the semantics of those elements have been overridden by other specifications.

A conforming Web browser would, upon finding a script element in an XML document, execute the script contained in that element. However, if the element is found within a transformation expressed in XSLT (assuming the user agent also supports XSLT), then the processor would instead treat the script element as an opaque element that forms part of the transform.

Web browsers that support the HTML syntax must process documents labeled with an HTML MIME type as described in this specification, so that users can interact with them.

User agents that support scripting must also be conforming implementations of the IDL fragments in this specification, as described in the Web IDL specification. [WEBIDL]

Unless explicitly stated, specifications that override the semantics of HTML elements do not override the requirements on DOM objects representing those elements. For example, the script element in the example above would still implement the HTMLScriptElement interface.

Non-interactive presentation user agents

User agents that process HTML and XML documents purely to render non-interactive versions of them must comply to the same conformance criteria as Web browsers, except that they are exempt from requirements regarding user interaction.

Typical examples of non-interactive presentation user agents are printers (static UAs) and overhead displays (dynamic UAs). It is expected that most static non-interactive presentation user agents will also opt to lack scripting support.

A non-interactive but dynamic presentation UA would still execute scripts, allowing forms to be dynamically submitted, and so forth. However, since the concept of "focus" is irrelevant when the user cannot interact with the document, the UA would not need to support any of the focus-related DOM APIs.

Visual user agents that support the suggested default rendering

User agents, whether interactive or not, may be designated (possibly as a user option) as supporting the suggested default rendering defined by this specification.

This is not required. In particular, even user agents that do implement the suggested default rendering are encouraged to offer settings that override this default to improve the experience for the user, e.g. changing the color contrast, using different focus styles, or otherwise making the experience more accessible and usable to the user.

User agents that are designated as supporting the suggested default rendering must, while so designated, implement the rules the rendering section defines as the behavior that user agents are expected to implement.

User agents with no scripting support

Implementations that do not support scripting (or which have their scripting features disabled entirely) are exempt from supporting the events and DOM interfaces mentioned in this specification. For the parts of this specification that are defined in terms of an events model or in terms of the DOM, such user agents must still act as if events and the DOM were supported.

Scripting can form an integral part of an application. Web browsers that do not support scripting, or that have scripting disabled, might be unable to fully convey the author's intent.

Conformance checkers

Conformance checkers must verify that a document conforms to the applicable conformance criteria described in this specification. Automated conformance checkers are exempt from detecting errors that require interpretation of the author's intent (for example, while a document is non-conforming if the content of a blockquote element is not a quote, conformance checkers running without the input of human judgement do not have to check that blockquote elements only contain quoted material).

Conformance checkers must check that the input document conforms when parsed without a browsing context (meaning that no scripts are run, and that the parser's scripting flag is disabled), and should also check that the input document conforms when parsed with a browsing context in which scripts execute, and that the scripts never cause non-conforming states to occur other than transiently during script execution itself. (This is only a "SHOULD" and not a "MUST" requirement because it has been proven to be impossible. [COMPUTABLE])

The term "HTML validator" can be used to refer to a conformance checker that itself conforms to the applicable requirements of this specification.

XML DTDs cannot express all the conformance requirements of this specification. Therefore, a validating XML processor and a DTD cannot constitute a conformance checker. Also, since neither of the two authoring formats defined in this specification are applications of SGML, a validating SGML system cannot constitute a conformance checker either.

To put it another way, there are three types of conformance criteria:

  1. Criteria that can be expressed in a DTD.
  2. Criteria that cannot be expressed by a DTD, but can still be checked by a machine.
  3. Criteria that can only be checked by a human.

A conformance checker must check for the first two. A simple DTD-based validator only checks for the first class of errors and is therefore not a conforming conformance checker according to this specification.

Data mining tools

Applications and tools that process HTML and XML documents for reasons other than to either render the documents or check them for conformance should act in accordance with the semantics of the documents that they process.

A tool that generates document outlines but increases the nesting level for each paragraph and does not increase the nesting level for each section would not be conforming.

Authoring tools and markup generators

Authoring tools and markup generators must generate conforming documents. Conformance criteria that apply to authors also apply to authoring tools, where appropriate.

Authoring tools are exempt from the strict requirements of using elements only for their specified purpose, but only to the extent that authoring tools are not yet able to determine author intent. However, authoring tools must not automatically misuse elements or encourage their users to do so.

For example, it is not conforming to use an address element for arbitrary contact information; that element can only be used for marking up contact information for the author of the document or section. However, since an authoring tool is likely unable to determine the difference, an authoring tool is exempt from that requirement. This does not mean, though, that authoring tools can use address elements for any block of italics text (for instance); it just means that the authoring tool doesn't have to verify that when the user uses a tool for inserting contact information for a section, that the user really is doing that and not inserting something else instead.

In terms of conformance checking, an editor has to output documents that conform to the same extent that a conformance checker will verify.

When an authoring tool is used to edit a non-conforming document, it may preserve the conformance errors in sections of the document that were not edited during the editing session (i.e. an editing tool is allowed to round-trip erroneous content). However, an authoring tool must not claim that the output is conformant if errors have been so preserved.

Authoring tools are expected to come in two broad varieties: tools that work from structure or semantic data, and tools that work on a What-You-See-Is-What-You-Get media-specific editing basis (WYSIWYG).

The former is the preferred mechanism for tools that author HTML, since the structure in the source information can be used to make informed choices regarding which HTML elements and attributes are most appropriate.

However, WYSIWYG tools are legitimate. WYSIWYG tools should use elements they know are appropriate, and should not use elements that they do not know to be appropriate. This might in certain extreme cases mean limiting the use of flow elements to just a few elements, like div, b, i, and span and making liberal use of the style attribute.

All authoring tools, whether WYSIWYG or not, should make a best effort attempt at enabling users to create well-structured, semantically rich, media-independent content.

User agents may impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial of service attacks, to guard against running out of memory, or to work around platform-specific limitations. (This is a fingerprinting vector.)

For compatibility with existing content and prior specifications, this specification describes two authoring formats: one based on XML, and one using a custom format inspired by SGML (referred to as the HTML syntax). Implementations must support at least one of these two formats, although supporting both is encouraged.

Some conformance requirements are phrased as requirements on elements, attributes, methods or objects. Such requirements fall into two categories: those describing content model restrictions, and those describing implementation behavior. Those in the former category are requirements on documents and authoring tools. Those in the second category are requirements on user agents. Similarly, some conformance requirements are phrased as requirements on authors; such requirements are to be interpreted as conformance requirements on the documents that authors produce. (In other words, this specification does not distinguish between conformance criteria on authors and conformance criteria on documents.)

2.1.8 依存関係

この仕様は、複数の基礎をなす仕様に依存する。

Infra

The following terms are defined in the WHATWG Infra standard: [INFRA]

Unicodeおよびエンコーディング

Unicode文字セットは、テキストデータを表すために使用され、WHATWG Encoding標準は、文字エンコーディングを中心とする要件を定義する。[UNICODE]

この仕様は、前述したように、その仕様で定義される用語に基づく用語を導入する

WHATWG Encoding標準[ENCODING]で定義される次の用語が使用される:

XMLおよび関連仕様

Implementations that support the XML syntax for HTML must support some version of XML, as well as its corresponding namespaces specification, because that syntax uses an XML serialization with namespaces. [XML] [XMLNS]

Data mining tools and other user agents that perform operations on content without running scripts, evaluating CSS or XPath expressions, or otherwise exposing the resulting DOM to arbitrary content, may "support namespaces" by just asserting that their DOM node analogues are in certain namespaces, without actually exposing the namespace strings.

HTML構文において、名前空間接頭辞および名前空間宣言は、XMLと同一の効果を持たない。たとえば、HTML要素名においてコロンは特別な意味を持たない。


XML名前空間でタグ名xml:spaceをもつ属性は、XML仕様で定義される。[XML]

Name生成物は、XML仕様で定義される。[XML]

この仕様はまた、Associating Style Sheets with XML documents仕様で定義される、<?xml-stylesheet?>処理命令を参照する。[XMLSSPI]

この仕様はまた、XSLTProcessorインターフェイスとそのtransformToFragment()およびtransformToDocument()メソッドに非規範的に言及する。[XSLTP]

URL

次の用語はWHATWG URL標準[URL]で定義される:

多くのスキーマおよびプロトコルはまたこの仕様で参照される:

メディアフラグメント構文Media Fragments URI仕様で定義される。[MEDIAFRAG]

HTTPおよび関連仕様

次の用語はHTTP仕様[HTTP]で定義される:

次の用語はCookie仕様[COOKIES]で定義される:

  • cookie-string
  • receives a set-cookie-string
  • `Cookie`ヘッダー

次の用語はWeb Linking仕様[WEBLINK]で定義される:

The following terms are defined in the WHATWG MIME Sniffing standard: [MIMESNIFF]

Fetch

次の用語はWHATWG Fetch標準[FETCH]で定義される:

次の用語は、Referrer Policy仕様[REFERRERPOLICY]で定義される:

次の用語は、Mixed Content [MIX]で定義される:

Web IDL

Web IDL仕様に記載されるとおりに、この仕様におけるIDL断片は、適合するIDL断片に要求されるとして解釈されなければならない。[WEBIDL]

次の用語はWeb IDL仕様で定義される:

Web IDL仕様はまた、この仕様においてWeb IDL断片で使用される次の型を定義する:

この仕様における用語投げるは、Web IDL仕様で定義されるとおりに使用される。DOMException型および次の例外名はWeb IDLによって定義されかつこの仕様によって使用される:

この仕様が(特別な値Not-a-Numberであるかもしれない)特定の時間を表すDateオブジェクトを作成することをユーザーエージェントに要求する場合、もしあれば、その時刻のミリ秒コンポーネントは整数に切り捨てられなければならず、新しく作成されるDateオブジェクトの時刻値は、結果として生じる切り捨てられる時刻を表さなければならない。

たとえば、2000年1月1日1時より後の100万分の23045秒の時刻、つまり2000-01-01T00:00:00.023045Zが与えられる場合、時刻を表す作成されたDateオブジェクトは、100万分の45秒早い、時刻2000-01-01T00:00:00.023Zを表す作成されたものと同じ時刻を表す。与えられる時刻がNaNである場合、結果は(オブジェクトが特定の時間の瞬間を表さないことを示す)時刻値NaNを表すDateオブジェクトとなる。

JavaScript

この仕様によって記載される言語の一部は、基礎となるスクリプト言語としてJavaScriptのみをサポートする。[JAVASCRIPT]

Users agents that support JavaScript must also implement the ECMAScript Internationalization API Specification. [JSINTL]

用語JavaScriptはより広く知られているため、用語"JavaScript"は、公式用語ECMAScriptよりもむしろ、ECMA-262を参照するために使用される。同様に、RFC 4329によれば公式に廃止されたタイプであるにもかかわらず、最も一般的に使用されるタイプであるため、この仕様でJavaScriptを参照するために使用されるMIMEタイプは、text/javascriptである。[RFC4329]

次の用語はJavaScript仕様で定義され、この仕様で使用される:

DOM

ドキュメントオブジェクトモデル(DOM)は、文書とそのコンテンツの表現(モデル)である。DOMは単なるAPIではない。HTML実装の適合基準は、DOMに対する操作の観点から、この仕様で定義される。[DOM]

この仕様はDOMの観点で定義され、機能の一部はDOMインターフェイスの拡張機能として定義されるため、実装は、DOMおよびUI Eventsで定義されるイベントをサポートしなければならない。[DOM] [UIEVENTS]

具体的に、次の機能がWHATWG DOM標準[DOM]で定義される:

次の機能は、UI Events仕様[UIEVENTS]で定義される:

次の機能は、Touch Events仕様[TOUCH]で定義される:

The following features are defined in the Pointer Events specification: [POINTEREVENTS]

The following features are defined in the auxclick specification: [AUXCLICK]

この仕様は、イベントのタイプを参照するために用語名前(name)を使用することがある。たとえば、"clickと名付けられるイベント"または"イベント名がkeypressである場合"などである。イベントのための用語"名前"と"タイプ"は同義語である。

次の機能は、DOM Parsing and Serialization仕様[DOMPARSING]で定義される:

Selectionインターフェイスは、Selection API仕様で定義される。[SELECTION]

ユーザーエージェントは、execCommand仕様で説明される機能を実装することを勧める。[EXECCOMMAND]

WHATWG Fullscreen API標準[FULLSCREEN]の次の部分は、ある程度dialog要素のレンダリングを定義するために、かつフルスクリーンAPIがHTMLと対話する方法を定義するために、この仕様から参照される:

High Resolution Time仕様は、DOMHighResTimeStampのtypedefおよびPerformanceインターフェイスのnow()メソッドを提供する。[HRT]

File API

この仕様はFile API仕様[FILEAPI]で定義される次の機能を使用する:

Media Source Extensions

次の用語はMedia Source Extensions仕様[MEDIASOURCE]で定義される:

Media Capture and Streams

次の用語はMedia Capture and Streams仕様[MEDIASTREAM]で定義される:

XMLHttpRequest

この仕様は、2つの仕様がどのように相互作用するかを説明し、ProgressEvent機能を使用するためにXMLHttpRequest仕様を参照する。次の機能および用語がXMLHttpRequest仕様[XHR]で定義される:

Battery Status

次の機能は、Battery Status API仕様[BATTERY]で定義される:

Media Queries

実装は、Media Queriesをサポートしなければならない。<media-condition>機能が定義される。[MQ]

CSSモジュール

全体としてのCSSのサポー​​トはこの仕様の実装に必要とされないが(少なくともウェブブラウザー用に奨励されるが)、一部の機能は、特定のCSS要件の観点で定義される。

この仕様が特定のCSSの文法に従って解析されるものを要求する場合、CSS Syntax仕様で関連するアルゴリズムが続かなければならない。[CSSSYNTAX]

具体的に、一部の機能は、CSS <color>値として解析される文字列を要求する。CSS値を解析する際、ユーザーエージェントは、一部のエラー処理規則を適用するためにCSS仕様によって要求される。これはまた、この仕様に適用される。[CSSCOLOR] [CSS]

たとえば、ユーザーエージェントは予期せずスタイルシートの最後を見つけると、開いているすべての構成物を閉じることを要求される。したがって、色値の(閉じ丸括弧の欠損している)文字列"rgb(0,0,0"を解析する場合、閉じ丸括弧はこのエラー処理規則によって暗示され、値は(色'black')を得られる。しかし、(欠損する括弧と欠損する"青"値の両方をもつ類似の構成物"rgb(0,0,"は、開いた構成物を閉じることは実行可能な値をもたらさないため、解析することができない。

次の用語および機能は、CSS仕様[CSS]で定義される:

CSS仕様[CSS]はまた、次のボーダープロパティを定義する:

ボーダープロパティ
Top Bottom Left Right
Width 'border-top-width' 'border-bottom-width' 'border-left-width' 'border-right-width'
Style 'border-top-style' 'border-bottom-style' 'border-left-style' 'border-right-style'
Color 'border-top-color' 'border-bottom-color' 'border-left-color' 'border-right-color'

用語内在幅および内在高さは、それぞれ、内在次元の幅次元および高さ次元を参照する。

'display'プロパティの基本バージョンはCSS仕様で定義され、プロパティは他のCSSモジュールによって拡張される。[CSS] [CSSRUBY] [CSSTABLE][CSS] [CSSRUBY] [CSSTABLE]

次の用語および機能はCSS Logical Properties仕様[CSSLOGICAL]で定義される:

次の用語および機能はCSS Color仕様[CSSCOLOR]で定義される:

用語paint sourceは、CSS 'element()'関数と特定のHTML要素との相互作用を定義するためにCSS Image Values and Replaced Content仕様で定義されるとおりに使用される。[CSSIMAGES]

用語デフォルトオブジェクトサイズおよび'object-fit'プロパティはまた、CSS Image Values and Replaced Content仕様で定義される。[CSSIMAGES]

次の機能は、CSS Backgrounds and Borders仕様[CSSBG]で定義される:

用語ブロックレベルは、CSS Display仕様で定義される。[CSSDISPLAY]

次の機能は、CSS Fonts仕様[CSSFONTS]で定義される:

'list-style-type'プロパティは、CSS Lists and Counters仕様で定義される。[CSSLISTS]

'overflow'プロパティは、CSS Overflow仕様[CSSOVERFLOW]で定義される。[CSSOVERFLOW]

次の機能は、CSS Positioned Layout仕様[CSSPOSITION]で定義される:

'display'プロパティの'ruby-base'値は、CSS Ruby Layout仕様で定義される。[CSSRUBY]

次の機能は、CSS Table仕様[CSSTABLE]で定義される:

次の機能は、CSS Text仕様[CSSTEXT]で定義される:

次の機能は、CSS Writing Modes仕様[CSSWM]で定義される:

次の機能は、CSS Basic User Interface仕様[CSSUI]で定義される:

スクリプトをサポートする実装は、CSS Object Modelをサポートしなければならない。次の機能は、CSSOM仕様[CSSOM] [CSSOMVIEW]で定義される:

次の機能は、CSS Syntax仕様[CSSSYNTAX]で定義される:

次の機能は、Selectors仕様[SELECTORS]で定義される:

次の機能は、CSS Values and Units仕様[CSSVALUES]で定義される:

用語スタイル属性は、CSS Style Attributes仕様で定義される。[CSSATTR]

次の機能は、CSS Cascading and Inheritance仕様[CSSCASCADE]で定義される:

フォントのCanvasRenderingContext2Dの使用は、具体的にはFontFaceオブジェクトおよびfont sourceコンセプトを含む、CSS FontsおよびFont Loading仕様で説明される機能に依存する。[CSSFONTS] [CSSFONTLOAD]

次のインターフェイスおよび用語は、Geometry Interfaces Module仕様[GEOMETRY]で定義される:

Intersection Observer

次の用語は、Intersection Observer仕様[INTERSECTIONOBSERVER]で定義される:

WebGL

次のインターフェイスは、WebGL仕様[WEBGL]で定義される:

WebVTT

実装は、subtitles, captions, chapter titles, metadataなどに対するおよびメディアリソースに対するテキストトラックフォーマットとしてWebVTTをサポートしてもよい。[WEBVTT]

この仕様で使用される次の用語は、WebVTT仕様で定義される:

WebSocket protocol

次の用語はWHATWG Fetch標準[FETCH]で定義される:

次の用語はWebSocket protocol仕様[WSP]で定義される:

  • WebSocket接続が確立される
  • 使用中の拡張
  • 使用中のサブプロトコル
  • WebSocketメッセージが受信した
  • WebSocketメッセージを送信する
  • WebSocket接続に失敗する
  • WebSocket接続を閉じる
  • WebSocket終了ハンドシェイクを開始する
  • WebSocket終了ハンドシェイクが開始される
  • WebSocket接続は閉じられた(おそらくクリーンに
  • WebSocket接続終了コード
  • WebSocket接続終了理由
  • Sec-WebSocket-Protocolフィールド
ARIA

次のロールのように、role属性はARIA仕様[ARIA]で定義される:

加えて、次のaria-*コンテンツ属性はARIA仕様で定義される[ARIA]

最後に、次の用語がARIA仕様で定義される[ARIA]

Content Security Policy

次の用語は、Content Security Policy仕様[CSP]で定義される:

Service Workers

次の用語はService Workers [SW]で定義される:

Secure Contexts

The following terms are defined in Secure Contexts: [SECURE-CONTEXTS]

Payment Request API

The following feature is defined in the Payment Request API specification: [PAYMENTREQUEST]

MathML

全体としてMathMLに対するサポートは、この仕様によって要求されないが(少なくともウェブブラウザーの場合に奨励されるが)、特定の機能は、実装されている一部のMathMLに依存する。[MATHML]

次の機能はMathML仕様で定義される:

SVG

全体としてSVGに対するサポートは、この仕様によって要求されないが(少なくともウェブブラウザーの場合に奨励されるが)、特定の機能は、実装されている一部のSVGに依存する。

また、SVG仕様は実装の現実を反映していない。実装は、SVG1.1とSVG Tiny 1.2のサブセットを実装している。進行中のSVG2仕様の準備ができるまで、SVG2仕様は実装のためのより現実的な目標であることが期待されるが、SVGを実装するユーザーエージェントは、次の故意の違反および追加を行わなければならない。[SVG] [SVGTINY12] [SVG2]

SVGを実装するユーザーエージェントはSVG 1.1由来の次の機能を実装してはならない:

  • tref要素
  • cursor要素(CSSのcursorプロパティを代わりに使用する)
  • フォント定義SVG要素:font, glyph, missing-glyph, hkern, vkern, font-face, font-face-src, font-face-uri, font-face-format, font-face-name(CSSの@font-faceを代わりに使用する)
  • externalResourcesRequired属性
  • enable-backgroundプロパティ
  • contentScriptTypeおよびcontentStyleType属性(SVG scriptおよびstyle要素のtype属性を代わりに使用する)

SVGを実装するユーザーエージェントはSVG Tiny 1.2由来の次の機能を実装しなければならない:

  • vector-effectプロパティのnon-scaling-stroke
  • class属性は、すべてのSVG要素で許可される
  • tabindex属性は、可視SVG要素で許可される
  • ARIAアクセシビリティー属性は、すべてのSVG要素で許可される

次の機能はSVG仕様で定義される:

Filter Effects

次の機能はFilter Effects [FILTERS]仕様で定義される:


この仕様は、特定のネットワークプロトコル、スタイルシート言語、スクリプト言語、または上記のリストで要求されるものを超えたDOM仕様のいずれかのサポートを要求しない。しかし、この仕様で記載される言語は、スタイル言語としてCSS、スクリプト言語としてJavaScript、およびネットワークプロトコルとしてHTTPに偏っており、そして複数の機能は、これらの言語およびプロトコルが使用されることを前提とする。

同様に、HTTPプロトコルを実装するユーザーエージェントは、HTTP State Management Mechanism (Cookies)を実装しなければならない。[HTTP] [COOKIES]

この仕様は、それぞれの節で文字エンコーディング、画像フォーマット、オーディオフォーマット、およびビデオフォーマットの特定の追加要件があるかもしれない。

2.1.9 拡張性

ユーザーエージェントがこの仕様を拡張するベンダー固有のプロパティを強く推奨しない。そうすることは、特定のユーザーエージェントのユーザーだけが当該のコンテンツにアクセスすることができ、相互運用性を減少させユーザーベースを分断するので、文書はそのような拡張を使用してはならない。

All extensions must be defined so that the use of extensions neither contradicts nor causes the non-conformance of functionality defined in the specification.

For example, while strongly discouraged from doing so, an implementation could add a new IDL attribute "typeTime" to a control that returned the time it took the user to select the current value of a control (say). On the other hand, defining a new control that appears in a form's elements array would be in violation of the above requirement, as it would violate the definition of elements given in this specification.


この仕様にベンダー中立の拡張が必要になった場合、この仕様が状況に応じて更新されうる、または拡張仕様がこの仕様の要求を上書きされうるかのいずれかである。この仕様に自分の活動を適用するある人が、そのような拡張仕様の要件を承認することを決定する場合、拡張仕様はこの仕様における適合性要求の目的に適用可能な仕様になる。

誰かが適合するものとして任意のバイトストリームを定義する仕様を記述することができ、そしてランダムなジャンクが準拠していることを主張することができる。しかし、それはそのランダムなジャンクが皆の目的に実際に適合していることを意味しない。他の誰かがその仕様が自分の仕事に適用されないと判断する場合、彼らは、前述のランダムジャンクがそのもので、ジャンクであり、かつ一切適合しないものであると完全に合法的に言うことはできる。適合性に関する限り、特定のコミュニティーで重要なのは、そのコミュニティーが同意するものが適用可能なことである。


User agents must treat elements and attributes that they do not understand as semantically neutral; leaving them in the DOM (for DOM processors), and styling them according to CSS (for CSS processors), but not inferring any meaning from them.

When support for a feature is disabled (e.g. as an emergency measure to mitigate a security problem, or to aid in development, or for performance reasons), user agents must act as if they had no support for the feature whatsoever, and as if the feature was not mentioned in this specification. For example, if a particular feature is accessed via an attribute in a Web IDL interface, the attribute itself would be omitted from the objects that implement that interface — leaving the attribute on the object but making it return null or throw an exception is insufficient.

2.1.10 Interactions with XPath and XSLT

Spec bugs: 18460

Implementations of XPath 1.0 that operate on HTML documents parsed or created in the manners described in this specification (e.g. as part of the document.evaluate() API) must act as if the following edit was applied to the XPath 1.0 specification.

First, remove this paragraph:

A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context. This is the same way expansion is done for element type names in start and end-tags except that the default namespace declared with xmlns is not used: if the QName does not have a prefix, then the namespace URI is null (this is the same way attribute names are expanded). It is an error if the QName has a prefix for which there is no namespace declaration in the expression context.

Then, insert in its place the following:

A QName in the node test is expanded into an expanded-name using the namespace declarations from the expression context. If the QName has a prefix, then there must be a namespace declaration for this prefix in the expression context, and the corresponding namespace URI is the one that is associated with this prefix. It is an error if the QName has a prefix for which there is no namespace declaration in the expression context.

If the QName has no prefix and the principal node type of the axis is element, then the default element namespace is used. Otherwise if the QName has no prefix, the namespace URI is null. The default element namespace is a member of the context for the XPath expression. The value of the default element namespace when executing an XPath expression through the DOM3 XPath API is determined in the following way:

  1. If the context node is from an HTML DOM, the default element namespace is "http://www.w3.org/1999/xhtml".
  2. Otherwise, the default element namespace URI is null.

This is equivalent to adding the default element namespace feature of XPath 2.0 to XPath 1.0, and using the HTML namespace as the default element namespace for HTML documents. It is motivated by the desire to have implementations be compatible with legacy HTML content while still supporting the changes that this specification introduces to HTML regarding the namespace used for HTML elements, and by the desire to use XPath 1.0 rather than XPath 2.0.

This change is a willful violation of the XPath 1.0 specification, motivated by desire to have implementations be compatible with legacy content while still supporting the changes that this specification introduces to HTML regarding which namespace is used for HTML elements. [XPATH10]


XSLT 1.0 processors outputting to a DOM when the output method is "html" (either explicitly or via the defaulting rule in XSLT 1.0) are affected as follows:

If the transformation program outputs an element in no namespace, the processor must, prior to constructing the corresponding DOM element node, change the namespace of the element to the HTML namespace, ASCII-lowercase the element's local name, and ASCII-lowercase the names of any non-namespaced attributes on the element.

This requirement is a willful violation of the XSLT 1.0 specification, required because this specification changes the namespaces and case-sensitivity rules of HTML in a manner that would otherwise be incompatible with DOM-based XSLT transformations. (Processors that serialize the output are unaffected.) [XSLT10]


This specification does not specify precisely how XSLT processing interacts with the HTML parser infrastructure (for example, whether an XSLT processor acts as if it puts any elements into a stack of open elements). However, XSLT processors must stop parsing if they successfully complete, and must set the current document readiness first to "interactive" and then to "complete" if they are aborted.


This specification does not specify how XSLT interacts with the navigation algorithm, how it fits in with the event loop, nor how error pages are to be handled (e.g. whether XSLT errors are to replace an incremental XSLT output, or are rendered inline, etc).

There are also additional non-normative comments regarding the interaction of XSLT and HTML in the script element section, and of XSLT, XPath, and HTML in the template element section.

2.2 大文字・小文字区別と文字列の比較

大文字・小文字区別において2つの文字列を比較することは、正確にコードポイントを比較することを意味する。

明記される場合を除き、文字列の比較は大文字・小文字区別の方法で実行されなければならない。

patterns未満でかつpatternの長さにsを切り捨てが、互いにマッチとしての2つの文字列のままにする場合、文字列のpatternは、文字列s接頭辞一致である。

2.3 共通マイクロ構文

日付や数字など、HTMLには特定のデータ型を受け入れるさまざまな箇所がある。この節では、これら形式の内容の適合基準が何か、そしてどのように解析するかを説明する。

実装者は、以下に説明される構文の解析を実装するために使用することを検討するかもしれないサードパーティー製のライブラリーを注意深く検査することを強く勧める。たとえば、エラー処理動作はこの仕様で使用される類似した日付構文を記述する仕様で多くの場合定義されないため、日付ライブラリーはこの仕様で要求されるものとは異なるエラー処理動作を実装する可能性が高く、それゆえ実装はエラーを処理する方法が大きく変化する傾向がある。

2.3.1 共通パーサー語句

空白類文字は、UnicodeのPropList.txtデータファイルでUnicodeプロパティ"White_Space"を持つものである。[UNICODE]

This is not to be confused with the "White_Space" value (abbreviated "WS") of the "Bidi_Class" property in the Unicode.txt data file.

制御文字とは、UnicodeのUnicodeData.txtデータファイルでUnicodeの"White_Space"プロパティを持つものである。[UNICODE]

Some of the micro-parsers described below follow the pattern of having an input variable that holds the string being parsed, and having a position variable pointing at the next character to parse in input.

2.3.2 真偽属性

いくつかの属性は真偽属性である。要素での真偽属性の存在は真の値を表し、属性の不在は偽の値を表す。

属性が存在する場合、その値は先頭または末尾の空白なしで、空の文字列または属性の正規名にASCII大文字・小文字不区別でマッチする値でなければならない。

値"true"および"false"は真偽属性で許可されない。偽の値を表すため、属性は完全に省略される必要がある。

checkedおよびdisabledとなるチェックボックスの例を示す。checkedおよびdisabled属性は真偽属性である。

<label><input type=checkbox checked name=cheese disabled> Cheese</label>

これは次に書かれるものと等価であるべきである:

<label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>

スタイルを混在させることもできる。以下は依然として等価である:

<label><input type='checkbox' checked name=cheese disabled=""> Cheese</label>

2.3.3 キーワードおよび列挙属性

一部の属性は、有限集合のキーワードのいずれかを取るように定義されている。このような属性は列挙属性と呼ばれる。キーワードは、特定の状態にそれぞれ対応付けて定義される(キーワードの一部が互いに同義語となる場合、複数のキーワードは同じ状態に対応づけられる。加えて、一部のキーワードは不適合であると言うことができる。これは、歴史的な理由のためだけの仕様である)。さらに、2つのデフォルト状態を挙げることができる。1つ目は不正値のデフォルトであり、2つ目は欠損値のデフォルトである。

列挙属性が指定される場合、属性値は、先行または後続の空白なしで、不適合でないとされる与えられたキーワードのいずれかとASCII大文字・小文字不区別で一致しなければならない。

属性が指定される際に、その値が与えられたキーワードのいずれかとASCII大文字・小文字不区別で一致する場合、属性のキーワードの状態は、属性が表す状態である。属性値が与えられたキーワードのいずれにも一致しないが、属性が不正値のデフォルトを持つ場合、その属性はその状態を表す。そうでなければ、属性値がキーワードのいずれにも一致しないが欠損値のデフォルト状態定義が存在する場合、それは属性によって表される状態である。そうでなければ、デフォルトは存在せず、何も表さない状態を意味する妥当でない値である。

属性が指定されない際に、欠損値のデフォルト定義状態がある場合、それは(欠損)属性によって表される状態である。そうでなければ、属性の不在は何も状態を表さないことを意味する。

空文字列は妥当なキーワードとなりうる。

2.3.4 数字

2.3.4.1 符号付き整数

文字列が1つ以上のASCII 数字、任意で接頭辞U+002D HYPHEN-MINUS文字(-)を持つ場合、文字列は妥当な整数である。

接頭辞U+002D HYPHEN-MINUS(-)接頭辞なしの妥当な整数は、10進数を表す。U+002D HYPHEN-MINUS文字(-)接頭辞あり妥当な整数は、U+002D HYPHEN-MINUSに続く10進数を表し、0から減算される。

The rules for parsing integers are as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either an integer or an error.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let sign have the value "positive".

  4. Skip ASCII whitespace within input given position.

  5. If position is past the end of input, return an error.

  6. If the character indicated by position (the first character) is a U+002D HYPHEN-MINUS character (-):

    1. Let sign be "negative".
    2. Advance position to the next character.
    3. If position is past the end of input, return an error.

    Otherwise, if the character indicated by position (the first character) is a U+002B PLUS SIGN character (+):

    1. Advance position to the next character. (The "+" is ignored, but it is not conforming.)
    2. If position is past the end of input, return an error.
  7. If the character indicated by position is not an ASCII digit, then return an error.

  8. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer. Let value be that integer.

  9. If sign is "positive", return value, otherwise return the result of subtracting value from zero.

2.3.4.2 非負整数

1つ以上のASCII数字からなる場合、文字列は妥当な非負整数である。

妥当な非負整数は、10進数である数を表す。

The rules for parsing non-negative integers are as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either zero, a positive integer, or an error.

  1. Let input be the string being parsed.

  2. Let value be the result of parsing input using the rules for parsing integers.

  3. If value is an error, return an error.

  4. If value is less than zero, return an error.

  5. Return value.

2.3.4.3 浮動小数点数

次の場合、文字列は妥当な浮動小数点数である:

  1. Optionally, a U+002D HYPHEN-MINUS character (-).
  2. 次のいずれかまたは両方の、与えられた順:
    1. ひと続きの1つ以上のASCII数字
    2. Both of the following, in the given order:
      1. A single U+002E FULL STOP character (.).
      2. ひと続きの1つ以上のASCII数字
  3. 任意で:
    1. Either a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E).
    2. Optionally, a U+002D HYPHEN-MINUS character (-) or U+002B PLUS SIGN character (+).
    3. ひと続きの1つ以上のASCII数字

妥当な浮動小数点数は、10の累乗による仮数部の乗算によって得られる。ここで乗算は最初の数であり、10進数として解釈される(もしあれば、小数点および小数点の後の数を含み、文字列全体がU+002D HYPHEN-MINUS文字(-)で始まるおよび数値が0でない場合、負数として仮数部を解釈する)。またここで、もしあれば、指数はEの後の数字である(Eと数字と数字の間にU+002D HYPHEN-MINUS文字(-)がある場合、負数として解釈され、数字が0でない、またはその他Eと数字の間にU+002B PLUS SIGN文字(+)が存在する場合無視できる)。Eが存在しない場合、指数はゼロとして扱われる。

無限大および非数(NaN)値は妥当な浮動小数点数ではない。

The valid floating-point number concept is typically only used to restrict what is allowed for authors, while the user agent requirements use the rules for parsing floating-point number values below (e.g., the max attribute of the progress element). However, in some cases the user agent requirements include checking if a string is a valid floating-point number (e.g., the value sanitization algorithm for the Number state of the input element, or the parse a srcset attribute algorithm).

The best representation of the number n as a floating-point number is the string obtained from running ToString(n). The abstract operation ToString is not uniquely determined. When there are multiple possible strings that could be obtained from ToString for a particular value, the user agent must always return the same string for that value (though it may differ from the value used by other user agents).

The rules for parsing floating-point number values are as given in the following algorithm. This algorithm must be aborted at the first step that returns something. This algorithm will return either a number or an error.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let value have the value 1.

  4. Let divisor have the value 1.

  5. Let exponent have the value 1.

  6. Skip ASCII whitespace within input given position.

  7. If position is past the end of input, return an error.

  8. If the character indicated by position is a U+002D HYPHEN-MINUS character (-):

    1. Change value and divisor to −1.
    2. Advance position to the next character.
    3. If position is past the end of input, return an error.

    Otherwise, if the character indicated by position (the first character) is a U+002B PLUS SIGN character (+):

    1. Advance position to the next character. (The "+" is ignored, but it is not conforming.)
    2. If position is past the end of input, return an error.
  9. If the character indicated by position is a U+002E FULL STOP (.), and that is not the last character in input, and the character after the character indicated by position is an ASCII digit, then set value to zero and jump to the step labeled fraction.

  10. If the character indicated by position is not an ASCII digit, then return an error.

  11. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer. Multiply value by that integer.

  12. If position is past the end of input, jump to the step labeled conversion.
  13. Fraction: If the character indicated by position is a U+002E FULL STOP (.), run these substeps:

    1. Advance position to the next character.

    2. If position is past the end of input, or if the character indicated by position is not an ASCII digit, U+0065 LATIN SMALL LETTER E (e), or U+0045 LATIN CAPITAL LETTER E (E), then jump to the step labeled conversion.

    3. If the character indicated by position is a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E), skip the remainder of these substeps.

    4. Fraction loop: Multiply divisor by ten.

    5. Add the value of the character indicated by position, interpreted as a base-ten digit (0..9) and divided by divisor, to value.
    6. Advance position to the next character.

    7. If position is past the end of input, then jump to the step labeled conversion.

    8. If the character indicated by position is an ASCII digit, jump back to the step labeled fraction loop in these substeps.

  14. If the character indicated by position is a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E), run these substeps:

    1. Advance position to the next character.

    2. If position is past the end of input, then jump to the step labeled conversion.

    3. If the character indicated by position is a U+002D HYPHEN-MINUS character (-):

      1. Change exponent to −1.
      2. Advance position to the next character.
      3. If position is past the end of input, then jump to the step labeled conversion.

      Otherwise, if the character indicated by position is a U+002B PLUS SIGN character (+):

      1. Advance position to the next character.
      2. If position is past the end of input, then jump to the step labeled conversion.

    4. If the character indicated by position is not an ASCII digit, then jump to the step labeled conversion.

    5. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer. Multiply exponent by that integer.

    6. Multiply value by ten raised to the exponentth power.

  15. Conversion: Let S be the set of finite IEEE 754 double-precision floating-point values except −0, but with two special values added: 21024 and −21024.

  16. Let rounded-value be the number in S that is closest to value, selecting the number with an even significand if there are two equally close values. (The two special values 21024 and −21024 are considered to have even significands for this purpose.)

  17. If rounded-value is 21024 or −21024, return an error.

  18. Return rounded-value.

2.3.4.4 Percentages and lengths

The rules for parsing dimension values are as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a number greater than or equal to 0.0, or an error; if a number is returned, then it is further categorized as either a percentage or a length.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Skip ASCII whitespace within input given position.

  4. If position is past the end of input, return an error.

  5. If the character indicated by position is a U+002B PLUS SIGN character (+), advance position to the next character.

  6. If position is past the end of input, return an error.

  7. If the character indicated by position is not an ASCII digit, then return an error.

  8. Collect a sequence of code points that are ASCII digits from input given position, and interpret the resulting sequence as a base-ten integer. Let value be that number.

  9. If position is past the end of input, return value as a length.

  10. If the character indicated by position is a U+002E FULL STOP character (.):

    1. Advance position to the next character.

    2. If position is past the end of input, or if the character indicated by position is not an ASCII digit, then return value as a length.

    3. Let divisor have the value 1.

    4. Fraction loop: Multiply divisor by ten.

    5. Add the value of the character indicated by position, interpreted as a base-ten digit (0..9) and divided by divisor, to value.
    6. Advance position to the next character.

    7. If position is past the end of input, then return value as a length.

    8. If the character indicated by position is an ASCII digit, return to the step labeled fraction loop in these substeps.

  11. If position is past the end of input, return value as a length.

  12. If the character indicated by position is a U+0025 PERCENT SIGN character (%), return value as a percentage.

  13. Return value as a length.

2.3.4.5 Non-zero percentages and lengths

The rules for parsing non-zero dimension values are as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a number greater than 0.0, or an error; if a number is returned, then it is further categorized as either a percentage or a length.

  1. Let input be the string being parsed.

  2. Let value be the result of parsing input using the rules for parsing dimension values.

  3. If value is an error, return an error.

  4. If value is zero, return an error.

  5. If value is a percentage, return value as a percentage.

  6. Return value as a length.

2.3.4.6 浮動小数点数のリスト

A valid list of floating-point numbers is a number of valid floating-point numbers separated by U+002C COMMA characters, with no other characters (e.g. no ASCII whitespace). さらに、与えられる浮動小数点数の数、または許可される値の範囲には制限があるかもしれない。

The rules for parsing a list of floating-point numbers are as follows:

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let numbers be an initially empty list of floating-point numbers. This list will be the result of this algorithm.

  4. Collect a sequence of code points that are ASCII whitespace, U+002C COMMA, or U+003B SEMICOLON characters from input given position. This skips past any leading delimiters.

  5. While position is not past the end of input:

    1. Collect a sequence of code points that are not ASCII whitespace, U+002C COMMA, U+003B SEMICOLON, ASCII digits, U+002E FULL STOP, or U+002D HYPHEN-MINUS characters from input given position. This skips past leading garbage.

    2. Collect a sequence of code points that are not ASCII whitespace, U+002C COMMA, or U+003B SEMICOLON characters from input given position, and let unparsed number be the result.

    3. Let number be the result of parsing unparsed number using the rules for parsing floating-point number values.

    4. If number is an error, set number to zero.

    5. Append number to numbers.

    6. Collect a sequence of code points that are ASCII whitespace, U+002C COMMA, or U+003B SEMICOLON characters from input given position. This skips past the delimiter.

  6. Return numbers.

2.3.4.7 Lists of dimensions

The rules for parsing a list of dimensions are as follows. These rules return a list of zero or more pairs consisting of a number and a unit, the unit being one of percentage, relative, and absolute.

  1. Let raw input be the string being parsed.

  2. If the last character in raw input is a U+002C COMMA character (,), then remove that character from raw input.

  3. Split the string raw input on commas. Let raw tokens be the resulting list of tokens.

  4. Let result be an empty list of number/unit pairs.

  5. For each token in raw tokens, run the following substeps:

    1. Let input be the token.

    2. Let position be a pointer into input, initially pointing at the start of the string.

    3. Let value be the number 0.

    4. Let unit be absolute.

    5. If position is past the end of input, set unit to relative and jump to the last substep.

    6. If the character at position is an ASCII digit, collect a sequence of code points that are ASCII digits from input given position, interpret the resulting sequence as an integer in base ten, and increment value by that integer.

    7. If the character at position is a U+002E FULL STOP character (.), run these substeps:

      1. Collect a sequence of code points consisting of ASCII whitespace and ASCII digits from input given position. Let s be the resulting sequence.

      2. Remove all ASCII whitespace in s.

      3. If s is not the empty string, run these subsubsteps:

        1. Let length be the number of characters in s (after the spaces were removed).

        2. Let fraction be the result of interpreting s as a base-ten integer, and then dividing that number by 10length.

        3. Increment value by fraction.

    8. Skip ASCII whitespace within input given position.

    9. If the character at position is a U+0025 PERCENT SIGN character (%), then set unit to percentage.

      Otherwise, if the character at position is a U+002A ASTERISK character (*), then set unit to relative.

    10. Add an entry to result consisting of the number given by value and the unit given by unit.

  6. Return the list result.

2.3.5 日付および時刻

下記のアルゴリズムにおいて、yearの月monthの日数は:monthが1、3、5、7、8、10、12ならば31である。monthが4、6、9、11ならば30である。monthが2かつyearが400で割り切れる数、またはyearが4で割り切れるが100で割り切れないならば29であり、そうでなければ28である。これは、グレゴリオ暦の閏年を考慮に入れている。[GREGORIAN]

ASCII数字がこの節で定義される日付および時刻の構文で使用される場合、これらは10進数で表現される。

While the formats described here are intended to be subsets of the corresponding ISO8601 formats, this specification defines parsing rules in much more detail than ISO8601. Implementors are therefore encouraged to carefully examine any date parsing libraries before using them to implement the parsing rules described below; ISO8601 libraries might not parse dates and times in exactly the same manner. [ISO8601]

この仕様が先発グレゴリオ暦を参照する場合、これは、1年に遡って挿入された現代のグレゴリオ暦を意味する。先発グレゴリオ日付として明示的に参照される先発グレゴリオ暦での日付は、たとえ暦が問題の時刻(または場所)で使用されていないとしても、その暦を使用して説明される。[GREGORIAN]

この仕様においてワイヤ形式としてのグレゴリオ暦の使用は、決定に関わる人々の文化的なバイアスに起因する恣意的な選択肢である。(著者に対する)フォームの日付、時刻、数値の形式フォームコントロールのローカライゼーションに関する実装ノートおよびtimeの節も参照のこと。

2.3.5.1 月

は、タイムゾーン情報および年と月を超えた日付を持たない、特定の先発グレゴリオ暦から成る。[GREGORIAN]

与えられた順で以下のコンポーネントからなる場合、文字列は、年yearおよび月monthで表される妥当な月文字列である:

  1. 4以上で表されるyear。ここでyear > 0である。
  2. A U+002D HYPHEN-MINUS文字(-)
  3. 1 ≤ month ≤ 12の範囲で、月monthを表す2つのASCII数字

The rules to parse a month string are as follows. This will return either a year and month, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a month component to obtain year and month. If this returns nothing, then fail.

  4. If position is not beyond the end of input, then fail.

  5. Return year and month.

The rules to parse a month component, given an input string and a position, are as follows. This will return either a year and a month, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not at least four characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the year.

  2. If year is not a number greater than zero, then fail.

  3. If position is beyond the end of input or if the character at position is not a U+002D HYPHEN-MINUS character, then fail. Otherwise, move position forwards one character.

  4. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the month.

  5. If month is not a number in the range 1 ≤ month ≤ 12, then fail.

  6. Return year and month.

2.3.5.2 日付

日付は、年月日からなりタイムゾーン情報を持たない、特定の先発グレゴリオ暦からなる。[GREGORIAN]

与えられた順で以下のコンポーネントからなる場合、文字列は年year、月month、日dayで表される妥当な日付文字列である:

  1. yearおよびmonthで表される、妥当な月文字列
  2. A U+002D HYPHEN-MINUS文字(-)
  3. 1 ≤ day ≤ maxdayの範囲でのdayで表される2つのASCII数字。ここでmaxdayyearおよび月monthでの日の数である。

The rules to parse a date string are as follows. This will return either a date, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a date component to obtain year, month, and day. If this returns nothing, then fail.

  4. If position is not beyond the end of input, then fail.

  5. Let date be the date with year year, month month, and day day.

  6. Return date.

The rules to parse a date component, given an input string and a position, are as follows. This will return either a year, a month, and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Parse a month component to obtain year and month. If this returns nothing, then fail.

  2. Let maxday be the number of days in month month of year year.

  3. If position is beyond the end of input or if the character at position is not a U+002D HYPHEN-MINUS character, then fail. Otherwise, move position forwards one character.

  4. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the day.

  5. If day is not a number in the range 1 ≤ day ≤ maxday, then fail.

  6. Return year, month, and day.

2.3.5.3 年なし日付

年なし日付はグレコリオ月とその月の日からなるが、年を伴わない。[GREGORIAN]

与えられた順で以下のコンポーネントからなる場合、文字列は月monthおよび日dayで表される妥当な年なし日付文字列である:

  1. 任意で、2つのA U+002D HYPHEN-MINUS文字(-)
  2. 1 ≤ month ≤ 12の範囲で、月monthを表す2つのASCII数字
  3. A U+002D HYPHEN-MINUS文字(-)
  4. 1 ≤ day ≤ maxdayの範囲でのdayで表される2つのASCII数字。ここでmaxdayは月monthかつ任意の閏年(たとえば4または2000)における日数である。

言い換えると、2月を意味するmonthが"02"である場合、あたかもその年は閏年かのように、日は29であってもよい。

The rules to parse a yearless date string are as follows. This will return either a month and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a yearless date component to obtain month and day. If this returns nothing, then fail.

  4. If position is not beyond the end of input, then fail.

  5. Return month and day.

The rules to parse a yearless date component, given an input string and a position, are as follows. This will return either a month and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code points that are U+002D HYPHEN-MINUS characters (-) from input given position. If the collected sequence is not exactly zero or two characters long, then fail.

  2. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the month.

  3. If month is not a number in the range 1 ≤ month ≤ 12, then fail.

  4. Let maxday be the number of days in month month of any arbitrary leap year (e.g. 4 or 2000).

  5. If position is beyond the end of input or if the character at position is not a U+002D HYPHEN-MINUS character, then fail. Otherwise, move position forwards one character.

  6. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the day.

  7. If day is not a number in the range 1 ≤ day ≤ maxday, then fail.

  8. Return month and day.

2.3.5.4 時刻

時刻は、時、分、秒、秒以下からなりタイムゾーン情報を持たない、特定の時刻からなる。

与えられた順で以下のコンポーネントからなる場合、文字列は、時hour、分minute、秒secondで表される妥当な時刻文字列である:

  1. 0 ≤ hour ≤ 23の範囲で、hourを表す2つのASCII数字
  2. A U+003A COLON文字(:)
  3. 0 ≤ minute ≤ 59の範囲でminuteを表す2つのASCII数字
  4. secondが非0である場合、または任意でsecondが0である場合:
    1. A U+003A COLON文字(:)
    2. 0 ≤ s ≤ 59の範囲で、second整数部を表す2つのASCII数字
    3. secondが非整数である場合、または任意でsecondが整数である場合:
      1. A U+002E FULL STOP character (.)
      2. second分数部で表される、1、2、また3

secondコンポーネントは60または61にはなり得ない。閏秒を表すことはできない。

The rules to parse a time string are as follows. This will return either a time, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a time component to obtain hour, minute, and second. If this returns nothing, then fail.

  4. If position is not beyond the end of input, then fail.

  5. Let time be the time with hour hour, minute minute, and second second.

  6. Return time.

The rules to parse a time component, given an input string and a position, are as follows. This will return either an hour, a minute, and a second, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the hour.

  2. If hour is not a number in the range 0 ≤ hour ≤ 23, then fail.
  3. If position is beyond the end of input or if the character at position is not a U+003A COLON character, then fail. Otherwise, move position forwards one character.

  4. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the minute.

  5. If minute is not a number in the range 0 ≤ minute ≤ 59, then fail.
  6. Let second be 0.

  7. If position is not beyond the end of input and the character at position is a U+003A COLON, then run these substeps:

    1. Advance position to the next character in input.

    2. If position is beyond the end of input, or at the last character in input, or if the next two characters in input starting at position are not both ASCII digits, then fail.

    3. Collect a sequence of code points that are either ASCII digits or U+002E FULL STOP characters from input given position. If the collected sequence is three characters long, or if it is longer than three characters long and the third character is not a U+002E FULL STOP character, or if it has more than one U+002E FULL STOP character, then fail. Otherwise, interpret the resulting sequence as a base-ten number (possibly with a fractional part). Set second to that number.

    4. If second is not a number in the range 0 ≤ second < 60, then fail.

  8. Return hour, minute, and second.

2.3.5.5 ローカル日付および時刻

ローカル日付および時刻は、年、月、日、時、分、秒、秒以下からなる特定の先発グレコリオ暦からなるが、タイムゾーン情報を持たない。[GREGORIAN]

与えられた順で以下のコンポーネントからなる場合、文字列は妥当なローカル日付および時刻文字列である:

  1. 日付を表す妥当な日付文字列
  2. U+0054 LATIN CAPITAL LETTER T文字(T)またはU+0020 SPACE文字
  3. 時刻を表す妥当な時刻文字列

与えられた順で以下のコンポーネントからなる場合、文字列は妥当な規格化ローカル日付および時刻文字列である:

  1. 日付を表す妥当な日付文字列
  2. A U+0054 LATIN CAPITAL LETTER T文字(T)
  3. 時刻を表す妥当な時間文字列は、与えられた時刻に対して可能な限り最短の文字列として表現される(たとえば、与えられた時刻がゼロ秒分を過ぎている場合、完全に秒のコンポーネントを省略する)

The rules to parse a local date and time string are as follows. This will return either a date and time, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a date component to obtain year, month, and day. If this returns nothing, then fail.

  4. If position is beyond the end of input or if the character at position is neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then fail. Otherwise, move position forwards one character.

  5. Parse a time component to obtain hour, minute, and second. If this returns nothing, then fail.

  6. If position is not beyond the end of input, then fail.

  7. Let date be the date with year year, month month, and day day.

  8. Let time be the time with hour hour, minute minute, and second second.

  9. Return date and time.

2.3.5.6 タイムゾーン

タイムゾーンオフセットは符号付きの時と分の数字からなる。

次のいずれかからなる場合、文字列は、タイムゾーンオフセットを表す妥当なタイムゾーンオフセット文字列である:

この形式は、-23:59から+23:59までのタイムゾーンオフセットを許可する。特に、実際のタイムゾーンオフセットの範囲は-12:00から+14:00までであり、実際のタイムゾーンオフセットの分コンポーネントは常に00、30または45のいずれかである。とはいえ、タイムゾーンは政争の具として使用され、非常に気まぐれな政策決定の対象とされるので、永遠に保持される保証はない。

正式なタイムゾーンの形成以前に遡る歴史的な時代でのタイムゾーンのオフセットを使用についての詳細は、下記のグローバル日付および時刻の節にある使用上の注意と例を参照のこと。

The rules to parse a time-zone offset string are as follows. This will return either a time-zone offset, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a time-zone offset component to obtain timezonehours and timezoneminutes. If this returns nothing, then fail.

  4. If position is not beyond the end of input, then fail.

  5. Return the time-zone offset that is timezonehours hours and timezoneminutes minutes from UTC.

The rules to parse a time-zone offset component, given an input string and a position, are as follows. This will return either time-zone hours and time-zone minutes, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. If the character at position is a U+005A LATIN CAPITAL LETTER Z character (Z), then:

    1. Let timezonehours be 0.

    2. Let timezoneminutes be 0.

    3. Advance position to the next character in input.

    Otherwise, if the character at position is either a U+002B PLUS SIGN (+) or a U+002D HYPHEN-MINUS (-), then:

    1. If the character at position is a U+002B PLUS SIGN (+), let sign be "positive". Otherwise, it's a U+002D HYPHEN-MINUS (-); let sign be "negative".

    2. Advance position to the next character in input.

    3. Collect a sequence of code points that are ASCII digits from input given position. Let s be the collected sequence.

    4. If s is exactly two characters long, then run these substeps:

      1. Interpret s as a base-ten integer. Let that number be the timezonehours.

      2. If position is beyond the end of input or if the character at position is not a U+003A COLON character, then fail. Otherwise, move position forwards one character.

      3. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the timezoneminutes.

      If s is exactly four characters long, then run these substeps:

      1. Interpret the first two characters of s as a base-ten integer. Let that number be the timezonehours.

      2. Interpret the last two characters of s as a base-ten integer. Let that number be the timezoneminutes.

      Otherwise, fail.

    5. If timezonehours is not a number in the range 0 ≤ timezonehours ≤ 23, then fail.
    6. If sign is "negative", then negate timezonehours.
    7. If timezoneminutes is not a number in the range 0 ≤ timezoneminutes ≤ 59, then fail.
    8. If sign is "negative", then negate timezoneminutes.

    Otherwise, fail.

  2. Return timezonehours and timezoneminutes.

2.3.5.7 グローバル日付および時刻

グローバル日付および時刻は、符号付き時分からなるタイムゾーンオフセットとともに年、月、日、時、分、秒、秒以下からなる特定先発グレコリオ暦で構成する。[GREGORIAN]

与えられた順で以下のコンポーネントからなる場合、日付、時刻、タイムゾーンオフセットを表す文字列は妥当なグローバル日付および時刻である:

  1. 日付を表す妥当な日付文字列
  2. U+0054 LATIN CAPITAL LETTER T文字(T)またはU+0020 SPACE文字
  3. 時刻を表す妥当な時刻文字列
  4. タイムゾーンオフセットを表す妥当なタイムゾーンオフセット文字列

20世紀半ばにUTCを形成する前の日付の時刻は、UTC(UT1の近似がSI秒を刻む)ではなく、UT1(0°経度での現代の地球太陽時)の見地から表現および解釈されなければならない。タイムゾーンを形成する前の時刻は、適切なローカル時刻とロンドンのグリニッジで観測された時間との間のおおよその現代的な違いのある明示的なタイムゾーンとともにUT1の時間として表現および解釈されなければならない。

以下は妥当なグローバル日付および時刻として記述される例の一部である。

"0037-12-13 00:00Z"
ネロ(ローマ皇帝)の誕生日にロンドン時間を用いた地域での真夜中。これが実際に対応している日付のさらなる議論については下記を参照のこと。
"1979-10-14T12:00:00.001-04:00"
夏時間の間にアメリカ東海岸で使用されるタイムゾーンで、1979年10月14日の正午1ミリ秒後。
"8592-01-01T02:09+02:09"
8592年1月1日のUTCで夜中。現在の実際のタイムゾーンではない、UTCより早く時刻が2時9分であるタイムゾーンに関連づけられるが、それでもなお、許可される。

数点の以下の日付に関して顕著である:

The rules to parse a global date and time string are as follows. This will return either a time in UTC, with associated time-zone offset information for round-tripping or display purposes, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Parse a date component to obtain year, month, and day. If this returns nothing, then fail.

  4. If position is beyond the end of input or if the character at position is neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then fail. Otherwise, move position forwards one character.

  5. Parse a time component to obtain hour, minute, and second. If this returns nothing, then fail.

  6. If position is beyond the end of input, then fail.

  7. Parse a time-zone offset component to obtain timezonehours and timezoneminutes. If this returns nothing, then fail.

  8. If position is not beyond the end of input, then fail.

  9. Let time be the moment in time at year year, month month, day day, hours hour, minute minute, second second, subtracting timezonehours hours and timezoneminutes minutes. That moment in time is a moment in the UTC time zone.

  10. Let timezone be timezonehours hours and timezoneminutes minutes from UTC.

  11. Return time and timezone.

2.3.5.8 週

は、週番号年と週番号からなる。週番号は、月曜日から始まる7日間を示す。以下の定義に従って、このカレンダーシステムにおける週番号年は52または53の7日間を持つ。グレゴリオ暦の日付で1969年12月29日(1969-12-29)月曜日で始まる7日間は、1970週番号年で週番号1として定義される。連続した週は連番が付けられる。週番号年で1週目の前の週は、前の週番号年の最終週である。逆もまた同様である。[GREGORIAN]

最初の日(1月1日)が木曜である先発グレコリオ暦の年year、または最初の日(1月1日)が木曜である先発グレコリオ暦の年yearのいずれかに対応する場合、数字yearとともに週番号年は53週を持つ。ここで、yearは400で割り切れる数字、または4で割り切れるが100で割り切れない数字である。他のすべての週番号年は52週である。

53週をもつ週番号年の最終日の週番号は53であり、52週をもつ週番号年の最終日の週番号は52である。

特定の日の週番号年の数は、先発グレゴリオ暦で、その日を含む年の数と異なる場合がある。週番号年yでの最初の週は、グレコリオ年yの最初の木曜を含む週である。

現代の用途に対して、ここで定義されるは、ISO 8601で定義されるようなISO週に相当する。[ISO8601]

与えられた順で以下のコンポーネントからなる場合、文字列は、週番号年yearおよび週weekを表す妥当な週文字列である:

  1. 4以上で表されるyear。ここでyear > 0である。
  2. A U+002D HYPHEN-MINUS文字(-)
  3. U+0057 LATIN CAPITAL LETTER W文字(W)
  4. 1 ≤ week ≤ maxweekの範囲で、週weekを表す2つのASCII数字。ここで maxweekは週番号年year最終日の週番号である。

The rules to parse a week string are as follows. This will return either a week-year number and week number, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not at least four characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the year.

  4. If year is not a number greater than zero, then fail.

  5. If position is beyond the end of input or if the character at position is not a U+002D HYPHEN-MINUS character, then fail. Otherwise, move position forwards one character.

  6. If position is beyond the end of input or if the character at position is not a U+0057 LATIN CAPITAL LETTER W character (W), then fail. Otherwise, move position forwards one character.

  7. Collect a sequence of code points that are ASCII digits from input given position. If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be the week.

  8. Let maxweek be the week number of the last day of year year.

  9. If week is not a number in the range 1 ≤ week ≤ maxweek, then fail.

  10. If position is not beyond the end of input, then fail.

  11. Return the week-year number year and the week number week.

2.3.5.9 継続時間

継続時間は複数秒からなる。

月と秒は同等ではない(1か月は正確な秒数ではなく、その正確な長さは、測定された正確な1日に依存する期間である)ので、この仕様で定義される継続時間は月を含めることはできない(また年は12か月に等しい)特定の秒数を記述する継続時間のみが記述可能である。

以下のいずれかからなる場合、文字列は、継続時間tで表す妥当な継続時間文字列である:

The rules to parse a duration string are as follows. This will return either a duration or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Let months, seconds, and component count all be zero.

  4. Let M-disambiguator be minutes.

    This flag's other value is months. It is used to disambiguate the "M" unit in ISO8601 durations, which use the same unit for months and minutes. Months are not allowed, but are parsed for future compatibility and to avoid misinterpreting ISO8601 durations that would be valid in other contexts.

  5. Skip ASCII whitespace within input given position.

  6. If position is past the end of input, then fail.

  7. If the character in input pointed to by position is a U+0050 LATIN CAPITAL LETTER P character, then advance position to the next character, set M-disambiguator to months, and skip ASCII whitespace within input given position.

  8. Run the following substeps in a loop, until a step requiring the loop to be broken or the entire algorithm to fail is reached:

    1. Let units be undefined. It will be assigned one of the following values: years, months, weeks, days, hours, minutes, and seconds.

    2. Let next character be undefined. It is used to process characters from the input.

    3. If position is past the end of input, then break the loop.

    4. If the character in input pointed to by position is a U+0054 LATIN CAPITAL LETTER T character, then advance position to the next character, set M-disambiguator to minutes, skip ASCII whitespace within input given position, and return to the top of the loop.

    5. Set next character to the character in input pointed to by position.

    6. If next character is a U+002E FULL STOP character (.), then let N equal zero. (Do not advance position. That is taken care of below.)

      Otherwise, if next character is an ASCII digit, then collect a sequence of code points that are ASCII digits from input given position, interpret the resulting sequence as a base-ten integer, and let N be that number.

      Otherwise next character is not part of a number; fail.

    7. If position is past the end of input, then fail.

    8. Set next character to the character in input pointed to by position, and this time advance position to the next character. (If next character was a U+002E FULL STOP character (.) before, it will still be that character this time.)

    9. If next character is a U+002E FULL STOP character (.), then run these substeps:

      1. Collect a sequence of code points that are ASCII digits from input given position. Let s be the resulting sequence.

      2. If s is the empty string, then fail.

      3. Let length be the number of characters in s.

      4. Let fraction be the result of interpreting s as a base-ten integer, and then dividing that number by 10length.

      5. Increment N by fraction.

      6. Skip ASCII whitespace within input given position.

      7. If position is past the end of input, then fail.

      8. Set next character to the character in input pointed to by position, and advance position to the next character.

      9. If next character is neither a U+0053 LATIN CAPITAL LETTER S character nor a U+0073 LATIN SMALL LETTER S character, then fail.

      10. Set units to seconds.

      そうでなければ、以下のサブ手順を実行する:

      1. If next character is ASCII whitespace, then skip ASCII whitespace within input given position, set next character to the character in input pointed to by position, and advance position to the next character.

      2. If next character is a U+0059 LATIN CAPITAL LETTER Y character, or a U+0079 LATIN SMALL LETTER Y character, set units to years and set M-disambiguator to months.

        If next character is a U+004D LATIN CAPITAL LETTER M character or a U+006D LATIN SMALL LETTER M character, and M-disambiguator is months, then set units to months.

        If next character is a U+0057 LATIN CAPITAL LETTER W character or a U+0077 LATIN SMALL LETTER W character, set units to weeks and set M-disambiguator to minutes.

        If next character is a U+0044 LATIN CAPITAL LETTER D character or a U+0064 LATIN SMALL LETTER D character, set units to days and set M-disambiguator to minutes.

        If next character is a U+0048 LATIN CAPITAL LETTER H character or a U+0068 LATIN SMALL LETTER H character, set units to hours and set M-disambiguator to minutes.

        If next character is a U+004D LATIN CAPITAL LETTER M character or a U+006D LATIN SMALL LETTER M character, and M-disambiguator is minutes, then set units to minutes.

        If next character is a U+0053 LATIN CAPITAL LETTER S character or a U+0073 LATIN SMALL LETTER S character, set units to seconds and set M-disambiguator to minutes.

        Otherwise if next character is none of the above characters, then fail.

    10. Increment component count.

    11. Let multiplier be 1.

    12. If units is years, multiply multiplier by 12 and set units to months.

    13. If units is months, add the product of N and multiplier to months.

      そうでなければ、以下のサブ手順を実行する:

      1. If units is weeks, multiply multiplier by 7 and set units to days.

      2. If units is days, multiply multiplier by 24 and set units to hours.

      3. If units is hours, multiply multiplier by 60 and set units to minutes.

      4. If units is minutes, multiply multiplier by 60 and set units to seconds.

      5. Forcibly, units is now seconds. Add the product of N and multiplier to seconds.

    14. Skip ASCII whitespace within input given position.

  9. If component count is zero, fail.

  10. If months is not zero, fail.

  11. Return the duration consisting of seconds seconds.

2.3.5.10 時刻における曖昧な瞬間

以下のいずれかである場合、文字列は任意の時刻を持つ妥当な日付文字列である:


The rules to parse a date or time string are as follows. The algorithm will return either a date, a time, a global date and time, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Let input be the string being parsed.

  2. Let position be a pointer into input, initially pointing at the start of the string.

  3. Set start position to the same position as position.

  4. Set the date present and time present flags to true.

  5. Parse a date component to obtain year, month, and day. If this fails, then set the date present flag to false.

  6. If date present is true, and position is not beyond the end of input, and the character at position is either a U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character, then advance position to the next character in input.

    Otherwise, if date present is true, and either position is beyond the end of input or the character at position is neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then set time present to false.

    Otherwise, if date present is false, set position back to the same position as start position.

  7. If the time present flag is true, then parse a time component to obtain hour, minute, and second. If this returns nothing, then fail.

  8. If the date present and time present flags are both true, but position is beyond the end of input, then fail.

  9. If the date present and time present flags are both true, parse a time-zone offset component to obtain timezonehours and timezoneminutes. If this returns nothing, then fail.

  10. If position is not beyond the end of input, then fail.

  11. If the date present flag is true and the time present flag is false, then let date be the date with year year, month month, and day day, and return date.

    Otherwise, if the time present flag is true and the date present flag is false, then let time be the time with hour hour, minute minute, and second second, and return time.

    Otherwise, let time be the moment in time at year year, month month, day day, hours hour, minute minute, second second, subtracting timezonehours hours and timezoneminutes minutes, that moment in time being a moment in the UTC time zone; let timezone be timezonehours hours and timezoneminutes minutes from UTC; and return time and timezone.

2.3.6 色

単純色は、sRGB色空間の中で各色のコンポーネント赤、緑、青を表す、0から255までの範囲の8ビット数字3つからなる。[SRGB]

正確に7文字長である、最初の文字がU+0023 NUMBER SIGN文字(#)であり、残りの6文字がすべてASCII16進数字である、最初の2桁は赤コンポーネントを表し、中の2桁は緑コンポーネントを表し、最後の2桁は青コンポーネントを表す16進数である場合、文字列は妥当な単純色である。

妥当な単純色でかつU+0041 LATIN CAPITAL LETTER AからU+0046 LATIN CAPITAL LETTER Fまでの範囲の文字を一切使用しない場合、文字列は妥当な小文字の単純色である。

The rules for parsing simple color values are as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a simple color or an error.

  1. Let input be the string being parsed.

  2. If input is not exactly seven characters long, then return an error.

  3. If the first character in input is not a U+0023 NUMBER SIGN character (#), then return an error.

  4. If the last six characters of input are not all ASCII hex digits, then return an error.

  5. Let result be a simple color.

  6. Interpret the second and third characters as a hexadecimal number and let the result be the red component of result.

  7. Interpret the fourth and fifth characters as a hexadecimal number and let the result be the green component of result.

  8. Interpret the sixth and seventh characters as a hexadecimal number and let the result be the blue component of result.

  9. Return result.

The rules for serializing simple color values given a simple color are as given in the following algorithm:

  1. Let result be a string consisting of a single U+0023 NUMBER SIGN character (#).

  2. Convert the red, green, and blue components in turn to two-digit hexadecimal numbers using ASCII lower hex digits, zero-padding if necessary, and append these numbers to result, in the order red, green, blue.

  3. Return result, which will be a valid lowercase simple color.


Some obsolete legacy attributes parse colors in a more complicated manner, using the rules for parsing a legacy color value, which are given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a simple color or an error.

  1. Let input be the string being parsed.

  2. If input is the empty string, then return an error.

  3. Strip leading and trailing ASCII whitespace from input.

  4. If input is an ASCII case-insensitive match for the string "transparent", then return an error.

  5. If input is an ASCII case-insensitive match for one of the named colors, then return the simple color corresponding to that keyword. [CSSCOLOR]

    CSS2 System Colors are not recognized.

  6. If input is four characters long, and the first character in input is a U+0023 NUMBER SIGN character (#), and the last three characters of input are all ASCII hex digits, then run these substeps:

    1. Let result be a simple color.

    2. Interpret the second character of input as a hexadecimal digit; let the red component of result be the resulting number multiplied by 17.

    3. Interpret the third character of input as a hexadecimal digit; let the green component of result be the resulting number multiplied by 17.

    4. Interpret the fourth character of input as a hexadecimal digit; let the blue component of result be the resulting number multiplied by 17.

    5. Return result.

  7. Replace any characters in input that have a Unicode code point greater than U+FFFF (i.e. any characters that are not in the basic multilingual plane) with the two-character string "00".

  8. If input is longer than 128 characters, truncate input, leaving only the first 128 characters.

  9. If the first character in input is a U+0023 NUMBER SIGN character (#), remove it.

  10. Replace any character in input that is not an ASCII hex digit with the character U+0030 DIGIT ZERO (0).

  11. While input's length is zero or not a multiple of three, append a U+0030 DIGIT ZERO (0) character to input.

  12. Split input into three strings of equal length, to obtain three components. Let length be the length of those components (one third the length of input).

  13. If length is greater than 8, then remove the leading length-8 characters in each component, and let length be 8.

  14. While length is greater than two and the first character in each component is a U+0030 DIGIT ZERO (0) character, remove that character and reduce length by one.

  15. If length is still greater than two, truncate each component, leaving only the first two characters in each.

  16. Let result be a simple color.

  17. Interpret the first component as a hexadecimal number; let the red component of result be the resulting number.

  18. Interpret the second component as a hexadecimal number; let the green component of result be the resulting number.

  19. Interpret the third component as a hexadecimal number; let the blue component of result be the resulting number.

  20. Return result.


2Dグラフィックスコンテキストは、不透明度も扱う個別の色構文を持つ。

2.3.7 空白区切りトークン

A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more ASCII whitespace, where words consist of any string of one or more characters, none of which are ASCII whitespace.

A string containing a set of space-separated tokens may have leading or trailing ASCII whitespace.

順序なし固有空白区切りトークンの組は、繰り返しトークンのない空白区切りトークンの組である。

順序あり固有空白区切りトークンの組は、繰り返しトークンはないが、トークンの順序が意味のある空白区切りトークンの組である。

空白区切りトークンの組は時折定義された許可される値の組を持つ。許可された値の組が定義される場合、トークンはすべて許可される値のリストでなければならない。その他の値は不適合である。そのような許可される値の組が用意されない場合、すべての値は適合である。

空白区切りトークンの組のトークンがどのように比較されるか(たとえば、大文字小文字を区別するかどうか)は、セットごとに定義される。

2.3.8 コンマ区切りトークン

A set of comma-separated tokens is a string containing zero or more tokens each separated from the next by a single U+002C COMMA character (,), where tokens consist of any string of zero or more characters, neither beginning nor ending with ASCII whitespace, nor containing any U+002C COMMA characters (,), and optionally surrounded by ASCII whitespace.

たとえば、文字列" a ,b,,d d "は4つのトークンからなる。"a"、"b"、空文字列および"d d"。各トークンの周りの先頭と末尾の空白はトークンの一部としてカウントされず、空文字列はトークンであるかもしれない。

コンマ区切りトークンの組は時に妥当なトークンを構成するさらなる制約を持つ。そのような制限が定義される場合、トークンはすべてその制限に収まるようにしなければならない。その他の値は不適合である。そのような制限が指定されない場合、すべての値は適合である。

2.3.9 参考文献

タイプtype要素の妥当なハッシュ名参照は、 U+0023 NUMBER SIGN文字(#)の後に同じツリーでタイプtypeをもつ要素のname属性の値に正確に一致する文字列から構成される文字列である。

The rules for parsing a hash-name reference to an element of type type, given a context node scope, are as follows:

  1. If the string being parsed does not contain a U+0023 NUMBER SIGN character, or if the first such character in the string is the last character in the string, then return null and abort these steps.

  2. Let s be the string from the character immediately after the first U+0023 NUMBER SIGN character in the string being parsed up to the end of that string.

  3. Return the first element of type type in scope's tree, in tree order, that has an id or name attribute whose value is s, or null if there is no such element.

    Although id attributes are accounted for when parsing, they are not used in determining whether a value is a valid hash-name reference. That is, a hash-name reference that refers to an element based on id is a conformance error (unless that element also has a name attribute with the same value).

2.3.10 メディアクエリー

メディアクエリー仕様の<media-query-list>生成物に一致する場合、文字列は妥当なメディアクエリーリストである。[MQ]

A string matches the environment of the user if it is the empty string, a string consisting of only ASCII whitespace, or is a media query list that matches the user's environment according to the definitions given in the Media Queries specification. [MQ]

2.4 URL

2.4.1 用語

A string is a valid non-empty URL if it is a valid URL string but it is not the empty string.

A string is a valid URL potentially surrounded by spaces if, after stripping leading and trailing ASCII whitespace from it, it is a valid URL string.

A string is a valid non-empty URL potentially surrounded by spaces if, after stripping leading and trailing ASCII whitespace from it, it is a valid non-empty URL.

この仕様は、たとえ解決不可能でも、XMLツールの互換性のために必要な場合、HTML文書DOCTYPEで用いるためのabout: URL予約としてURL about:legacy-compatを定義する。[ABOUT]

この仕様は、たとえ解決不可能でも、メディアトラック類のための識別子として用いられるabout: URLを予約としてURL about:html-kindを定義する。[ABOUT]

この仕様は、たとえ解決不可能でも、iframe srcdoc文書URLとして用いられるabout: URLを予約としてURL about:srcdocを定義する。[ABOUT]

Documentオブジェクトdocumentフォールバック基底URLは、次のサブステップを実行して得られるURLレコードである:

  1. Documentiframe srcdoc文書である場合、documentブラウジングコンテキストがもつブラウジングコンテキストコンテナノード文書に属する文書基底URLを返す。

  2. documentURLabout:blankであり、かつdocumentブラウジングコンテキストクリエイターブラウジングコンテキストを持つ場合、クリエイター基底URLを返す。

  3. documentURLを返す。

Documentオブジェクトの文書基底URLは、以下のサブステップを実行して得られる絶対URLである:

  1. Documenthref属性を持つbase要素が存在しない場合、文書基底URLDocumentフォールバック基底URLであり、これらの手順を中止する。

  2. そうでなければ、文書基底URLツリー順で、href属性を持つDocumentで最初のbase要素の凍結基底URLである。

2.4.2 Parsing URLs

Parsing a URL is the process of taking a string and obtaining the URL record that it represents. While this process is defined in the WHATWG URL standard, the HTML standard defines a wrapper for convenience. [URL]

This wrapper is only useful when the character encoding for the URL parser has to match that of the document or environment settings object for legacy reasons. When that is not the case the URL parser can be used directly.

To parse a URL url, relative to either a document or environment settings object, the user agent must use the following steps. Parsing a URL either results in failure or a resulting URL string and resulting URL record.

  1. Let encoding be document's character encoding, if document was given, and environment settings object's API URL character encoding otherwise.

  2. Let baseURL be document's base URL, if document was given, and environment settings object's API base URL otherwise.

  3. Let urlRecord be the result of applying the URL parser to url, with baseURL and encoding.

  4. If urlRecord is failure, then abort these steps with an error.

  5. Let urlString be the result of applying the URL serializer to urlRecord.

  6. Return urlString as the resulting URL string and urlRecord as the resulting URL record.

2.4.3 Dynamic changes to base URLs

When a document's document base URL changes, all elements in that document are affected by a base URL change.

The following are base URL change steps, which run when an element is affected by a base URL change (as defined by the DOM specification):

If the element creates a hyperlink

If the URL identified by the hyperlink is being shown to the user, or if any data derived from that URL is affecting the display, then the href attribute should be reparsed relative to the element's node document and the UI updated appropriately.

For example, the CSS :link/:visited pseudo-classes might have been affected.

If the hyperlink has a ping attribute and its URL(s) are being shown to the user, then the ping attribute's tokens should be reparsed relative to the element's node document and the UI updated appropriately.

If the element is a q, blockquote, ins, or del element with a cite attribute

If the URL identified by the cite attribute is being shown to the user, or if any data derived from that URL is affecting the display, then the URL should be reparsed relative to the element's node document and the UI updated appropriately.

そうでなければ

The element is not directly affected.

For instance, changing the base URL doesn't affect the image displayed by img elements, although subsequent accesses of the src IDL attribute from script will return a new absolute URL that might no longer correspond to the image being shown.

2.5 リソースを取得する

Spec bugs: 11235

2.5.1 用語

A response whose type is "basic", "cors", or "default" is CORS-same-origin. [FETCH]

A response whose type is "opaque" or "opaqueredirect" is CORS-cross-origin.

A response's unsafe response is its internal response if it has one, and the response itself otherwise.

To create a potential-CORS request, given a url, destination, corsAttributeState, and an optional same-origin fallback flag, run these steps:

  1. Let mode be "no-cors" if corsAttributeState is No CORS, and "cors" otherwise.

  2. If same-origin fallback flag is set and mode is "no-cors", set mode to "same-origin".

  3. Let credentialsMode be "include".

  4. If corsAttributeState is Anonymous, set credentialsMode to "same-origin".

  5. Let request be a new request whose url is url, destination is destination, mode is mode, credentials mode is credentialsMode, and whose use-URL-credentials flag is set.

2.5.2 Determining the type of a resource

The Content-Type metadata of a resource must be obtained and interpreted in a manner consistent with the requirements of the WHATWG MIME Sniffing standard. [MIMESNIFF]

The computed MIME type of a resource must be found in a manner consistent with the requirements given in the WHATWG MIME Sniffing standard. [MIMESNIFF]

The rules for sniffing images specifically, the rules for distinguishing if a resource is text or binary, and the rules for sniffing audio and video specifically are also defined in the WHATWG MIME Sniffing standard. These rules return a MIME type as their result. [MIMESNIFF]

It is imperative that the rules in the WHATWG MIME Sniffing standard be followed exactly. When a user agent uses different heuristics for content type detection than the server expects, security problems can occur. For more details, see the WHATWG MIME Sniffing standard. [MIMESNIFF]

2.5.3 Extracting character encodings from meta elements

The algorithm for extracting a character encoding from a meta element, given a string s, is as follows. It either returns a character encoding or nothing.

  1. Let position be a pointer into s, initially pointing at the start of the string.

  2. Loop: Find the first seven characters in s after position that are an ASCII case-insensitive match for the word "charset". If no such match is found, return nothing and abort these steps.

  3. Skip any ASCII whitespace that immediately follow the word "charset" (there might not be any).

  4. If the next character is not a U+003D EQUALS SIGN (=), then move position to point just before that next character, and jump back to the step labeled loop.

  5. Skip any ASCII whitespace that immediately follow the equals sign (there might not be any).

  6. Process the next character as follows:

    If it is a U+0022 QUOTATION MARK character (") and there is a later U+0022 QUOTATION MARK character (") in s
    If it is a U+0027 APOSTROPHE character (') and there is a later U+0027 APOSTROPHE character (') in s
    Return the result of getting an encoding from the substring that is between this character and the next earliest occurrence of this character.
    If it is an unmatched U+0022 QUOTATION MARK character (")
    If it is an unmatched U+0027 APOSTROPHE character (')
    If there is no next character
    Return nothing.
    そうでなければ
    Return the result of getting an encoding from the substring that consists of this character up to but not including the first ASCII whitespace or U+003B SEMICOLON character (;), or the end of s, whichever comes first.

This algorithm is distinct from those in the HTTP specification (for example, HTTP doesn't allow the use of single quotes and requires supporting a backslash-escape mechanism that is not supported by this algorithm). While the algorithm is used in contexts that, historically, were related to HTTP, the syntax as supported by implementations diverged some time ago. [HTTP]

2.5.4 CORS設定属性

CORS設定属性は、列挙属性である。次の表は、キーワードと属性の状態を示す。1列目のキーワードは、キーワードと同じ行で2列目のセル内の状態に対応づける。

キーワード 状態 概要
anonymous Anonymous 要素に対するリクエストは、"cors"に設定されるリクエストのモードおよび"same-origin"に設定されるリクエストの認証情報モードを持つ。
use-credentials Use Credentials 要素に対するリクエストは、"cors"に設定されるリクエストのモードおよび"include"に設定されるリクエストの認証情報モードを持つ。

空文字列も妥当なキーワードであり、匿名状態に対応づける。属性の不正な値のデフォルトは、匿名状態である。反射のために、匿名状態の正規ケースはanonymousキーワードである。属性が省略された場合に用いられる、欠損値のデフォルトは、No CORS状態である。

2.5.5 リファラーポリシー属性

リファラポリシー属性は、列挙属性である。空文字列を含む各リファラーポリシーは、同じ名前の状態にマッピングする、この属性のためのキーワードである。

属性の不正値のデフォルトおよび欠損値のデフォルトの両方は、空文字列状態である。

様々なフェッチの処理モデルにこの状態の影響は、WHATWG Fetch標準、およびReferrer Policyで、この仕様を通してより詳細に定義される。[FETCH] [REFERRERPOLICY]

複数の信号は、どの処理モデルが与えられるフェッチに使用されるかに寄与することができる。リファラポリシー属性はそのうちの一つである。一般に、この信号が処理される順序は次のとおり:

  1. まず、noreferrerリンクタイプの存在

  2. 次に、リファラーポリシー属性の値

  3. それからreferrerに設定されるnameをもつ任意のmeta要素の存在

  4. 最後に、`Referrer-Policy` HTTPヘッダー。

2.6 共通DOMインターフェイス

2.6.1 IDL属性におけるコンテンツ属性の反映

一部のIDL属性は、特定のコンテンツ属性の反映を定義する。これは、IDL属性がコンテンツ属性の現在値を返し、IDL属性が与えられた値にコンテンツ属性の値を変更することを意味する。

In general, on getting, if the content attribute is not present, the IDL attribute must act as if the content attribute's value is the empty string; and on setting, if the content attribute is not present, it must first be added.

If a reflecting IDL attribute is a USVString attribute whose content attribute is defined to contain a URL, then on getting, if the content attribute is absent, the IDL attribute must return the empty string. Otherwise, the IDL attribute must parse the value of the content attribute relative to the element's node document and if that is successful, return the resulting URL string. If parsing fails, then the value of the content attribute must be returned instead, converted to a USVString. On setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is an enumerated attribute, and the IDL attribute is limited to only known values, then, on getting, the IDL attribute must return the conforming value associated with the state the attribute is in (in its canonical case), if any, or the empty string if the attribute is in a state that has no associated keyword value or if the attribute is not in a defined state (e.g. the attribute is missing and there is no missing value default). On setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a nullable DOMString attribute whose content attribute is an enumerated attribute, then, on getting, if the corresponding content attribute is in its missing value default then the IDL attribute must return null, otherwise, the IDL attribute must return the conforming value associated with the state the attribute is in (in its canonical case). On setting, if the new value is null, the content attribute must be removed, and otherwise, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a DOMString or USVString attribute but doesn't fall into any of the above categories, then the getting and setting must be done in a transparent, case-preserving manner.

If a reflecting IDL attribute is an IDL enumeration attribute, then, on getting, if the corresponding content attribute's value case-sensitively matches one of the enumerated values, then the IDL attribute must return the content attribute's value; otherwise it must return the content attribute's default value. On setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a boolean attribute, then on getting the IDL attribute must return true if the content attribute is set, and false if it is absent. On setting, the content attribute must be removed if the IDL attribute is set to false, and must be set to the empty string if the IDL attribute is set to true. (This corresponds to the rules for boolean content attributes.)

If a reflecting IDL attribute has a signed integer type (long) then, on getting, the content attribute must be parsed according to the rules for parsing signed integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, then the default value must be returned instead, or 0 if there is no default value. On setting, the given value must be converted to the shortest possible string representing the number as a valid integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has a signed integer type (long) that is limited to only non-negative numbers then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or −1 if there is no default value. On setting, if the value is negative, the user agent must throw an "IndexSizeError" DOMException. Otherwise, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has an unsigned integer type (unsigned long) then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 0 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 0 if there is no default value. On setting, first, if the new value is in the range 0 to 2147483647, then let n be the new value, otherwise let n be the default value, or 0 if there is no default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and that string must be used as the new content attribute value.

If a reflecting IDL attribute has an unsigned integer type (unsigned long) that is limited to only non-negative numbers greater than zero, then the behavior is similar to the previous case, but zero is not allowed. On getting, the content attribute must first be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 1 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 1 if there is no default value. On setting, if the value is zero, the user agent must throw an "IndexSizeError" DOMException. Otherwise, first, if the new value is in the range 1 to 2147483647, then let n be the new value, otherwise let n be the default value, or 1 if there is no default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and that string must be used as the new content attribute value.

If a reflecting IDL attribute has an unsigned integer type (unsigned long) that is limited to only non-negative numbers greater than zero with fallback, then the behavior is similar to the previous case, but disallowed values are converted to the default value. On getting, the content attribute must first be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 1 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead. On setting, first, if the new value is in the range 1 to 2147483647, then let n be the new value, otherwise let n be the default value; then, n must be converted to the shortest possible string representing the number as a valid non-negative integer and that string must be used as the new content attribute value.

If a reflecting IDL attribute has a floating-point number type (double or unrestricted double), then, on getting, the content attribute must be parsed according to the rules for parsing floating-point number values, and if that is successful, the resulting value must be returned. If, on the other hand, it fails, or if the attribute is absent, the default value must be returned instead, or 0.0 if there is no default value. On setting, the given value must be converted to the best representation of the number as a floating-point number and then that string must be used as the new content attribute value.

If a reflecting IDL attribute has a floating-point number type (double or unrestricted double) that is limited to numbers greater than zero, then the behavior is similar to the previous case, but zero and negative values are not allowed. On getting, the content attribute must be parsed according to the rules for parsing floating-point number values, and if that is successful and the value is greater than 0.0, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 0.0 if there is no default value. On setting, if the value is less than or equal to zero, then the value must be ignored. Otherwise, the given value must be converted to the best representation of the number as a floating-point number and then that string must be used as the new content attribute value.

The values Infinity and Not-a-Number (NaN) values throw an exception on setting, as defined in the Web IDL specification. [WEBIDL]

If a reflecting IDL attribute has the type DOMTokenList, then on getting it must return a DOMTokenList object whose associated element is the element in question and whose associated attribute's local name is the name of the attribute in question.

If a reflecting IDL attribute has the type HTMLElement, or an interface that descends from HTMLElement, then, on getting, it must run the following algorithm (stopping at the first point where a value is returned):

  1. If the corresponding content attribute is absent, then the IDL attribute must return null.
  2. Let candidate be the element that the document.getElementById() method would find when called on the content attribute's element's node document if it were passed as its argument the current value of the corresponding content attribute.
  3. If candidate is null, or if it is not type-compatible with the IDL attribute, then the IDL attribute must return null.
  4. Otherwise, it must return candidate.

On setting, if the given element has an id attribute, and has the same tree as the element of the attribute being set, and the given element is the first element in that tree whose ID is the value of that id attribute, then the content attribute must be set to the value of that id attribute. Otherwise, the content attribute must be set to the empty string.

2.6.2 コレクション

HTMLFormControlsCollectionおよびHTMLOptionsCollectionインターフェイスは、HTMLCollectionインターフェイスから派生するコレクションである。HTMLAllCollectionインターフェイスはコレクションであるが、派生ではない。

2.6.2.1 HTMLAllCollectionインターフェイス

HTMLAllCollectionインターフェイスは、レガシーdocument.all属性に対して使用される。このインターフェイスは、HTMLCollectionと類似の動作をする。主な違いは、このインターフェイスが完全に最後には何かを返すことになるためにそのメソッドの驚くほどさまざまな異なる(不正)利用を可能にし、プロパティアクセスの代替としての機能として呼び出すことができることということである。

すべてのHTMLAllCollectionオブジェクトは、Documentでルート化され、すべての要素とマッチするフィルターを持つ。その結果HTMLAllCollectionオブジェクトのコレクションによって表される要素は、ルートDocumentのすべての子孫要素から成る。

[LegacyUnenumerableNamedProperties]
interface HTMLAllCollection {
  readonly attribute unsigned long length;
  getter Element? (unsigned long index);
  getter (HTMLCollection or Element)? namedItem(DOMString name);
  legacycaller (HTMLCollection or Element)? item(optional DOMString nameOrIndex);
};
collection . length

コレクションの要素数を返す。

element = collection . item(index)
element = collection(index)
element = collection[index]

ツリー順で決定される)コレクションからのインデックスindexとともにアイテムを返す。

element = collection . item(name)
collection = collection . item(name)
element = collection . namedItem(name)
collection = collection . namedItem(name)
element = collection(name)
collection = collection(name)
element = collection[name]
collection = collection[name]

コレクションからのIDまたは名前nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、それらの要素すべてを含むHTMLCollectionオブジェクトが返される。

ただしbuttonformiframeinputmapmetaobjectselectおよびtextarea要素は、このメソッドのために名前を持つことができる。 それらの名前はname属性値によって与えられる。

The object's supported property indices are as defined for HTMLCollection objects.

The supported property names consist of the non-empty values of all the id attributes of all the elements represented by the collection, and the non-empty values of all the name attributes of all the "all"-named elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

On getting, the length attribute must return the number of nodes represented by the collection.

The indexed property getter must return the result of getting the "all"-indexed element from this HTMLAllCollection given the passed index.

The namedItem(name) method must return the result of getting the "all"-named element(s) from this HTMLAllCollection given name.

The item(nameOrIndex) method (and the legacycaller behavior) must run the following steps:

  1. If nameOrIndex was not provided, return null.

  2. If nameOrIndex, converted to a JavaScript string value, is an array index property name, return the result of getting the "all"-indexed element from this HTMLAllCollection given the number represented by nameOrIndex.

  3. Return the result of getting the "all"-named element(s) from this HTMLAllCollection given nameOrIndex.


The following elements are "all"-named elements: a, applet, button, embed, form, frame, frameset, iframe, img, input, map, meta, object, select, and textarea

To get the "all"-indexed element from an HTMLAllCollection collection given an index index, return the indexth element in collection, or null if there is no such indexth element.

To get the "all"-named element(s) from an HTMLAllCollection collection given a name name, perform the following steps:

  1. If name is the empty string, return null.

  2. Let subCollection be an HTMLCollection object rooted at the same Document as collection, whose filter matches only elements that are either:

  3. If there is exactly one element in subCollection, then return that element.

  4. Otherwise, if subCollection is empty, return null.

  5. Otherwise, return subCollection.

2.6.2.2 HTMLFormControlsCollectionインターフェイス

HTMLFormControlsCollectionインターフェイスは、form要素で記載要素コレクションに使用される。

interface HTMLFormControlsCollection : HTMLCollection {
  // inherits length and item()
  getter (RadioNodeList or Element)? namedItem(DOMString name); // shadows inherited namedItem()
};

interface RadioNodeList : NodeList {
  attribute DOMString value;
};
collection . length

コレクションの要素数を返す。

element = collection . item(index)
element = collection[index]

コレクションからのインデックスindexとともにアイテムを返す。アイテムはツリー順にソートされる。

element = collection . namedItem(name)
radioNodeList = collection . namedItem(name)
element = collection[name]
radioNodeList = collection[name]

コレクションからのIDまたはname nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、それらの要素すべてを含むRadioNodeListオブジェクトが返される。

radioNodeList . value [ = value ]

オブジェクトによって表される最初にチェックされたラジオボタンの値を返す。

設定される場合、オブジェクトによって表される与えられた値を持つ最初のラジオボタンをチェックする。

The object's supported property indices are as defined for HTMLCollection objects.

The supported property names consist of the non-empty values of all the id and name attributes of all the elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

The namedItem(name) method must act according to the following algorithm:

  1. If name is the empty string, return null and stop the algorithm.
  2. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm.
  3. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm.
  4. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree order.
  5. Return that RadioNodeList object.

Members of the RadioNodeList interface inherited from the NodeList interface must behave as they would on a NodeList object.

The value IDL attribute on the RadioNodeList object, on getting, must return the value returned by running the following steps:

  1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose checkedness is true. Otherwise, let it be null.

  2. If element is null, return the empty string.

  3. If element is an element with no value attribute, return the string "on".

  4. Otherwise, return the value of element's value attribute.

On setting, the value IDL attribute must run the following steps:

  1. If the new value is the string "on": let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose value content attribute is either absent, or present and equal to the new value, if any. If no such element exists, then instead let element be null.

    Otherwise: let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. If no such element exists, then instead let element be null.

  2. If element is not null, then set its checkedness to true.

2.6.2.3 HTMLOptionsCollectionインターフェイス

HTMLOptionsCollectionインターフェイスは、option要素のコレクションに使用される。常にselect要素がルートであり、要素の子孫をコントロールする属性およびメソッドを持つ。

interface HTMLOptionsCollection : HTMLCollection {
  // inherits item(), namedItem()
  [CEReactions] attribute unsigned long length; // shadows inherited length
  [CEReactions] setter void (unsigned long index, HTMLOptionElement? option);
  [CEReactions] void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
  [CEReactions] void remove(long index);
  attribute long selectedIndex;
};
collection . length [ = value ]

コレクションの要素数を返す。

より小さい数に設定する場合、対応するコンテナ内のoption要素数は切り捨てられる。

より大きい数に設定する場合、そのコンテナに新しい空白のoption要素を追加する。

element = collection . item(index)
element = collection[index]

コレクションからのインデックスindexとともにアイテムを返す。アイテムはツリー順にソートされる。

collection[index] = element

indexがコレクションで項目の数より大きい数である場合、対応するコンテナで新しい空白のoption要素を追加する。

nullに設定する場合、コレクションからインデックスindexで項目を削除する。

option要素に設定する場合、コレクションからインデックスindexで追加または置換する。

element = collection . namedItem(name)
element = collection[name]

コレクションからのIDまたはname nameとともにアイテムを返す。

複数のマッチするアイテムが存在する場合、最初のものが返される。

collection . add(element [, before ] )

beforeによって与えられるノードの前の要素を挿入する。

before引数は数字でもよく、その場合elementはその数字をもつアイテムの前に挿入され、またはコレクションからの要素でもよい。その場合elementはその要素の前に挿入される。

beforeが省略された、null、または範囲外の数字の場合、elementはリストの最後に加えられるだろう。

elementに挿入された要素が親要素である場合、このメソッドは"HierarchyRequestError" DOMExceptionを投げる。

collection . remove(index)

コレクションからのインデックスindexをもつ項目を削除する。

collection . selectedIndex [ = value ]

もしあるならば、最初に選ばれたアイテムのインデックスを、または選択したアイテムが存在しない場合−1を返す。

選択を変更する設定が可能である。

The object's supported property indices are as defined for HTMLCollection objects.

On getting, the length attribute must return the number of nodes represented by the collection.

On setting, the behavior depends on whether the new value is equal to, greater than, or less than the number of nodes represented by the collection at that time. If the number is the same, then setting the attribute must do nothing. If the new value is greater, then n new option elements with no attributes and no child nodes must be appended to the select element on which the HTMLOptionsCollection is rooted, where n is the difference between the two numbers (new value minus old value). Mutation events must be fired as if a DocumentFragment containing the new option elements had been inserted. If the new value is lower, then the last n nodes in the collection must be removed from their parent nodes, where n is the difference between the two numbers (old value minus new value).

Setting length never removes or adds any optgroup elements, and never adds new children to existing optgroup elements (though it can remove children from them).

The supported property names consist of the non-empty values of all the id and name attributes of all the elements represented by the collection, in tree order, ignoring later duplicates, with the id of an element preceding its name if it contributes both, they differ from each other, and neither is the duplicate of an earlier entry.

When the user agent is to set the value of a new indexed property or set the value of an existing indexed property for a given property index index to a new value value, it must run the following algorithm:

  1. If value is null, invoke the steps for the remove method with index as the argument, and abort these steps.

  2. Let length be the number of nodes represented by the collection.

  3. Let n be index minus length.

  4. If n is greater than zero, then append a DocumentFragment consisting of n-1 new option elements with no attributes and no child nodes to the select element on which the HTMLOptionsCollection is rooted.

  5. If n is greater than or equal to zero, append value to the select element. Otherwise, replace the indexth element in the collection by value.

The add(element, before) method must act according to the following algorithm:

  1. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a "HierarchyRequestError" DOMException and abort these steps.

  2. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a "NotFoundError" DOMException and abort these steps.

  3. If element and before are the same element, then return and abort these steps.

  4. If before is a node, then let reference be that node. Otherwise, if before is an integer, and there is a beforeth node in the collection, let reference be that node. Otherwise, let reference be null.

  5. If reference is not null, let parent be the parent node of reference. Otherwise, let parent be the select element on which the HTMLOptionsCollection is rooted.

  6. Pre-insert element into parent node before reference.

The remove(index) method must act according to the following algorithm:

  1. If the number of nodes represented by the collection is zero, abort these steps.

  2. If index is not a number greater than or equal to 0 and less than the number of nodes represented by the collection, abort these steps.

  3. Let element be the indexth element in the collection.

  4. Remove element from its parent node.

The selectedIndex IDL attribute must act like the identically named attribute on the select element on which the HTMLOptionsCollection is rooted

2.6.3 The DOMStringList interface

The DOMStringList interface is a non-fashionable retro way of representing a list of strings.

[Exposed=(Window,Worker)]
interface DOMStringList {
  readonly attribute unsigned long length;
  getter DOMString? item(unsigned long index);
  boolean contains(DOMString string);
};

New APIs must use sequence<DOMString> or equivalent rather than DOMStringList.

strings . length

Returns the number of strings in strings.

strings[index]
strings . item(index)

Returns the string with index index from strings.

strings . contains(string)

Returns true if strings contains string, and false otherwise.

Each DOMStringList object has an associated list.

The supported property indices for a DOMStringList object are the numbers zero to the associated list's size minus one. If its associated list is empty, it has no supported property indices.

The length attribute's getter must this DOMStringList object's associated list's size.

The item(index) method, when invoked, must return the indexth item in this DOMStringList object's associated list, or null if index plus one is less than this DOMStringList object's associated list's size.

The contains(string) method, when invoked, must return true if this DOMStringList object's associated list contains string, and false otherwise.

2.6.4 Garbage collection

There is an implied strong reference from any IDL attribute that returns a pre-existing object to that object.

For example, the window.document attribute means that there is a strong reference from a Window object to its Document object. Similarly, there is always a strong reference from a Document to any descendant nodes, and from any node to its node document.

2.7 Safe passing of structured data

This section uses the terminology and typographic conventions from the JavaScript specification. [JAVASCRIPT]

2.7.1 Cloneable objects

Cloneable objects support being cloned across event loops. That is, they support being cloned across document and worker boundaries, including across documents of different origins. Not all objects are cloneable objects and not all aspects of objects that are cloneable objects are necessarily preserved when cloned.

Platform objects have the following internal method:

[[Clone]] ( targetRealm, memory )

Unless specified otherwise, invoking the [[Clone]]() internal method must throw a "DataCloneError" DOMException. (By default, platform objects are not cloneable objects.)

Platform objects that are cloneable objects have a [[Clone]]() internal method which is specified to run a series of steps. The result of running those steps must be a thrown exception or a clone of this, created in targetRealm. It is up such objects to define what cloning means for them.

Objects defined in the JavaScript specification are handled by the StructuredClone abstract operation directly.

2.7.2 Transferable objects

Transferable objects support being transferred across event loops. Transferring is effectively recreating the object while sharing a reference to the underlying data and then detaching the object being transferred. This is useful to transfer ownership of expensive resources. Not all objects are transferable objects and not all aspects of objects that are transferable objects are necessarily preserved when transferred.

Transferring is an irreversible and non-idempotent operation. Once an object has been transferred, it cannot be transferred, or indeed used, again.

Platform objects that are transferable objects have a [[Detached]] internal slot and the following internal method:

[[Transfer]]( targetRealm )

Whereas all platform objects have a [[Clone]]() internal method, not all have a [[Detached]] internal slot and a [[Transfer]]() internal method.

Platform objects that are transferable objects must define the [[Transfer]]() internal method such that it either throws an exception or returns a clone of this, created in targetRealm, with this's underlying data shared with the return value, and this's [[Detached]] internal slot value set to true. It is up to such objects to define what transferring means for them.

Objects defined in the JavaScript specification are handled by the StructuredCloneWithTransfer abstract operation directly. (Technically, by IsTransferable and Transfer.)

2.7.3 StructuredCloneWithTransfer ( input, transferList, targetRealm )

  1. Let memory be an empty map.

    The purpose of the memory map, both here and in the StructuredClone abstract operation, is to avoid cloning objects twice. This ends up preserving cycles and the identity of duplicate objects in graphs.

  2. For each object transferable in transferList:

    1. If IsTransferable(transferable) is false, then throw a "DataCloneError" DOMException.

    2. Let placeholder be a user-agent-defined placeholder object.

    3. Create an entry in memory with key transferable and value placeholder.

  3. Let clone be the result of ? StructuredClone(input, targetRealm, memory).

  4. Let outputTransferList be a new empty List.

  5. For each object transferable in transferList:

    1. Let placeholderResult be the value of the entry in memory whose key is transferable.

    2. Let transferResult be ? Transfer(transferable, targetRealm).

    3. Within clone, replace references to placeholderResult with transferResult, such that everything holding a reference to placeholderResult, now holds a reference to transferResult.

      This is a rather unusual low-level operation for which no primitives are defined by JavaScript.

    4. Add transferResult as the last element of outputTransferList.

  6. Return { [[Clone]]: clone, [[TransferList]]: outputTransferList }.

Originally the StructuredCloneWithTransfer abstract operation was known as the "structured clone" algorithm. The StructuredClone abstract operation was known as the "internal structured clone" algorithm. Transferring objects, now handled by the StructuredCloneWithTransfer abstract operation, were formerly handled by parts of the algorithm of the postMessage() method on the Window object and the postMessage() method on the MessagePort object.

2.7.4 StructuredClone ( input, targetRealm [ , memory ] )

  1. If memory was not supplied, let memory be an empty map.

  2. If memory contains an entry with key input, then return that entry's value.

  3. If Type(input) is Undefined, Null, Boolean, String, or Number, then return input.

  4. If Type(input) is Symbol, then throw a "DataCloneError" DOMException.

  5. Let deepClone be false.

  6. If input has a [[BooleanData]] internal slot, then let output be a new Boolean object in targetRealm whose [[BooleanData]] internal slot value is the [[BooleanData]] internal slot value of input.

  7. Otherwise, if input has a [[NumberData]] internal slot, then let output be a new Number object in targetRealm whose [[NumberData]] internal slot value is the [[NumberData]] internal slot value of input.

  8. Otherwise, if input has a [[StringData]] internal slot, then let output be a new String object in targetRealm whose [[StringData]] internal slot value is the [[StringData]] internal slot value of input.

  9. Otherwise, if input has a [[DateValue]] internal slot, then let output be a new Date object in targetRealm whose [[DateValue]] internal slot value is the [[DateValue]] internal slot value of input.

  10. Otherwise, if input has a [[RegExpMatcher]] internal slot, then let output be a new RegExp object in targetRealm whose [[RegExpMatcher]] internal slot value is the [[RegExpMatcher]] internal slot value of input, whose [[OriginalSource]] internal slot value is the [[OriginalSource]] internal slot value of input, and whose whose [[OriginalFlags]] internal slot value is the [[OriginalFlags]] internal slot value of input.

  11. Otherwise, if input has an [[ArrayBufferData]] internal slot, then:

    1. If IsDetachedBuffer(input) is true, then throw a "DataCloneError" DOMException.

    2. Let outputArrayBuffer be the %ArrayBuffer% intrinsic object in targetRealm.

    3. Let output be ? CloneArrayBuffer(input, 0, outputArrayBuffer).

  12. Otherwise, if input has a [[ViewedArrayBuffer]] internal slot, then:

    1. Let buffer be the value of input's [[ViewedArrayBuffer]] internal slot.

    2. Let bufferClone be ? StructuredClone(buffer, targetRealm, memory).

    3. If input has a [[DataView]] internal slot, then let output be a new DataView object in targetRealm whose [[DataView]] internal slot value is true, whose [[ViewedArrayBuffer]] internal slot value is bufferClone, whose [[ByteLength]] internal slot value is the [[ByteLength]] internal slot value of input, and whose [[ByteOffset]] internal slot value is the [[ByteOffset]] internal slot value of input.

    4. Otherwise:

      1. Assert: input has a [[TypedArrayName]] internal slot.

      2. Let constructor be the intrinsic object listed in column one of The TypedArray Constructors table for the value of input's [[TypedArrayName]] internal slot in targetRealm.

      3. Let byteOffset be input's [[ByteOffset]] internal slot value.

      4. Let length be input's [[ArrayLength]] internal slot value.

      5. Let output be ? TypedArrayCreate(constructor, « bufferClone, byteOffset, length »).

  13. Otherwise, if input has [[MapData]] internal slot, then:

    1. Let output be a new Map object in targetRealm whose [[MapData]] internal slot value is a new empty List.

    2. Set deepClone to true.

  14. Otherwise, if input has [[SetData]] internal slot, then:

    1. Let output be a new Set object in targetRealm whose [[SetData]] internal slot value is a new empty List.

    2. Set deepClone to true.

  15. Otherwise, if input is an Array exotic object, then:

    1. Let inputLen be OrdinaryGetOwnProperty(input, "length").[[Value]].

    2. Let outputProto be the %ArrayPrototype% intrinsic object in targetRealm.

    3. Let output be ! ArrayCreate(inputLen, outputProto).

    4. Set deepClone to true.

  16. Otherwise, if input has a [[Clone]]() internal method, then let output be ? input.[[Clone]](targetRealm, memory).

  17. Otherwise, if IsCallable(input) is true, then throw a "DataCloneError" DOMException.

  18. Otherwise, if input has any internal slot other than [[Prototype]] or [[Extensible]], then throw a "DataCloneError" DOMException.

    For instance, a [[PromiseState]] or [[WeakMapData]] internal slot.

  19. Otherwise, if input is an exotic object, then throw a "DataCloneError" DOMException.

    For instance, a proxy object.

  20. Otherwise:

    1. Let output be a new Object in targetRealm.

    2. Set deepClone to true.

  21. Create an entry in memory whose key is input and value is output.

  22. If deepClone is true, then:

    1. If input has a [[MapData]] internal slot, then:

      1. Let inputList the value of input's [[MapData]] internal slot.

      2. Let copiedList be a new empty List.

      3. Repeat for each Record { [[Key]], [[Value]] } entry that is an element of inputList,

        1. Let copiedEntry be a new Record { [[Key]]: entry.[[Key]], [[Value]]: entry.[[Value]] }.

        2. If copiedEntry.[[Key]] is not empty, append copiedEntry as the last element of copiedList.

      4. Let outputList be the value of output's [[MapData]] internal slot.

      5. For each Record { [[Key]], [[Value]] } entry that is an element of copiedList,

        1. Let outputKey be ? StructuredClone(entry.[[Key]], targetRealm, memory).

        2. Let outputValue be ? StructuredClone(entry.[[Value]], targetRealm, memory).

        3. Add { [[Key]]: outputKey, [[Value]]: outputValue } as the last element of outputList.

    2. Otherwise, if input has a [[SetData]] internal slot, then:

      1. Let copiedList be a copy of the value of input's [[SetData]] internal slot.

      2. Let outputList be the value of output's [[SetData]] internal slot.

      3. For each entry that is an element of copiedList that is not empty,

        1. Let outputEntry be ? StructuredClone(entry, targetResult, memory).

        2. Add outputEntry as the last element of outputList.

    3. Otherwise:

      1. Let enumerableKeys be a new empty List.

      2. For each key in ! input.[[OwnPropertyKeys]]():

        1. If Type(key) is String, then:

          1. Let inputDesc be ! input.[[GetOwnProperty]](key).

          2. If inputDesc.[[Enumerable]] is true, then add key as the last element of enumerableKeys.

      3. For each key in enumerableKeys:

        1. If ! HasOwnProperty(input, key) is true, then:

          1. Let inputValue be ? input.[[Get]](key, input).

          2. Let outputValue be ? StructuredClone(inputValue, targetRealm, memory).

          3. Perform ? CreateDataProperty(output, key, outputValue).

      The key collection performed above is very similar to the JavaScript specification's EnumerableOwnProperties operation, but crucially it uses the deterministic ordering provided by the [[OwnPropertyKeys]] internal method, instead of reordering the keys in an unspecified manner as EnumerableOwnProperties does. [JAVASCRIPT]

  23. Return output.

In general implementations will need to use some kind of serialization and marshalling to implement the creation of objects in targetRealm, as targetRealm could be in a different event loop and not easily accessible to the code that invokes StructuredCloneWithTransfer or StructuredClone.

2.7.5 IsTransferable ( O )

  1. Assert: Type(O) is Object.

  2. If O has an [[ArrayBufferData]] internal slot, then:

    1. If IsDetachedBuffer(O) is true, then return false.

    2. Return true.

  3. Otherwise, if O has a [[Detached]] internal slot, then:

    1. If O's [[Detached]] internal slot value is true, then return false.

    2. Return true.

  4. Return false.

2.7.6 Transfer ( input, targetRealm )

  1. If input has an [[ArrayBufferData]] internal slot, then:

    1. Let output be a new ArrayBuffer object in targetRealm whose [[ArrayBufferByteLength]] internal slot value is the [[ArrayBufferByteLength]] internal slot value of input, and whose [[ArrayBufferData]] internal slot value is the [[ArrayBufferData]] internal slot value of input.

    2. Perform ! DetachArrayBuffer(input).

    3. Return output.

  2. Return ? input.[[Transfer]](targetRealm).

2.7.7 Performing structured clones from other specifications

Other specifications may use the StructuredClone, StructuredCloneWithTransfer, IsTransferable, and Transfer abstract operations.

In general, call sites may pass in Web IDL values instead of JavaScript values; this is to be understood to perform an implicit conversion to the JavaScript value before invoking these algorithms.

Call sites that are not invoked as a result of author code synchronously calling into a user agent method must take care to properly prepare to run script and prepare to run a callback before invoking these abstract operations, if they are being performed on arbitrary objects. This is necessary because the StructuredClone operation can invoke author-defined accessors as part of its final deep-cloning steps, and these accessors could call into operations that rely on the entry and incumbent concepts being properly set up.

postMessage performs StructuredCloneWithTransfer on its arguments, but is careful to do so immediately, inside the synchronous portion of its algorithm. Thus it is able to use the structured cloning algorithms without needing to prepare to run script and prepare to run a callback.

Parsing URLs can happen at a variety of times that are not the synchronous result of author code. However, the URL parser only applies StructuredClone to Blob objects, so it is not in danger of running author code with incorrect entry and incumbent values, and thus it too does not need to perform these preparation steps.

In contrast, a hypothetical API that used StructuredClone to serialize some author-supplied object periodically, directly from a task on the event loop, would need to ensure it performs the appropriate preparations before calling into the structured clone algorithms. As of this time, we know of no such APIs on the platform; usually it is simpler to perform the clone ahead of time, as a synchronous consequence of author code, like postMessage.

2.7.8 Monkey patch for Blob and FileList objects

This monkey patch will be removed in due course. See w3c/FileAPI issue 32.

Blob objects are cloneable objects.

Each Blob object's [[Clone]](targetRealm, memory) internal method must run these steps:

  1. If this is closed, then throw a "DataCloneError" DOMException.

  2. Return a new instance of this in targetRealm, corresponding to the same underlying data.

FileList objects are cloneable objects.

Each FileList object's [[Clone]](targetRealm, memory) internal method must run these steps:

  1. Let output be a new FileList object in targetRealm.

  2. For each file in this, add ? StructuredClone(file, targetRealm, memory) to the end of the list of File objects of output.

  3. Return output.