HTML — HTML 文書の書き方

13. ~HTMLの構文

注記: この節は、 `~HTML~MIME型$とされた資源に対する規則のみを述べる。 ~XML資源に対する規則は、 § ~XML構文 にて論じられる。 ◎ This section only describes the rules for resources labeled with an HTML MIME type. Rules for XML resources are discussed in the section below entitled "The XML syntax".

13.1. ~HTML文書の書き方

この節が適用されるのは[ 文書 / 著作~tool /~markup生成器 ]に限られ、 特に,適合性~検査器には適用されない — 適合性~検査器は、 § ~HTML文書の構文解析-法 に与える要件を利用するモノトスル。 ◎ This section only applies to documents, authoring tools, and markup generators. In particular, it does not apply to conformance checkers; conformance checkers must use the requirements given in the next section ("parsing HTML documents").

【 この節における “書く( `write^en )” は、 生成器, 等の~programから “書き出す” ことも含まれる。 】

文書は、 次に与える順の各部からなっていなければナラナイ: ◎ Documents must consist of the following parts, in the given order:

  1. 0 〜 1 個の `FEFF^U `BYTE ORDER MARK^cn ( BOM ) ◎ Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.
  2. 0 個以上の[ `~comment$ / `~ASCII空白$ ] ◎ Any number of comments and ASCII whitespace.
  3. `~DOCTYPE$ ◎ A DOCTYPE.
  4. 0 個以上の[ `~comment$ / `~ASCII空白$ ] ◎ Any number of comments and ASCII whitespace.
  5. `html$e `要素$の形をとる`文書~要素$ ◎ The document element, in the form of an html element.
  6. 0 個以上の[ `~comment$ / `~ASCII空白$ ] ◎ Any number of comments and ASCII whitespace.

上に言及した各種~内容については、 以下の少数の節にて述べる。 ◎ The various types of content mentioned above are described in the next few sections.

加えて、 `文字~符号化法~宣言$を直列化する方法にも制約があり, その論題をとりあげる節にて論じられる。 ◎ In addition, there are some restrictions on how character encoding declarations are to be serialized, as discussed in the section on that topic.

注記: [ `html$e 要素の前 / `html$e 要素の内側の始端 / `head$e 要素の前 ]にある`~ASCII空白$は、 文書の構文解析-時には落とされることになる。 一方で, `html$e 要素より`後に^emある`~ASCII空白$は、 `body$e 要素の終端にあったかのように構文解析される。 したがって、 `文書~要素$の前後にある`~ASCII空白$は,往復しない†。 ◎ ASCII whitespace before the html element, at the start of the html element and before the head element, will be dropped when the document is parsed; ASCII whitespace after the html element will be parsed as if it were at the end of the body element. Thus, ASCII whitespace around the document element does not round-trip.

【 “往復する( `round-trip^en )” とは、 構文解析してから再び直列化されても(あるいはその逆をしても),元のまま保たれることを意味する。 】

次に挙げるものに対しては、 その後に改行文字を挿入することが示唆される:

  • ~DOCTYPE
  • 文書~要素の前にある~comment
  • `html$e 要素の開始~tag
  • `html$e 要素の内側にあって, `head$e 要素の前にある~comment

【 ~HTMLにおける文書~要素は `html^e 要素に他ならない (が、そのような `html^e 要素は一つに限られる)。 】

◎ It is suggested that newlines be inserted after the DOCTYPE, after any comments that are before the document element, after the html element's start tag (if it is not omitted), and after any comments that are inside the html element but before the head element.

~HTML構文における多くの文字列(例:要素の名前や属性)は、 `~ASCII英大文字$と`~ASCII英小文字$に限り,文字大小は区別されない。 この節では、 これを簡便に “文字大小無視( `case-insensitive^en )” と称する。 ◎ Many strings in the HTML syntax (e.g. the names of elements and their attributes) are case-insensitive, but only for ASCII upper alphas and ASCII lower alphas. For convenience, in this section this is just referred to as "case-insensitive".

【 と,原文には記されているが、 この訳では一律に “~ASCII大小無視” と記すことにする (さして簡便にならないので)。 】

13.1.1. ~DOCTYPE

`~DOCTYPE@ は、 要求される “前置き” である。 ◎ A DOCTYPE is a required preamble.

注記: ~DOCTYPEは、 旧来の理由から要求される。 省略された場合、 ~browserは,[ 何らかの仕様と互換でない,異なる具現化~mode ]を利用する傾向にある。 文書~内に~DOCTYPEを含めておけば、[ ~browserは,最善な労をもって関連な仕様に従う ]ことが確保される。 ◎ DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.

~DOCTYPEは、 次に与える順の文字~並びでなければナラナイ: ◎ A DOCTYPE must consist of the following components, in this order:

  1. `~ASCII大小無視$で `<!DOCTYPE^l に合致する文字列 ◎ A string that is an ASCII case-insensitive match for the string "<!DOCTYPE".
  2. 1 個以上の`~ASCII空白$ ◎ One or more ASCII whitespace.
  3. `~ASCII大小無視$で `html^l に合致する文字列 ◎ A string that is an ASCII case-insensitive match for the string "html".
  4. 0 個( “短い~DOCTYPE” )または 1 個の`~DOCTYPE旧来~文字列$ ◎ Optionally, a DOCTYPE legacy string.
  5. 0 個以上の`~ASCII空白$ ◎ Zero or more ASCII whitespace.
  6. `003E^U `>^smb ◎ A U+003E GREATER-THAN SIGN character (>).

注記: 言い換えれば、 ~ASCII大小無視で `<!DOCTYPE html>^l に合致する文字列。 ◎ In other words, <!DOCTYPE html>, case-insensitively.


上の “短い~DOCTYPE” による~HTML~markupを出力できない~HTML生成器の目的においては、 ~DOCTYPEの中に `~DOCTYPE旧来~文字列@ ( `DOCTYPE legacy string^en )を挿入してもヨイ(上で定義した位置に)。 この文字列は、 次に与える順の文字~並びでなければナラナイ: ◎ For the purposes of HTML generators that cannot output HTML markup with the short DOCTYPE "<!DOCTYPE html>", a DOCTYPE legacy string may be inserted into the DOCTYPE (in the position defined above). This string must consist of:

  1. 1 個以上の`~ASCII空白$ ◎ One or more ASCII whitespace.
  2. `~ASCII大小無視$で `SYSTEM^l に合致する文字列 ◎ A string that is an ASCII case-insensitive match for the string "SYSTEM".
  3. 1 個以上の`~ASCII空白$ ◎ One or more ASCII whitespace.
  4. [ ❝" / ❝' ]( `引用符^i ) ◎ A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the quote mark).
  5. ~literal文字列 "`~about_legacy-compat$" ◎ The literal string "about:legacy-compat".
  6. 2 つ前に挙げた `引用符^i と同じ文字 ◎ A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled quote mark).

注記: 言い換えれば、 次のいずれかに,引用符で括られた部分は一致し, 他の部分は~ASCII大小無視で合致する ⇒# `<!DOCTYPE html SYSTEM "about:legacy-compat">^c / `<!DOCTYPE html SYSTEM 'about:legacy-compat'>^c ◎ In other words, <!DOCTYPE html SYSTEM "about:legacy-compat"> or <!DOCTYPE html SYSTEM 'about:legacy-compat'>, case-insensitively except for the part in single or double quotes.

`~DOCTYPE旧来~文字列$は、[ “短い~DOCTYPE” を出力できない~systemで生成される文書 ]を除き,利用するベキでない。 ◎ The DOCTYPE legacy string should not be used unless the document is generated from a system that cannot output the shorter string.

13.1.2. 要素

`要素@ ( `element^en )は、 次に挙げる 6 種に分けられる: ◎ There are six different kinds of elements: void elements, the template element, raw text elements, escapable raw text elements, foreign elements, and normal elements.

`~void要素@ ( `void element^en ) ◎ Void elements
`area$e, `base$e, `br$e, `col$e, `embed$e, `hr$e, `img$e, `input$e, `link$e, `meta$e, `source$e, `track$e, `wbr$e
`~template要素@ ( `template element^en ) ◎ The template element
`template$e
`生~text要素@ ( `raw text element^en ) ◎ Raw text elements
`script$e, `style$e
`~escape可能な生~text要素@ ( `escapable raw text element^en ) ◎ Escapable raw text elements
`textarea$e, `title$e
`外来な要素@ ( `foreign element^en ) ◎ Foreign elements
[ `~MathML名前空間$ / `~SVG名前空間$ ]に属する要素 ◎ Elements from the MathML namespace and the SVG namespace.
`通常の要素@ ( `normal element^en ) ◎ Normal elements
許容される他のすべての`~HTML要素$ ◎ All other allowed HTML elements are normal elements.

`~tag@ ( `tag^en )は、 ~markupにおいて要素の始端と終端を区切るために利用される: ◎ Tags are used to delimit the start and end of elements in the markup.\

  • [ `生~text要素$ / `~escape可能な生~text要素$ / `通常の要素$ ]には、 その[ 始端を指示する`開始~tag$, 終端を指示する`終了~tag$ ]がある。 ◎ Raw text, escapable raw text, and normal elements have a start tag to indicate where they begin, and an end tag to indicate where they end.\
  • ある種の`通常の要素$の[ 開始~tag/終了~tag ]は、 § 省略可能な~tagにて述べるとおり, `省略-$できる。 省略できないものは、 省略してはナラナイ。 ◎ The start and end tags of certain normal elements can be omitted, as described below in the section on optional tags. Those that cannot be omitted must not be omitted.\
  • `~void要素$には、 開始~tagしかない — 終了~tagを指定してはナラナイ。 ◎ Void elements only have a start tag; end tags must not be specified for void elements.\
  • `外来な要素$は、 開始~tagを省略してはナラナイ — その開始~tagが ⇒# `自己閉じ$である場合,終了~tagは省略しなければナラナイ/ `自己閉じ$でない場合,終了~tagを省略してはナラナイ ◎ Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag.

要素の`内容$は、 開始~tagの直後から終了~tagの直前までの合間に置かなければナラナイ (どちらの~tagも,ある種の事例では黙示され得る)。 個々の要素に許容される正確な内容は、 この仕様の他所に述べたとおり,要素の`内容~model$に依存する。 要素は、 その内容~modelに許容されない内容を包含してはナラナイ。 加えて、 上に挙げた 5 種の要素には追加的な`構文-要件^emもある。 ◎ The contents of the element must be placed between just after the start tag (which might be implied, in certain cases) and just before the end tag (which again, might be implied in certain cases). The exact allowed contents of each individual element depend on the content model of that element, as described earlier in this specification. Elements must not contain content that their content model disallows. In addition to the restrictions placed on the contents by those content models, however, the five types of elements have additional syntactic requirements.

`~void要素$は、 内容を有し得ない (終了~tagは無いので、 開始~tagと終了~tagの合間に置ける内容は無い)。 ◎ Void elements can't have any contents (since there's no end tag, no content can be put between the start tag and the end tag).

`~template要素$は`~template内容$を有し得るが, `template$e 要素~自身の子にはならない。 そのような`~template内容$は、 当の要素が属する`文書$【!main Document】に干渉するのを避けるよう,[ どの`閲覧~文脈$にも属さない,異なる`文書$ ]に結付けられた`文書片$内に格納される。 `template$e 要素を成す`~template内容$用の~markupは、 (他の要素と同じく) `template$e 要素の開始~tagの直後から終了~tagの直前までに置かれる — それらは,どのような[ `~text$, `文字~参照$, `要素$, `~comment$ ]からなってもヨイ — ただし、 ~textは[ 文字 `003C^U `<^smb /`多義的~ampersand$ ]を包含してはナラナイ。 ◎ The template element can have template contents, but such template contents are not children of the template element itself. Instead, they are stored in a DocumentFragment associated with a different Document — without a browsing context — so as to avoid the template contents interfering with the main Document. The ; for the template contents of a template element is placed just after the template element's start tag and just before template element's end tag (as with other elements), and may consist of any text, character references, elements, and comments, but the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand.

`生~text要素$は、 `~text$を内容に有し得る。 また、 下に述べる制約もある。 ◎ Raw text elements can have text, though it has restrictions described below.

`~escape可能な生~text要素$は、[ `~text$, `文字~参照$ ]を内容に有し得る — ただし、 ~textは`多義的~ampersand$を包含してはナラナイ。 また、 下に述べる制約もある。 ◎ Escapable raw text elements can have text and character references, but the text must not contain an ambiguous ampersand. There are also further restrictions described below.

`外来な要素$のうち,開始~tagが`自己閉じ$とされたものは、 内容を有し得ない (これも,終了~tagは無いので、 開始~tagと終了~tagの合間に置ける内容はない)。 他の`外来な要素$は、[ `~text$, `文字~参照$, `~CDATAsec$, 他の`要素$, `~comment$ ]を内容に有し得る — ただし、 ~textは[ 文字`003C^U `<^smb / `多義的~ampersand$ ]を包含してはナラナイ。 ◎ Foreign elements whose start tag is marked as self-closing can't have any contents (since, again, as there's no end tag, no content can be put between the start tag and the end tag). Foreign elements whose start tag is not marked as self-closing can have text, character references, CDATA sections, other elements, and comments, but the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand.

注記: ~HTML構文は、 `外来な要素$においても,名前空間~宣言を~supportしない。 ◎ The HTML syntax does not support namespace declarations, even in foreign elements.

一例として、 次の~HTML素片を考える: ◎ For instance, consider the following HTML fragment:

`element-1^xCode

最も内縁の要素 `cdr:license^e は、 実際には ~SVG名前空間に属する — ~XMLと違って, `xmlns:cdr^l 属性の効果はないので。 上の素片~内の~commentが言ってるように、 この素片は,実際には適合していない。 `SVG 2^cite は、 ~SVG名前空間~内に `cdr:license^l と称される要素は定義しないので。 ◎ The innermost element, cdr:license, is actually in the SVG namespace, as the "xmlns:cdr" attribute has no effect (unlike in XML). In fact, as the comment in the fragment above says, the fragment is actually non-conforming. This is because SVG 2 does not define any elements called "cdr:license" in the SVG namespace.

`通常の要素$は、[ `~text$, `文字~参照$, 他の`要素$, `~comment$ ]を内容に有し得る — ただし、 ~textは[ 文字`003C^U `<^smb / `多義的~ampersand$ ]を包含してはナラナイ。 一部の`通常の要素$には、 許容される内容について,[ 内容~modelにより課される制約 / この段落に述べた制約 ]を超えるような制約が,他にもある。 ◎ Normal elements can have text, character references, other elements, and comments, but the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand. Some normal elements also have yet more restrictions on what content they are allowed to hold, beyond the restrictions imposed by the content model and those described in this paragraph. Those restrictions are described below.

各~tagは、 要素の名前を与える `~tag名@ ( `tag name^en )を包含する。 【`~custom要素$を除く】どの~HTML要素も、 その名前は`~ASCII英数字$のみからなる。 ~HTML構文においては、 ~tag名は,`外来な要素$に対しても`~ASCII大小無視$である — すなわち、 すべてを小文字~化した結果が要素の~tag名に合致する限り,小文字, 大文字を混ぜて書いてもヨイ。 ◎ Tags contain a tag name, giving the element's name. HTML elements all have names that only use ASCII alphanumerics. In the HTML syntax, tag names, even those for foreign elements, may be written with any mix of lower- and uppercase letters that, when converted to all-lowercase, matches the element's tag name; tag names are case-insensitive.

13.1.2.1. 開始~tag

`開始~tag@ ( `start tag^en )は、 次に与える順の文字~並びでなければナラナイ: ◎ Start tags must have the following format:

  1. `003C^U `<^smb ◎ The first character of a start tag must be a U+003C LESS-THAN SIGN character (<).
  2. 要素の`~tag名$を与える文字~並び ◎ The next few characters of a start tag must be the element's tag name.
  3. (属性たちを与える,) 0 個以上の[ 次に与える順の文字~並び ]:

    1. 1 個以上の`~ASCII空白$
    2. 1 個の属性 — そのための構文は下に述べる
    ◎ If there are to be any attributes in the next step, there must first be one or more ASCII whitespace. ◎ Then, the start tag may have a number of attributes, the syntax for which is described below. Attributes must be separated from each other by one or more ASCII whitespace.
  4. 0 個以上の`~ASCII空白$ — ただし,場合によっては、 最後の属性に 1 個以上の~ASCII空白を後続させることが要求される。 下の § 属性 を見よ。 ◎ After the attributes, or after the tag name if there are no attributes, there may be one or more ASCII whitespace. (Some attributes are required to be followed by a space. See the attributes section below.)
  5. [ `~void要素$/`外来な要素$ ]である場合に限り, 0 〜 1 個の ❝/ — この文字を与えた場合: ◎ Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/), which\

    • `外来な要素$に対しては、 当の開始~tagを `自己閉じ@ ( `self-closing^en )にする。 ◎ on foreign elements marks the start tag as self-closing.\
    • `~void要素$に対しては、 当の開始~tagを`自己閉じ$にすることはない — それは不必要であり,いかなる種類の効果も無い。 この文字は、 ~void要素~用には,~~用心して利用するベキである — とりわけ,直前に引用符無しの属性~値がある場合、 構文解析器により破棄されず,当の属性~値の一部を成すようになるので。 ◎ On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.
  6. `003E^U `>^smb ◎ Finally, start tags must be closed by a U+003E GREATER-THAN SIGN character (>).
13.1.2.2. 終了~tag

`終了~tag@ ( `end tag^en )は、 次に与える順の文字~並びでなければナラナイ: ◎ End tags must have the following format:

  1. `003C^U `<^smb ◎ The first character of an end tag must be a U+003C LESS-THAN SIGN character (<).
  2. ❝/ ◎ The second character of an end tag must be a U+002F SOLIDUS character (/).
  3. 要素の`~tag名$を与える文字~並び ◎ The next few characters of an end tag must be the element's tag name.
  4. 0 個以上の`~ASCII空白$ ◎ After the tag name, there may be one or more ASCII whitespace.
  5. `003E^U `>^smb ◎ Finally, end tags must be closed by a U+003E GREATER-THAN SIGN character (>).
13.1.2.3. 属性

要素の `属性@ ( `attribute^en )は、 要素の開始~tagの内側にて表出される。 各 属性は、 名前と値を持つ: ◎ Attributes for an element are expressed inside the element's start tag. Attributes have a name and a value.\

`属性~名@ ( `attribute name^en ) ◎ Attribute names\
1 個以上の[ 次に挙げるもの以外の文字 ]からなっていなければナラナイ ⇒# `制御文字$, `0020^U `SPACE^cn, ❝", ❝', `003E^U `>^smb, ❝/, ❝=, `非文字$ ◎ must consist of one or more characters other than controls, U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=), and noncharacters.\
~HTML構文においては、 属性~名は — `外来な要素$であっても — [ `~ASCII英小文字$, `~ASCII英大文字$ ]を混ぜて書いてもヨイ。 ◎ In the HTML syntax, attribute names, even those for foreign elements, may be written with any mix of ASCII lower and ASCII upper alphas.
`属性~値@ ( `attribute value^en ) ◎ Attribute values\
`~text$と`文字~参照$の混在 — ただし、 ~textは`多義的~ampersand$を包含できない。 ◎ are a mixture of text and character references, except with the additional restriction that the text cannot contain an ambiguous ampersand.

属性は、 次の 4 通りの仕方で指定できる: ◎ Attributes can be specified in four different ways:

空~属性~構文 ◎ Empty attribute syntax
`属性~名$のみ。 値は、 暗黙的に空~文字列になる。 ◎ Just the attribute name. The value is implicitly the empty string.

次の例の `disabled$a 属性は、 空~属性~構文で与えられている: ◎ In the following example, the disabled attribute is given with the empty attribute syntax:

`attribute-1^xCode
◎ ↓If an attribute using the empty attribute syntax is to be followed by another attribute, then there must be ASCII whitespace separating the two.
引用符無しの属性~値~構文 ◎ Unquoted attribute value syntax

次に与える順の文字~並び:

  1. `属性~名$
  2. 0 個以上の`~ASCII空白$
  3. ❝=
  4. 0 個以上の`~ASCII空白$
  5. 空でない`属性~値$であって,次に挙げる文字は包含しないもの ⇒# `~ASCII空白$, ❝", ❝', ❝=, `003C^U `<^smb, `003E^U `>^smb, ❝`
◎ The attribute name, followed by zero or more ASCII whitespace, followed by a single U+003D EQUALS SIGN character, followed by zero or more ASCII whitespace, followed by the attribute value, which, in addition to the requirements given above for attribute values, must not contain any literal ASCII whitespace, any U+0022 QUOTATION MARK characters ("), U+0027 APOSTROPHE characters ('), U+003D EQUALS SIGN characters (=), U+003C LESS-THAN SIGN characters (<), U+003E GREATER-THAN SIGN characters (>), or U+0060 GRAVE ACCENT characters (`), and must not be the empty string.

次の例の `value$a 属性は、 引用符無しの属性~値~構文で与えられている: ◎ In the following example, the value attribute is given with the unquoted attribute value syntax:

`attribute-2^xCode
この属性~構文を利用している属性に,[ `開始~tag$構文の[ `~void要素$/`自己閉じ$ ]に許容される省略可能な ❝/ ]が後続する場合、 その 2 つは`~ASCII空白$で分離しなければナラナイ。 ◎ If an attribute using the unquoted attribute syntax is to be followed by another attribute or by the optional U+002F SOLIDUS character (/) allowed in step 6 of the start tag syntax above, then there must be ASCII whitespace separating the two. ↓
一重引用符付き属性~値~構文 ◎ Single-quoted attribute value syntax

次に与える順の文字~並び:

  1. `属性~名$
  2. 0 個以上の`~ASCII空白$
  3. ❝=
  4. 0 個以上の`~ASCII空白$
  5. ❝'
  6. `属性~値$の要件を満たす文字列であって,~literal ❝' を包含しないもの
  7. ❝'
◎ The attribute name, followed by zero or more ASCII whitespace, followed by a single U+003D EQUALS SIGN character, followed by zero or more ASCII whitespace, followed by a single U+0027 APOSTROPHE character ('), followed by the attribute value, which, in addition to the requirements given above for attribute values, must not contain any literal U+0027 APOSTROPHE characters ('), and finally followed by a second single U+0027 APOSTROPHE character (').

次の例の `type$a 属性は、 一重引用符付き属性~値~構文で与えられている: ◎ In the following example, the type attribute is given with the single-quoted attribute value syntax:

`attribute-3^xCode
◎ ↓If an attribute using the single-quoted attribute syntax is to be followed by another attribute, then there must be ASCII whitespace separating the two.
二重引用符付き属性~値~構文 ◎ Double-quoted attribute value syntax

次に与える順の文字~並び:

  1. `属性~名$
  2. 0 個以上の`~ASCII空白$
  3. ❝=
  4. 0 個以上の`~ASCII空白$
  5. ❝"
  6. `属性~値$の要件を満たす文字列であって,~literal ❝" を包含しないもの
  7. ❝"
◎ The attribute name, followed by zero or more ASCII whitespace, followed by a single U+003D EQUALS SIGN character, followed by zero or more ASCII whitespace, followed by a single U+0022 QUOTATION MARK character ("), followed by the attribute value, which, in addition to the requirements given above for attribute values, must not contain any literal U+0022 QUOTATION MARK characters ("), and finally followed by a second single U+0022 QUOTATION MARK character (").

次の例の `name$a 属性は、 二重引用符付き属性~値~構文で与えられている: ◎ In the following example, the name attribute is given with the double-quoted attribute value syntax:

`attribute-4^xCode
◎ ↓If an attribute using the double-quoted attribute syntax is to be followed by another attribute, then there must be ASCII whitespace separating the two.

同じ開始~tag内にある複数の属性は:

  • 利用する属性~構文が何であれ、 `~ASCII空白$で互いに分離しなければナラナイ。
  • 互いの名前は`~ASCII大小無視$で合致してはナラナイ。
◎ ↑ ◎ There must never be two or more attributes on the same start tag whose names are an ASCII case-insensitive match for each other.

`外来な要素$が有する名前空間付き属性のうち,次の表tを成す いずれかの行の ( 1 列目, 2 列目 ) に与える ( 局所~名, 名前空間 ) を持つものは、 同じ行の 3 列目に与える名前として書かなければナラナイ。 ◎ When a foreign element has one of the namespaced attributes given by the local name and namespace of the first and second cells of a row from the following table, it must be written using the name given by the third cell from the same row.

局所~名 名前空間 属性~名
`actuate^a `~XLink名前空間$ `xlink:actuate^a
`arcrole^a `~XLink名前空間$ `xlink:arcrole^a
`href^a `~XLink名前空間$ `xlink:href^a
`role^a `~XLink名前空間$ `xlink:role^a
`show^a `~XLink名前空間$ `xlink:show^a
`title^a `~XLink名前空間$ `xlink:title^a
`type^a `~XLink名前空間$ `xlink:type^a
`lang^a `~XML名前空間$ `xml:lang^a
`space^a `~XML名前空間$ `xml:space^a
`xmlns^a `~XMLNS名前空間$ `xmlns^a
`xlink^a `~XMLNS名前空間$ `xmlns:xlink^a

`~HTML構文$においては、 他の名前空間付き属性は表出できない。 ◎ No other namespaced attribute can be expressed in the HTML syntax.

注記: 上の表t内の属性が適合するかどうかは、 他の仕様(例: `SVG 2^cite / `MathML^cite )にて定義される。 この節は、 これらの属性が~HTML構文を利用して直列化された場合の構文~規則のみを述べる。 ◎ Whether the attributes in the table above are conforming or not is defined by other specifications (e.g. SVG 2 and MathML); this section only describes the syntax rules if the attributes are serialized using the HTML syntax.

13.1.2.4. 省略可能な~tag

ある種の~tagは `省略-@ ( `omit^en )できる。 ◎ Certain tags can be omitted.

注記: 下に述べる状況において,要素の`開始~tag$を省略しても、 要素が無いことを意味するものではない。 それは黙示されるが,依然としてそこにある。 例えば,~HTML文書には、 根 `html$e 要素は常にある — 文字列 `<html>^l が~markup内のどこにも現れなくても。 ◎ Omitting an element's start tag in the situations described below does not mean the element is not present; it is implied, but it is still there. For example, an HTML document always has a root html element, even if the string <html> doesn't appear anywhere in the markup.

所与の要素の `直後の同胞@ は、 要素の親~内で要素の直後に現れる内容を指すとする — 要素~自身が親~内の最後の内容ならば無い。 【この用語は、以下を簡潔に述べるために,この訳に導入している(用いるのはこの節のみ)】

`html$e 要素の`開始~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ 内側にある最初のものは`~comment$でない ◎ An html element's start tag may be omitted if the first thing inside the html element is not a comment.

例えば次の事例では、 `<html>^l ~tagを除去してもかまわない: ◎ For example, in the following case it's ok to remove the "<html>" tag:

`optional-html-1^xCode

そうした結果の文書は、 次の様になる: ◎ Doing so would make the document look like this:

`optional-html-2^xCode

これは、 前と正確に同じ~DOMになる。 特に、 構文解析器は,`文書~要素$の前後にある空白を無視することに注意。 次の例でも,正確に同じ~DOMが得られることになる: ◎ This has the exact same DOM. In particular, note that whitespace around the document element is ignored by the parser. The following example would also have the exact same DOM:

`optional-html-3^xCode

しかしながら,次の例では、 開始~tagを除去すると,~commentは `html$e 要素の前に移動する: ◎ However, in the following example, removing the start tag moves the comment to before the html element:

`optional-html-4^xCode

~tagが除去されたなら、 文書は実際には次と同じに転化される: ◎ With the tag removed, the document actually turns into the same as this:

`optional-html-5^xCode

これが、 ~commentが後続しない場合に限り,~tagを除去できるわけである: ~commentがある場合、 ~tagを除去すると,文書を構文解析した結果の~treeは変化する。 もちろん,~commentの位置が~~問題にならないなら、 ~tagは省略できる — ~commentは、 先ず開始~tagの前に移動されたかのようになる。 ◎ This is why the tag can only be removed if it is not followed by a comment: removing the tag when there is a comment there changes the document's resulting parse tree. Of course, if the position of the comment does not matter, then the tag can be omitted, as if the comment had been moved to before the start tag in the first place.

`html$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または`~comment$でない ◎ An html element's end tag may be omitted if the html element is not immediately followed by a comment.

`head$e 要素の`開始~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ 内側にある最初のものは、 無い(要素は空), または要素である ◎ A head element's start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.

`head$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `~ASCII空白$/`~comment$ ]でない ◎ A head element's end tag may be omitted if the head element is not immediately followed by ASCII whitespace or a comment.

`body$e 要素の`開始~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ 内側にある最初のものは、 無い(要素は空), または次のいずれでもない ⇒ `~ASCII空白$/`~comment$/次に挙げる要素 ⇒ `meta$e / `noscript$e / `link$e / `script$e / `style$e / `template$e ◎ A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not ASCII whitespace or a comment, except if the first thing inside the body element is a meta, noscript, link, script, style, or template element.

`body$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または`~comment$でない ◎ A body element's end tag may be omitted if the body element is not immediately followed by a comment.

上の例において、[ `head$e 要素の開始~tagと終了~tag / `body$e 要素の開始~tag ]は省略できないことに注意 — それらの前/後には空白があるので: ◎ Note that in the example above, the head element start and end tags, and the body element start tag, can't be omitted, because they are surrounded by whitespace:

`optional-body-1^xCode

( `body$e / `html$e 要素の終了~tagは、 ~~問題無く省略できる — それらの後に空白があろうが, `body$e 要素の中にあるものとして構文解析されるので。) ◎ (The body and html element end tags could be omitted without trouble; any spaces after those get parsed into the body element anyway.)

しかしながら,通例的には、 空白は~~問題にならない。 あらかじめ空白を除去してもかまわない: ◎ Usually, however, whitespace isn't an issue. If we first remove the whitespace we don't care about:

`optional-body-2^xCode

~DOMに影響することなく,いくつかの~tagを省略できる: ◎ Then we can omit a number of tags without affecting the DOM:

`optional-body-3^xCode

さらに、 空白を追加し直すこともできる: ◎ At that point, we can also add some whitespace back:

`optional-body-4^xCode

これは、 次の文書に等価になる — 省略された~tagは、 構文解析器により黙示される位置に示されている。 結果の空白~text~nodeは、 `head$e 要素の内側の終端にある改行文字のみになる: ◎ This would be equivalent to this document, with the omitted tags shown in their parser-implied positions; the only whitespace text node that results from this is the newline at the end of the head element:

`optional-body-5^xCode

`li$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または `li$e 要素である ◎ An li element's end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.

`dt$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `dt$e / `dd$e ]要素である ◎ A dt element's end tag may be omitted if the dt element is immediately followed by another dt element or a dd element.

`dd$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `dd$e / `dt$e ]要素である ◎ A dd element's end tag may be omitted if the dd element is immediately followed by another dd element or a dt element, or if there is no more content in the parent element.

`p$e 要素の`終了~tag$は、 要素が ~OR↓ を満たすならば省略してもヨイ:

  • `直後の同胞$は、 次に挙げるいずれかの要素である ⇒ `address$e / `article$e / `aside$e / `blockquote$e / `details$e / `div$e / `dl$e / `fieldset$e / `figcaption$e / `figure$e / `footer$e / `form$e / `h6$e / `h6$e / `h6$e / `h6$e / `h6$e / `h6$e / `header$e / `hgroup$e / `hr$e / `main$e / `menu$e / `nav$e / `ol$e / `p$e / `pre$e / `search$e / `section$e / `table$e / `ul$e
  • [ `直後の同胞$は無い ]~AND[ 親は[ `自律的~custom要素$ / 次に挙げるもの以外の`~HTML要素$ ]である ] ⇒ `a$e / `audio$e / `del$e / `ins$e / `map$e / `noscript$e / `video$e
◎ A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, search, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.

したがって,先に掲げた例は、 次の様に更に単純~化できる: ◎ We can thus simplify the earlier example further:

`optional-p-1^xCode

`rt$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `rt$e / `rp$e ]要素である ◎ An rt element's end tag may be omitted if the rt element is immediately followed by an rt or rp element, or if there is no more content in the parent element.

`rp$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `rt$e / `rp$e ]要素である ◎ An rp element's end tag may be omitted if the rp element is immediately followed by an rt or rp element, or if there is no more content in the parent element.

`optgroup$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `optgroup$e / `hr$e ]要素である ◎ An optgroup element's end tag may be omitted if the optgroup element is immediately followed by another optgroup element, if it is immediately followed by an hr element, or if there is no more content in the parent element.

`option$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `option$e / `optgroup$e / `hr$e ]要素である ◎ An option element's end tag may be omitted if the option element is immediately followed by another option element, if it is immediately followed by an optgroup element, if it is immediately followed by an hr element, or if there is no more content in the parent element.

`colgroup$e 要素の`開始~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ [ 内側にある最初のものは `col$e 要素である ]~AND[ 直前に[ `終了~tag$が省略された 別の `colgroup$e 要素 ]は無い ] (要素は空である場合、省略できない。) ◎ A colgroup element's start tag may be omitted if the first thing inside the colgroup element is a col element, and if the element is not immediately preceded by another colgroup element whose end tag has been omitted. (It can't be omitted if the element is empty.)

`colgroup$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `~ASCII空白$/`~comment$ ]でない ◎ A colgroup element's end tag may be omitted if the colgroup element is not immediately followed by ASCII whitespace or a comment.

`caption$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `~ASCII空白$/`~comment$ ]でない ◎ A caption element's end tag may be omitted if the caption element is not immediately followed by ASCII whitespace or a comment.

`thead$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、[ `tbody$e / `tfoot$e ]要素である ◎ A thead element's end tag may be omitted if the thead element is immediately followed by a tbody or tfoot element.

`tbody$e 要素の`開始~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ [ 内側にある最初のものは `tr$e 要素である ]~AND[ 直前に[ `終了~tag$が省略された[ `tbody$e / `thead$e / `tfoot$e ]要素 ]はない ] (要素は空である場合、省略できない。) ◎ A tbody element's start tag may be omitted if the first thing inside the tbody element is a tr element, and if the element is not immediately preceded by a tbody, thead, or tfoot element whose end tag has been omitted. (It can't be omitted if the element is empty.)

`tbody$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `tbody$e / `tfoot$e ]要素である ◎ A tbody element's end tag may be omitted if the tbody element is immediately followed by a tbody or tfoot element, or if there is no more content in the parent element.

`tfoot$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い ◎ A tfoot element's end tag may be omitted if there is no more content in the parent element.

`tr$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `tr$e 要素 ]である ◎ A tr element's end tag may be omitted if the tr element is immediately followed by another tr element, or if there is no more content in the parent element.

`td$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `td$e / `th$e ]要素である ◎ A td element's end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.

`th$e 要素の`終了~tag$は、 要素が次を満たすならば省略してもヨイ ⇒ `直後の同胞$は、 無い, または[ `td$e / `th$e ]要素である ◎ A th element's end tag may be omitted if the th element is immediately followed by a td or th element, or if there is no more content in the parent element.

これらの,~tableに関係する~tagを省略する能を用いれば、 ~table~markupはかなり簡素になる。 例えば次の~markupに対しては: ◎ The ability to omit all these table-related tags makes table markup much terser. ◎ Take this example:

`optional-table-1^xCode

次の様に~mark-upしても、 空白の有無の相違を除き,正確に同じ~tableになる: ◎ The exact same table, modulo some whitespace differences, could be marked up as follows:

`optional-table-2^xCode

この仕方により,~cellが占める場所はかなり減るので、 各~rowを一行にまとめて,さらに簡素にできる: ◎ Since the cells take up much less room this way, this can be made even terser by having each row on one line:

`optional-table-3^xCode

これらの~tableの間の,~DOM~levelにおける唯一の相違は、 (いずれの事例でも意味論的に無色な)空白の精確な位置になる。 ◎ The only differences between these tables, at the DOM level, is with the precise position of the (in any case semantically-neutral) whitespace.

しかしながら、 何らかの属性を有する`開始~tag$は,決して省略してはナラナイ。 ◎ However, a start tag must never be omitted if it has any attributes.

先に掲げた、 すべての空白, すべての省略可能な~tagが除去された例に戻って: ◎ Returning to the earlier example with all the whitespace removed and then all the optional tags removed:

`optional-attr-1^xCode

この例にて, `body$e 要素は `class$a 属性を有していて, `html$e 要素は `lang$a 属性を有していた場合、 ~markupは次のようになる: ◎ If the body element in this example had to have a class attribute and the html element had to have a lang attribute, the markup would have to become:

`optional-attr-2^xCode

注記: この節は、 当の文書は適合している — 特に,`内容~model$に対する違反は無い — ものと見做している。 文書がこの仕様に述べた`内容~model$に適合しない場合、 文書~内の~tagを この節にて述べた流儀で省略した結果は, 予期されない~DOMの相違をもたらす見込みが高い (内容~modelは、 ある程度,これを避けるよう設計されている)。 ◎ This section assumes that the document is conforming, in particular, that there are no content model violations. Omitting tags in the fashion described in this section in a document that does not conform to the content models described in this specification is likely to result in unexpected DOM differences (this is, in part, what the content models are designed to avoid).

13.1.2.5. 内容~modelに課される制約

歴史的な理由から、 ある種の要素には,その内容~modelに与えた制約を超える制約が更にある。 ◎ For historical reasons, certain elements have extra restrictions beyond even the restrictions given by their content model.

`table$e 要素は、 `tr$e 要素を~~直に包含してはナラナイ — `tr$e 要素は、 形上では,この仕様に述べた内容~modelに則って `table$e 要素の内側に許容されているが。 (~markup内で `tr$e 要素が `table$e の内側に~~直に置かれた場合、 その前に `tbody$e 開始~tagを黙示することになる。) ◎ A table element must not contain tr elements, even though these elements are technically allowed inside table elements according to the content models described in this specification. (If a tr element is put inside a table in the markup, it will in fact imply a tbody start tag before it.)

[ `pre$e / `textarea$e ]要素の`開始~tag$の直後には、 1 個の`改行文字$を置いてもヨイ。 これは、 要素の処理に影響しない — すなわち,要素の内容には含まれない。 これ以外の後続の`改行文字$は、 要素の内容に`含める^emモノトスル (さもなければ、 内容~内の頭部の改行文字は,省略可能な改行文字の様に扱われ, 無視されることになるので)。 ◎ A single newline may be placed immediately after the start tag of pre and textarea elements. This does not affect the processing of the element. The otherwise optional newline must be included if the element's contents themselves start with a newline (because otherwise the leading newline in the contents would be treated like the optional newline, and ignored).

次の 2 個の `pre$e ~blockは、 等価になる: ◎ The following two pre blocks are equivalent:

`content-1^xCode `content-2^xCode
13.1.2.6. 生~text要素/~escape可能な生~text要素の内容に課される制約

[ `生~text要素$/`~escape可能な生~text要素$ ] %要素 内の~textは、 次に与える順の文字~並びを包含してはナラナイ:

  1. `003C^U `<^smb
  2. ❝/
  3. %要素 の~tag名に`~ASCII大小無視$で合致する文字~並び
  4. `~ASCII空白$ / `003E^U `>^smb / ❝/
◎ The text in raw text and escapable raw text elements must not contain any occurrences of the string "</" (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that case-insensitively match the tag name of the element followed by one of U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), U+000D CARRIAGE RETURN (CR), U+0020 SPACE, U+003E GREATER-THAN SIGN (>), or U+002F SOLIDUS (/).

13.1.3. ~text

`~text@ ( `text^en )は、[ `要素$/ `属性~値$ / `~comment$ ]の内側に許容される。 加えて,他の節にて述べられるとおり、 ~textが置かれる所に基づいて,[ ~text内に何が許容され, 何が許容されないか ]についての拘束が更に課される。 ◎ Text is allowed inside elements, attribute values, and comments. Extra constraints are placed on what is and what is not allowed in text based on where the text is to be put, as described in the other sections.

13.1.3.1. 改行文字

~HTMLにおける `改行文字@ ( `newline^en )は、 次のいずれかとして表現してもヨイ:

  • `000D^U `CARRIAGE RETURN^cn (略称 `CR^cn )
  • `000A^U `LINE FEED^cn (略称 `LF^cn )
  • 次に与える順の文字~並び:

    1. `000D^U `CR^cn
    2. `000A^U `LF^cn
◎ Newlines in HTML may be represented either as U+000D CARRIAGE RETURN (CR) characters, U+000A LINE FEED (LF) characters, or pairs of U+000D CARRIAGE RETURN (CR), U+000A LINE FEED (LF) characters in that order.

`文字~参照$が許容される所では、 `000A^U `LF^cn を表す文字~参照も`改行文字$を表現する(が、 `000D^U `CR^cn 表す文字~参照はそうでない)。 ◎ Where character references are allowed, a character reference of a U+000A LINE FEED (LF) character (but not a U+000D CARRIAGE RETURN (CR) character) also represents a newline.

13.1.4. 文字~参照

他の節にて述べたある種の事例においては、 `~text$には `文字~参照@ ( `character reference^en )を混ぜてもヨイ。 これを利用すれば、 さもなければ`~text$内に合法に含めれない文字を~escapeできる。 ◎ In certain cases described in other sections, text may be mixed with character references. These can be used to escape characters that couldn't otherwise legally be included in text.

文字~参照は、 `0026^U `&^smb から開始され,次の 3 種いずれかが後続していなければナラナイ: ◎ Character references must start with a U+0026 AMPERSAND character (&). Following this, there are three possible kinds of character references:

有名~文字~参照: ◎ Named character references

次に与える順の文字~並び:

  1. § `有名~文字~参照$に与えるいずれかの名前(文字大小は区別される)
  2. ❝;
◎ The ampersand must be followed by one of the names given in the named character references section, using the same case. The name must be one that is terminated by a U+003B SEMICOLON character (;).
10 進~数量-文字~参照: ◎ Decimal numeric character reference

次に与える順の文字~並び:

  1. ❝#
  2. 1 個以上の`~ASCII数字$からなる並びであって,[ 下の定義に則って許容される符号位置 ]に対応する基数 10 の整数を表現するもの
  3. ❝;
◎ The ampersand must be followed by a U+0023 NUMBER SIGN character (#), followed by one or more ASCII digits, representing a base-ten integer that corresponds to a code point that is allowed according to the definition below. The digits must then be followed by a U+003B SEMICOLON character (;).
16 進~数量-文字~参照: ◎ Hexadecimal numeric character reference

次に与える順の文字~並び:

  1. ❝#
  2. [ ❝x / ❝X ]
  3. 1 個以上の`~ASCII~hex数字$からなる並びであって,[ 下の定義に則って許容される符号位置 ]に対応する基数 16 の整数を表現するもの
  4. ❝;
◎ The ampersand must be followed by a U+0023 NUMBER SIGN character (#), which must be followed by either a U+0078 LATIN SMALL LETTER X character (x) or a U+0058 LATIN CAPITAL LETTER X character (X), which must then be followed by one or more ASCII hex digits, representing a hexadecimal integer that corresponds to a code point that is allowed according to the definition below. The digits must then be followed by a U+003B SEMICOLON character (;).

上に述べた[ 数量-文字~参照 ]の形では、 次を除く符号位置を参照することが許容される ⇒# `000D^U `CR^cn / `非文字$ / `~ASCII空白$以外の`制御文字$ ◎ The numeric character reference forms described above are allowed to reference any code point excluding U+000D CR, noncharacters, and controls other than ASCII whitespace.

`0026^U `&^smb は、 次に与える順の文字~並びが後続するならば, `多義的~ampersand@ ( `ambiguous ampersand^en )とされる:

  1. 1 個以上の`~ASCII英数字$からなる並びであって, § `有名~文字~参照$に与えるどの名前にも合致しないもの
  2. ❝;
◎ An ambiguous ampersand is a U+0026 AMPERSAND character (&) that is followed by one or more ASCII alphanumerics, followed by a U+003B SEMICOLON character (;), where these characters do not match any of the names given in the named character references section.

13.1.5. ~CDATAsec

`~CDATAsec@ ( `CDATA section^en )は、 次に与える順の文字~並びでなければナラナイ: ◎ CDATA sections must consist of the following components, in this order:

  1. 文字列 `<![CDATA[^l ◎ The string "<![CDATA[".
  2. 0 〜 1 個の[ `~text$であって,文字列 `]]>^l を包含しないもの ] ◎ Optionally, text, with the additional restriction that the text must not contain the string "]]>".
  3. 文字列 `]]>^l ◎ The string "]]>".

~CDATAsecを利用できるのは、 外来な内容(~MathML/~SVG)内に限られる。 この例では、 ~CDATAsecを利用して,~MathML `ms$e 要素の内容を~escapeしている: ◎ CDATA sections can only be used in foreign content (MathML or SVG). In this example, a CDATA section is used to escape the contents of a MathML ms element:

`CDATA-1^xCode

13.1.6. ~comment

`~comment@ ( `comment^en )は、 次に与える順の文字~並びでなければナラナイ: ◎ Comments must have the following format:

  1. 文字列 `<!--^l ◎ The string "<!--".
  2. ~AND↓ を満たす`~text$:

    • `>^l から開始しない
    • `->^l から開始しない
    • `<!--^l を包含しない
    • `-->^l を包含しない
    • `--!>^l を包含しない
    • `<!-^l で終端しない

    (特に,空~文字列はこれらを満たす)

    ◎ Optionally, text, with the additional restriction that the text must not start with the string ">", nor start with the string "->", nor contain the strings "<!--", "-->", or "--!>", nor end with the string "<!-".
  3. 文字列 `-->^l ◎ The string "-->".

注記: `~text$は、 文字列 `<!^l で終端することは許容される — 次の様に:

`comments-1^xCode ◎ The text is allowed to end with the string "<!", as in <!--My favorite operators are > and <!-->.

13.2. ~HTML文書の構文解析-法

【 この節の内容は、 別~pageにて。 】

13.3. ~HTML素片の直列化-法

以下の~algoの目的において, `~voidとして直列化する要素@ とは、 次に挙げる要素~型の総称である ⇒# `~void要素$, `basefont$e, `bgsound$e, `frame$e, `keygen$e, `param$e ◎ For the purposes of the following algorithm, an element serializes as void if its element type is one of the void elements, or is basefont, bgsound, frame, keygen, or param.

`~HTML素片~直列化~algo@ は、 所与の ⇒# [ `Element$I / `Document$I / `DocumentFragment$I ]~node %~node, 真偽値 %可能なら~shadow根を直列化するか, `~shadow根$たちが成す~list【!sequence<ShadowRoot>】 %~shadow根~群 ◎終 に対し,文字列を返す: ◎ The following steps form the HTML fragment serialization algorithm. The algorithm takes as input a DOM Element, Document, or DocumentFragment referred to as the node, a boolean serializableShadowRoots, and a sequence<ShadowRoot> shadowRoots, and returns a string.

注記: この~algoは、 %~node 自身ではなく,その`子~群$を直列化する。 ◎ This algorithm serializes the children of the node being serialized, not the node itself.

  1. ~IF[ %~node は`~voidとして直列化する要素$である ] ⇒ ~RET 空~文字列 ◎ If the node serializes as void, then return the empty string.
  2. %結果 ~LET 空~文字列 ◎ Let s be a string, and initialize it to the empty string.
  3. ~IF[ %~node は `template$e 要素である ] ⇒ %~node ~SET %~node の`~template内容$( `DocumentFragment$I ~node ) ◎ If the node is a template element, then let the node instead be the template element's template contents (a DocumentFragment node).
  4. ~IF[ %~node【!current node】 は`~shadow~host$である ]: ◎ If current node is a shadow host, then:

    1. %~shadow根 ~LET %~node の`~shadow根$el ◎ Let shadow be current node's shadow root.
    2. ~IF[ %~shadow根 ~IN %~shadow根~群 ]~OR[ ~AND↓ ]…

      • %可能なら~shadow根を直列化するか ~EQ ~T
      • %~shadow根 の`直列化-可能か$sR ~EQ ~T

      …ならば:

      ◎ If one of the following is true: • serializableShadowRoots is true and shadow's serializable is true; or • shadowRoots contains shadow, ◎ then:
      1. %結果 に次を順に付加する ⇒# `<template shadowrootmode="^l, %~shadow根 の`~mode$sR( ~IN { `open^l, `closed^l } ), `"^l ◎ Append "<template shadowrootmode="". ◎ If shadow's mode is "open", then append "open". Otherwise, append "closed". ◎ Append """.
      2. ~IF[ %~shadow根 の`~focusを委任するか$sR ~EQ ~T ] ⇒ %結果 に ` shadowrootdelegatesfocus=""^l を付加する ◎ If shadow's delegates focus is set, then append " shadowrootdelegatesfocus=""".
      3. ~IF[ %~shadow根 の`直列化-可能か$sR【!Serializable:~HTMLcloning#serializable】 ~EQ ~T ] ⇒ %結果 に ` shadowrootserializable=""^l を付加する ◎ If shadow's serializable is set, then append " shadowrootserializable=""".
      4. ~IF[ %~shadow根 の`~clone可能か$sR ~EQ ~T ] ⇒ %結果 に ` shadowrootclonable=""^l を付加する ◎ If shadow's clonable is set, then append " shadowrootclonable=""".
      5. %結果 に `>^l を付加する ◎ Append ">".
      6. %結果 に次の結果を付加する ⇒ `~HTML素片~直列化~algo$( ↓ ) 【!(thus recursing into ...】 ⇒# %~shadow根, %可能なら~shadow根を直列化するか, %~shadow根~群 ◎ Append the value of running the HTML fragment serialization algorithm with shadow, serializableShadowRoots, and shadowRoots (thus recursing into this algorithm for that element).
      7. %結果 に `</template>^l を付加する ◎ Append "</template>".
  5. %~node の`子~群$を成す ~EACH( %子~node ) に対し【!`~tree順序$で(不要)】 ⇒ %結果 に次の結果を付加する ⇒ 下に定義する `~nodeを直列化する手続き^i( ↓ ) ⇒# %子~node, %可能なら~shadow根を直列化するか, %~shadow根~群 ◎ For each child node of the node, in tree order, run the following steps: ◎ Let current node be the child node being processed. ◎ Append the appropriate string from the following list to s:
  6. ~RET %結果 ◎ ↓↓

`~nodeを直列化する手続き^i は、 所与の ⇒# %~node, %可能なら~shadow根を直列化するか, %~shadow根~群 ◎終 に対し, %~node が実装する~interfaceに応じて: ◎ ↑

`Element$I ◎ If current node is an Element
  1. %結果 ~LET 空~文字列 ◎ ↓
  2. %~tag名 ~LET [ %~node は[ `~HTML名前空間$ / `~MathML名前空間$ / `~SVG名前空間$ ]に属するならば %~node の局所~名 / ~ELSE_ %~node の有修飾~名 ] ◎ If current node is an element in the HTML namespace, the MathML namespace, or the SVG namespace, then let tagname be current node's local name. Otherwise, let tagname be current node's qualified name.
  3. %結果 に `003C^U `<^smb を付加する ◎ ↓
  4. %結果 に %~tag名 を付加する ◎ Append a U+003C LESS-THAN SIGN character (<), followed by tagname.

    注記: [ `~HTML構文解析器$ / `createElement()$m ]により作成された`~HTML要素$に対しては、 %~tag名 は小文字になる。 ◎ For HTML elements created by the HTML parser or createElement(), tagname will be lowercase.

  5. ~IF[ %~node の`~is0値$ ~NEQ ~NULL ]~AND[ %~node は `is$a 属性を有さない ] ⇒ %結果 に次に与える文字~並びを順に付加する:

    1. ` is="^l
    2. `文字列を~escapeする$( %~node の`~is0値$, `属性~用^i )
    3. `0022^U `"^smb
    ◎ If current node's is value is not null, and the element does not have an is attribute in its attribute list, then append the string " is="", followed by current node's is value escaped as described below in attribute mode, followed by a U+0022 QUOTATION MARK character (").
  6. %~node が有する ~EACH( 属性 %属性 ) に対し ⇒ %結果 に次に与える文字~並びを順に付加する:

    1. `0020^U `SPACE^cn
    2. %属性 の`直列形の名前$
    3. ❝=
    4. ❝"
    5. `文字列を~escapeする$( %属性 の値, `属性~用^i )
    6. ❝"
    ◎ For each attribute that the element has, append a U+0020 SPACE character, the attribute's serialized name as described below, a U+003D EQUALS SIGN character (=), a U+0022 QUOTATION MARK character ("), the attribute's value, escaped as described below in attribute mode, and a second U+0022 QUOTATION MARK character (").

    この段の目的における %属性 の `直列形の名前@ は、 %属性 が属する名前空間に応じて,次を返すモノトスル: ◎ An attribute's serialized name for the purposes of the previous paragraph must be determined as follows:

    なし ◎ If the attribute has no namespace
    %属性 の局所~名 ◎ The attribute's serialized name is the attribute's local name.
    注記: `~HTML要素$において,[ `~HTML構文解析器$ / `setAttribute()$m ]により設定された属性に対しては、 局所~名は小文字になる。 ◎ For attributes on HTML elements set by the HTML parser or by setAttribute(), the local name will be lowercase.
    `~XML名前空間$ ◎ If the attribute is in the XML namespace

    次に与える順の文字~並び:

    1. 文字列 `xml:^l
    2. %属性 の局所~名
    ◎ The attribute's serialized name is the string "xml:" followed by the attribute's local name.
    `~XMLNS名前空間$ ◎ ↓

    %属性 の局所~名 ~EQ `xmlns^c ならば 文字列 `xmlns^l / ~ELSE_ 次に与える順の文字~並び:

    1. 文字列 `xmlns:^l
    2. %属性 の局所~名
    ◎ If the attribute is in the XMLNS namespace and the attribute's local name is xmlns ◎ The attribute's serialized name is the string "xmlns". ◎ If the attribute is in the XMLNS namespace and the attribute's local name is not xmlns ◎ The attribute's serialized name is the string "xmlns:" followed by the attribute's local name.
    `~XLink名前空間$ ◎ If the attribute is in the XLink namespace

    次に与える順の文字~並び:

    1. 文字列 `xlink:^l
    2. %属性 の局所~名
    ◎ The attribute's serialized name is the string "xlink:" followed by the attribute's local name.
    その他の名前空間 ◎ If the attribute is in some other namespace
    %属性 の有修飾~名 ◎ The attribute's serialized name is the attribute's qualified name.

    属性たちの正確な順序は`実装定義$であり,元の~markupにて属性が与えられた順序などの要因にも依存し得るが、 ~sort順序は,安定的 — すなわち、 要素に対しこの~algoを続けて呼出しても,属性たちが直列化される順序は同じ — にするモノトスル。 ◎ While the exact order of attributes is implementation-defined, and may depend on factors such as the order that the attributes were given in the original markup, the sort order must be stable, such that consecutive invocations of this algorithm serialize an element's attributes in the same order.

  7. %結果 に `003E^U `>^smb を付加する ◎ Append a U+003E GREATER-THAN SIGN character (>).
  8. ~IF[ %~node は`~voidとして直列化する要素$である ] ⇒ ~RET %結果 ◎ If current node serializes as void, then continue on to the next child node at this point.
  9. %結果 に次の結果を付加する ⇒ `~HTML素片~直列化~algo$( ↓ ) 【!(thus recursing into ...】 ⇒# %~node, %可能なら~shadow根を直列化するか, %~shadow根~群 ◎ Append the value of running the HTML fragment serialization algorithm with current node, serializableShadowRoots, and shadowRoots (thus recursing into this algorithm for that node),\
  10. %結果 に次に与える順の文字~並びを付加する:

    1. `003C^U `<^smb
    2. ❝/
    3. %~tag名
    4. `003E^U `>^smb
    ◎ followed by a U+003C LESS-THAN SIGN character (<), a U+002F SOLIDUS character (/), tagname again, and finally a U+003E GREATER-THAN SIGN character (>).
  11. ~RET %結果 ◎ ↑
`Text$I ◎ If current node is a Text node
  1. %data ~LET %~node の`~data$cd
  2. ~IF[ %~node の親は[ `style$e / `script$e / `xmp$e / `iframe$e / `noembed$e / `noframes$e / `plaintext$e ]要素である ] ⇒ ~RET %data
  3. ~IF[ %~node の親は `noscript$e 要素である ]~AND[ %~node 用の`~scriptingは可能化されて$いる ] ⇒ ~RET %data
  4. ~RET `文字列を~escapeする$( %data )
◎ If the parent of current node is a style, script, xmp, iframe, noembed, noframes, or plaintext element, or if the parent of current node is a noscript element and scripting is enabled for the node, then append the value of current node's data literally. ◎ Otherwise, append the value of current node's data, escaped as described below.
`Comment$I ◎ If current node is a Comment

~RET 次に与える順の文字~並び

  1. `003C^U `<^smb
  2. ❝!
  3. ❝-
  4. ❝-
  5. %~node の`~data$cd
  6. ❝-
  7. ❝-
  8. `003E^U `>^smb
◎ Append "<!--" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS), followed by the value of current node's data, followed by the literal string "-->" (U+002D HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN).
`ProcessingInstruction$I ◎ If current node is a ProcessingInstruction

~RET 次に与える順の文字~並び:

  1. `003C^U `<^smb
  2. ❝?
  3. %~node の`~target$pI【!`target^m ~IDL属性の値】
  4. `0020^U `SPACE^cn
  5. %~node の`~data$cd
  6. `003E^U `>^smb
◎ Append "<?" (U+003C LESS-THAN SIGN, U+003F QUESTION MARK), followed by the value of current node's target IDL attribute, followed by a single U+0020 SPACE character, followed by the value of current node's data, followed by a single U+003E GREATER-THAN SIGN character (>).
`DocumentType$I ◎ If current node is a DocumentType

~RET 次に与える順の文字~並び:

  1. `003C^U `<^smb
  2. ❝!
  3. ❝D
  4. ❝O
  5. ❝C
  6. ❝T
  7. ❝Y
  8. ❝P
  9. ❝E
  10. `0020^U `SPACE^cn
  11. %~node の`名前$dT
  12. `003E^U `>^smb
◎ Append "<!DOCTYPE" (U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+0044 LATIN CAPITAL LETTER D, U+004F LATIN CAPITAL LETTER O, U+0043 LATIN CAPITAL LETTER C, U+0054 LATIN CAPITAL LETTER T, U+0059 LATIN CAPITAL LETTER Y, U+0050 LATIN CAPITAL LETTER P, U+0045 LATIN CAPITAL LETTER E), followed by a space (U+0020 SPACE), followed by the value of current node's name, followed by ">" (U+003E GREATER-THAN SIGN).

◎ Return s.

`~HTML素片~直列化~algo$の出力を`~HTML構文解析器$で構文解析した結果は、 元の~tree構造にならない~~可能性もある。 直列化して構文解析し直す段を往復しないような~tree構造は、 `~HTML構文解析器$ 自身からも生産され得る — そのような事例は、 概して,適合していないが。 ◎ It is possible that the output of this algorithm, if parsed with an HTML parser, will not return the original tree structure. Tree structures that do not roundtrip a serialize and reparse step can also be produced by the HTML parser itself, although such cases are typically non-conforming.

一例として, `textarea$e 要素に `Comment^I ~nodeが付加されていた場合、 要素を直列化して構文解析し直した結果の~commentは,~text~control内に表示されることになる。 同様に、 ~DOM操作による結果,要素が[ 文字列 `-->^l をそのまま包含するような~comment ]を包含する場合、 要素を直列化して構文解析し直した結果の~commentは,その地点で切落され、 残りの部分は~markupとして解釈されることになる。 他にも、 `script$e 要素に文字列 `</script>^l を伴う `Text$I ~nodeを包含させた場合や, `p$e 要素に `ul$e 要素を包含させた場合などが挙げられる( `ul$e 要素の`開始~tag$は `p$e に対する終了~tagを黙示するので)。 ◎ For instance, if a textarea element to which a Comment node has been appended is serialized and the output is then reparsed, the comment will end up being displayed in the text control. Similarly, if, as a result of DOM manipulation, an element contains a comment that contains "-->", then when the result of serializing the element is parsed, the comment will be truncated at that point and the rest of the comment will be interpreted as markup. More examples would be making a script element contain a Text node with the text string "</script>", or having a p element that contains a ul element (as the ul element's start tag would imply the end tag for the p).

これは、 ~XSS攻撃を可能化し得る。 例えば,ある~pageにおいて、 利用者に何らかの~font-family名を手入力してもらい,それを~DOMを介して ~CSS `style$e ~blockの中に挿入してから, `innerHTML$m ~IDL属性を利用して `style$e 要素の~HTML直列化を取得しているとする。 利用者が~font-family名として `</style><script>攻撃~code</script>^l を手入力した場合、 `innerHTML$m は[ 他の文脈にて構文解析されたときには、 元の~DOM内には存在しない `script$e ~nodeを包含することになる ]ような~markupを返すことになる。 ◎ This can enable cross-site scripting attacks. An example of this would be a page that lets the user enter some font family names that are then inserted into a CSS style block via the DOM and which then uses the innerHTML IDL attribute to get the HTML serialization of that style element: if the user enters "</style><script>attack</script>" as a font family name, innerHTML will return markup that, if parsed in a different context, would contain a script node, even though no script node existed in the original DOM.

例えば、 次の~markupを考える: ◎ For example, consider the following markup:

`serializing-1^xCode

これを構文解析した結果は次になる: ◎ This will be parsed into:

  • `html$e
    • `head$e
    • `body$e
      • `form$e `id$a=`outer^l
        • `div$e
          • `form$e `id$a=`inner^l
            • `input$e

`input$e 要素は、 内縁 `form$e 要素( `inner^l )に所有されることになる。 ここで,この~tree構造が直列化され構文解析し直された場合、 開始~tag `<form id="inner">^e は無視されることになり, `input$e 要素は 外縁 `form$e 要素に所有されることになる。 ◎ The input element will be associated with the inner form element. Now, if this tree structure is serialized and reparsed, the <form id="inner"> start tag will be ignored, and so the input element will be associated with the outer form element instead.

`serializing-2^xCode
  • `html$e
    • `head$e
    • `body$e
      • `form$e `id$a=`outer^l
        • `div$e
          • `input$e

別の例として、 次の~markupを考える: ◎ As another example, consider the following markup:

`serializing-3^xCode

これを構文解析した結果は次になる: ◎ This will be parsed into:

  • `html$e
    • `head$e
    • `body$e
      • `a$e
        • `a$e
        • `table$e

すなわち、 2 個の `a$e 要素は入子にされる — 2 個目の `a$e は`親が違えられ$るので。 直列化して構文解析し直す往復~後には、[ `table$e, 2 個の `a$e ]要素は,互いに同胞になる — 2 個目の開始~tag `<a>^c が, 1 個目の `a$e 要素を暗黙的に閉じるので。 ◎ That is, the a elements are nested, because the second a element is foster parented. After a serialize-reparse roundtrip, the a elements and the table element would all be siblings, because the second <a> start tag implicitly closes the first a element.

`serializing-4^xCode
  • `html$e
    • `head$e
    • `body$e
      • `a$e
      • `a$e
      • `table$e

歴史的な理由から、 この~algoでは,[ `pre$e / `textarea$e / `listing$e ]要素~内の先頭の `000A^U `LF^cn 文字は往復しない — ~markupが適合していようが(廃用にされた `listing^e は適合し得ないが)。 `~HTML構文解析器$は,構文解析-時にそのような文字を落とすことになるが、 この~algoは,落とされた `000A^U `LF^cn を直列化する`ことはない^em。 ◎ For historical reasons, this algorithm does not round-trip an initial U+000A LINE FEED (LF) character in pre, textarea, or listing elements, even though (in the first two cases) the markup being round-tripped can be conforming. The HTML parser will drop such a character during parsing, but this algorithm does not serialize an extra U+000A LINE FEED (LF) character.

例えば、 次の~markupを考える: ◎ For example, consider the following markup:

`serializing-5^xCode

この文書を最初に構文解析したとき、 この `pre$e 要素の`子~text内容$の頭部にある改行文字は, 1 個だけに減る。 直列化して構文解析し直す往復~後には、 また 1 個~減り,`子~text内容$は `Hello.^l だけになる。 ◎ When this document is first parsed, the pre element's child text content starts with a single newline character. After a serialize-reparse roundtrip, the pre element's child text content is simply "Hello.".

`is$a 属性は、 `~custom化された組込みの要素$の作成を通達するとき特別な役割を果たす — そこでは、 構文解析された~HTML用に,要素の`~is0値$を設定する仕組みが供される — ので,直列化の間に特別に取扱われる。 これは、 直列化して構文解析する往復を通しても, 要素の`~is0値$は保全されることを確保する。 ◎ Because of the special role of the is attribute in signaling the creation of customized built-in elements, in that it provides a mechanism for parsed HTML to set the element's is value, we special-case its handling during serialization. This ensures that an element's is value is preserved through serialize-parse roundtrips.

構文解析器を介して,`~custom化された組込みの要素$を作成するとき、 開発者は `is$a 属性を直に利用する — そのような事例では、 往復は申し分なく働く。 ◎ When creating a customized built-in element via the parser, a developer uses the is attribute directly; in such cases serialize-parse roundtrips work fine.

`serializing-6^xCode

一方で,~custom化された組込みの要素を[ その`~custom要素~構築子$/ `createElement()$m ]を介して作成した場合、 `is$a 属性は追加されない。 代わりに,`~is0値$(それが~custom要素の機構が利用するものである)は、 属性を仲介することなく設定される。 ◎ But when creating a customized built-in element via its constructor or via createElement(), the is attribute is not added. Instead, the is value (which is what the custom elements machinery uses) is set without intermediating through an attribute.

【!serializing-7】
<script>
%container.innerHTML = "";
const %p = document.createElement("p", { is: "super-p" });
%container.appendChild(p);

/* 
~DOM内には `is^a 属性は無い:
◎
The is attribute is not present in the DOM:
 */
console.assert(!p.hasAttribute("is"));

/* 
が、
要素は依然として `super-p^e である:
◎
But the element is still a super-p:
 */
console.assert(%p instanceof SuperP);
</script>

往復が依然として働くことを確保するため、 直列化~処理nでは,要素の`~is0値$を明示的に `is$a 属性として書き出す: ◎ To ensure that serialize-parse roundtrips still work, the serialization process explicitly writes out the element's is value as an is attribute:

`serializing-8^xCode

(上の~algoの目的において) `文字列を~escapeする@ ときは、 所与の ( %文字列, %属性~用か (省略時は ε) ) に対し,次の手続きを走らす: ◎ Escaping a string (for the purposes of the algorithm above) consists of running the following steps:

  1. %文字列 を成す各~文字 `&^l を文字列 `&amp;^l に置換する ◎ Replace any occurrence of the "&" character by the string "&amp;".
  2. %文字列 を成す各~文字 `00A0^U `NO-BREAK SPACE^cn を文字列 `&nbsp;^l に置換する ◎ Replace any occurrences of the U+00A0 NO-BREAK SPACE character by the string "&nbsp;".
  3. ~IF[ %属性~用か ~EQ `属性~用^i ] ⇒ %文字列 を成す各~文字 `"^l を文字列 `&quot;^l に置換する ◎ If the algorithm was invoked in the attribute mode, replace any occurrences of the """ character by the string "&quot;".
  4. ~ELSE:

    1. %文字列 を成す各~文字 `<^l を文字列 `&lt;^l に置換する
    2. %文字列 を成す各~文字 `>^l を文字列 `&gt;^l に置換する
    ◎ If the algorithm was not invoked in the attribute mode, replace any occurrences of the "<" character by the string "&lt;", and any occurrences of the ">" character by the string "&gt;".

13.4. ~HTML素片の構文解析-法

【 この節の内容は、 別~pageにて。 】

13.5. 有名~文字~参照

【 この節の内容は、 別~pageにて。 】