The Outline Algorithm Utopia

Browser and UI #2 HTML/ARIA
saku🌞 / @sakupi01

saku

🀗
Design Technologist / ex-Web Frontend @Cybozu

Goolgle Developer Expert for Web Technologies

🍏 / ☕ / 🌏 >

❀

🐊 @sakupi01
🐙 @sakupi01
🊋 @sakupi01.com

The Outline Algorithm Utopia

※ このスラむドは The Outline Algorithm Utopia の内容に基づきたす

ブラりザからのお知らせ

ブラりザからのお知らせ: UA Style が倉わりたす

Intent to unship: UA styles for h1 in article, aside, nav, section

Intent to Deprecate and Remove: Deprecate special font size rules for H1 within some elements
Intent to unship: UA styles for h1 in article, aside, nav, section
Remove UA style for h1-h6 in section (et. al.) and hgroup · Issue #7867 · whatwg/html
Remove UA styles for h1 in article, aside, nav, section by zcorpan · Pull Request #11102 · whatwg/html

䜕がどう倉わる

<body>
  <h1>I'm a Level 1 Heading.</h1>
  <section>
    <h1>I'm a Level 1. Supposed to act as a Level 2.</h1>
    <section>
      <h1>I'm a Level 1. Supposed to act as a Level 3.</h1>
      <section>
        <h1>I'm a Level 1. Supposed to act as a Level 4.</h1>
        <section>
          <h1>I'm a Level 1. Supposed to act as a Level 5.</h1>
        </section>
      </section>
    </section>
  </section>
</body>

~ 2025/03

section のネストが深くなるに぀れお、 margin ず font-size が小さくなる

<section> のネストが深くなるに぀れお、 margin ず font-size が小さくなる

2025/03 ~

section のネスト関係なく、h1 であれば h1 の margin ず font-size

<section> のネスト関係なく、h1 であれば h1 の margin ず font-size
→ 段階的にロヌルアりト

なぜ

なぜ

そもそもなんでネストによっお芋た目が倉わっおいたのか

なぜ

そもそもなんでネストによっお芋た目が倉わっおいたのか
それによっお䜕が問題ずなっおいたのか

なぜ

そもそもなんでネストによっお芋た目が倉わっおいたのか
それによっお䜕が問題ずなっおいたのか
この倉曎が意味するものずは

なぜ

そもそもなんでネストによっお芋た目が倉わっおいたのか
それによっお䜕が問題ずなっおいたのか
この倉曎が意味するものずは
次に䜕が埅っおいる

Back to over 30 years ago ... 🛞

Flat Content

  • Brian Kardell の䞻匵を借りるのであれば、HTML の蚭蚈思想は、その前身ずなるフラットな構造のマヌクアップ蚀語GMLに遡るずされおいる
  • 芁玠は単に芖芚的なマヌカヌずしお機胜し、特に <p> などの芁玠では、閉じタグは必芁ないず考えられおいた節がある
<h1>This marks the top level heading
<p>You can know that this is a paragraph and not heading...

構造的な Document Model - DOM, The Accessibility Tree

  • プログラム的な利甚における構造解釈が必芁になる
    • DOM, The Accessibility Tree
  • 芖芚的な Semantics ず 構造的な Semantics の間に䞍敎合が生じるようでは困る

HTMLにおいお「芖芚的な Semantics」が「構造的な意味」より優先された結果、倚くの混乱が生じた。芖芚が正しいように芋えれば構造がメチャクチャでも気にしないずいう状況を生み出しおしたった

「芋出しレベルの自動ハンドリング」をブラりザ偎でやっおしたえばいいのでは・・・

芋出しレベルの適切なハンドリングは、完党に開発する偎に委ねられおいる 「芋出しレベルの自動ハンドリング」を実珟すれば、ブラりザ偎でアクセシブルな DOM 構造を担保できおいいのでは...

🚀

The Birth of Utopia

🚀

Sectioning & Document Outline Algorithm

  • 文曞を Sectioning する
    • <section> や <article> などの Sectioning Content Element たたは Sectioning Root を䜿甚する堎合
    • h1-6 の芋出し芁玠を䜿甚しお䜜成された、「暗黙のセクション」を䜿甚する堎合
    • <hgroup> 芁玠を䜿甚しおグルヌプ化したセクションの芋出しを䜿甚する堎合
  • それによっお、”Outline” ずいう「Heading を持った Section で構成される枠」 を生成する
  • その階局構造を決定するアルゎリズムが、実に Document Outline Algorithm

<body> 
 <h4>Apples</h4>
 <p>Apples are fruit.</p>
 <section> 
  <h2>Taste</h2>
  <p>They taste lovely.</p>
  <h6>Sweet</h6> 
  <p>Red apples are sweeter than green ones.</p>
  <h1>Color</h1> 
  <p>Apples come in various colors.</p>
 </section>
</body>

<body>
 <h1>Apples</h1>
 <p>Apples are fruit.</p>
 <section> 
  <h2>Taste</h2>
  <p>They taste lovely.</p>
  <section> 
   <h3>Sweet</h3>
   <p>Red apples are sweeter than green ones.</p>
  </section>
 </section>
 <section> 
  <h2>Color</h2>
  <p>Apples come in various colors.</p>
 </section>
</body>

as-is

Sectioning Root

Sectioning Content Element

暗黙のセクション

暗黙のセクション

to-be

Sectioning Content Element

暗黙のセクション

暗黙のセクション


<body> 
  <h1>I'm a Level 1 Heading.</h1>
  <section> 
    <h1>I'm a Level 1. Supposed to act as a Level 2.</h1>
    <section> 
      <h1>I'm a Level 1. Supposed to act as a Level 3.</h1>
      <section> 
        <h1>I'm a Level 1. Supposed to act as a Level 4.</h1>
        <section> 
          <h1>I'm a Level 1. Supposed to act as a Level 5.</h1>
        </section>
      </section>
    </section>
  </section>
</body>

<body>
  <h1>I'm a Level 1 Heading.</h1>
  <section>
    <h2>I'm a Level 1. Supposed to act as a Level 2.</h2>
    <section>
      <h3>I'm a Level 1. Supposed to act as a Level 3.</h3>
      <section>
        <h4>I'm a Level 1. Supposed to act as a Level 4.</h4>
        <section>
          <h5>I'm a Level 1. Supposed to act as a Level 5.</h5>
        </section>
      </section>
    </section>
  </section>
</body>

as-is

Sectioning Root

Sectioning Content Element

Sectioning Content Element

Sectioning Content Element

Sectioning Content Element

to-be

「フラットな構造」を基本ずしおいた HTML に、階局構造を衚珟するずいう画期的なアむディアが持ち蟌たれた

... もしかしお、、、

「党郚 <h1> 䜿っおも、Sectioning しずけば、ブラりザが ”いい感じ” にしおくれる」

Sections may contain headings of any rank, but authors are strongly encouraged to either use only h1 elements, or to use elements of the appropriate rank for the section’s nesting level.


セクション内には任意のランクを含めるこずができたすが、著者はh1 芁玠のみを䜿甚するか、セクションのネストに応じたランクの芋出しを蚘述するこずを掚奚したす。
4.3 Sections — HTML 5.1 Nightly https://web.archive.org/web/20121214011658/http://www.w3.org/html/wg/drafts/html/master/sections.html#headings-and-sections

ブラりザ「実装したよ」

section のネストが深くなるに぀れお、 margin ず font-size が小さくなる

「ほんずだ」

「ほんずうに」

sectioningでの芋出し階局は支揎技術に䌝わらない

“The Algorithm” was the only missing piece

ブラりザは Sectioning を党く具珟化しなかったわけではない

  • <section> や <article>、<nav> ずいった Sectioning Content Element を実装
  • Section のネストレベルに応じた UA Style を提䟛

Section のネストが深くなるほど margin ず font-size が小さくなるようなスタむルが適甚され、芋た目䞊は「芋出しレベルが自動調敎」されるように

“The Algorithm” was the only missing piece

  • Sectioning を駆䜿したマヌクアップをしおも、Outline Algorithm 自䜓は実装されおいないので、構造的な Semantics ずしおプログラムに䌝わらない。支揎技術に䌝わらない
  • 問題だったもの「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合が、䜕も解決されおいない

sectioningでの芋出し階局は支揎技術に䌝わらない

Outline Algorithm in HTML5 Era

Outline Algorithm を前提ずした蚘述を削陀、譊告文を远加

⚠Warning! There are currently no known native implementations of the outline algorithm in graphical browsers or assistive technology user agents, although the algorithm is implemented in other software such as conformance checkers and browser extensions. Therefore the outline algorithm cannot be relied upon to convey document structure to users. Authors should use heading rank (h1-h6) to convey document structure.
HTML 5.2: 4.3. Sections https://html.spec.whatwg.org/multipage/sections.html#creating-an-outline

「構造的な Semantics」 を「芖芚的な Semantics」に合わせるこずを諊め、癜玙に戻そうずしはじめた

Outline Algorithm in HTML Living Standard Era

この間は HTML の暙準が W3C の HTML5.x から WHATWG の Living Standard に倉遷しおいった期間でもあり

Outline Algorithm in HTML Living Standard Era

  • Living Standard になる段階で Outline Algorithm に関する泚意曞きが削陀される

  • Living Standard の仕様から Outline Algorithm に関しお誀解を招く蚘述を削陀する PR

  • 単に仕様ず矛盟した譊告を茉せるにずどたらず、アルゎリズム自䜓を消すか実装するかの問題たで波及しおおり、これが議論を難航させる原因になった

この間は HTML の暙準が W3C の HTML5.x から WHATWG の Living Standard に倉遷しおいった期間でもあり

それに察しお Steve Faulkner が 2015 幎に Issue を立お、Living Standard の仕様から Outline Algorithm に関しお誀解を招く蚘述を削陀する PR を提出し、これが玄 7 幎間も議論されるこずになりたす。 WHATWG での議論は、仕様ず矛盟した譊告を茉せるのではなく、アルゎリズム自䜓を消すか実装するかの問題になっおおり、これが議論を難航させる原因になったのだず思いたす。

「Outline Algorithm は䞀向に実装されないが、Structural なコンテンツは珟代の Web にずっお欠かせない。ならば、別の手段で Structural な意味を HTML に持たせるこずはできないか」

じゃあその 7 幎間、呚りはただ埅っおいただけなのかずいうずそういうわけではない

「Outline Algorithm は䞀向に実装されないが、Structural なコンテンツは珟代の Web にずっお欠かせない。ならば、別の手段で Structural な意味を HTML に持たせるこずはできないか」

  • <h>
  • Heading Level Concept

Over 34 year’s old, yet brand-new: <h>

<h> ずいうアむディア自䜓は、実は Tim Berners-Lee が Web を始めたばかりの 1991 幎から存圚した

I would in fact prefer, instead of <H1>, <H2> etc for headings [those come from the AAP DTD] to have a nestable <SECTION>..</SECTION> element, and a generic <H>..</H> which at any level within the sections would produce the required level of heading.
www-talk from September to October 1991: Re: status. Re: X11 BROWSER for WWW

<h>

既に実装枈みの Sectioning Content Elements ず組み合わせ、Outline Algorithm によっお、Section のコンテキストに応じた芋出しレベルを自動的に決定するために提案された芁玠

<section>
  <h>I can be any Level depending on the section context!</h>
  <p>paragraph</p>
</section>

<h> 以倖の Headings を deprecated 候補ずし、XHTML2.0 の仕様にはこれが含たれるこずに

結局 h1-6 は残されたたたで、それどころか XHTML 2.0 自䜓も攟眮され、謎だらけのたた終わる ...

Re-visit <h>

HTML5 でも <h> の远加が提案される

<h>の持぀矛盟

課題HTML ずしお、「Outline Algorithm が実装されないこず」が課題だったのに、
解決策<h>は「Outline Algorithm を利甚した新芏方法」だった

根本的な解決策にはならず・・・

HTML ずしお ”課題” だったのは「Outline Algorithm が実装されないこず」だったのに、 結果ずしお出た ”解決策” は「Outline Algorithm を利甚した新芏方法」

Heading Level Concept

「Outline Algorithm で Outline を生成するこず」ではなく「Sectioning Content 内の芋出しレベルを調敎するこず」に焊点を圓おた Anne van Kesteren の提案

// https://github.com/annevk/html-heading-level-polyfill/blob/main/polyfill.js
function determineLevel(el) {
  let level = 1;
  // Arguably the parentNode being null check can be removed as it will never be null when this and
  // the function below are run on a document, as is the case.
  //
  // This is "sectioning content" and "sectioning roots"
  while (el.parentNode && (el = el.parentNode.closest("article,aside,nav,section,blockquote,details,dialog,fieldset,figure,td"))) {
    level += 1;
  }
  return level;
}

Anne の䜜った Heading Levels の Polyfill この Polyfill のアルゎリズムは非垞にシンプルで、

か
の Sectioning Content をたどり、Sectioning にネストされる毎にレベルを加算しお aria-level 属性に蚭定するずいうもの

これぞ顧客が本圓に求めおいたもの・・・

  • Outline Algorithm ずいう机䞊の空論を䞻匵し続けない
    • Outline Algorithm を倧幅に簡略化し、Section Content のネストレベルをカりントするだけ
  • ”プログラム的な利甚における構造解釈の重芁性” ずいう今の Web が、支揎技術を利甚するナヌザが、 喫緊で必芁ずしおいるものにアプロヌチしおいる

この点で、Heading Level Concept は非垞に筋の通った提案だった

Heading Level Concept は頓挫。Outline Algorithm 廃止ぞ

h1が消倱する埌方互換の問題が発生

Unfortunately, this was not a success (too many h1s got adjusted to be h2s) so we’ve removed this code and abandoned this particular plan for dealing with heading levels in HTML: https://bugzilla.mozilla.org/show_bug.cgi?id=1590366.
Intent to prototype: heading levels

<body>
  <main> 
    <article> 
      <h1>Level 3・・・</h1> 
    </article>
  </main>
</body>

Outline Algorithm の抂念を廃止する PR ぞの契機ずなった:

replace current outline algorithm with one based on heading levels by stevefaulkner · Pull Request #7829 · whatwg/html

Sectioning Content Element

Sectioning Content Element

レベル = 1+2 = 3 になっおしたう

ずはいえ、Heading Level Concept によっお、長幎滞っおいた Outline Algorithm の議論にメスが入り、これが Outline Algorithm の抂念を廃止する PR に぀ながりたした。

党お、終わった・・・

問題: 「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合

解決策: 以䞋の 2 条件が揃うこず

  1. ✅ 「芖芚的な Semantics」を 「構造的な Semantics」 に合わせる
    1. Sectioning を意識したスタむルの実装
  2. 「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせるこっちを頑匵っおた
    1. Outline Algorithm を実装する

問題: 「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合

解決策: 以䞋の 2 条件が揃うこず

  1. ✅ 「芖芚的な Semantics」を 「構造的な Semantics」 に合わせる
    1. Sectioning を意識したスタむルの実装
  2. 「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせる こっちが頓挫した
    1. Outline Algorithm を実装する
      • <h> の提案は Reject
      • Anne の Heading Level Concept (v1)は頓挫
      • Outline Algorithm を仕様から削陀

問題: 「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合

解決策: 以䞋の 2 条件が揃うこず

  1. ✅ 「芖芚的な Semantics」を 「構造的な Semantics」 に合わせるこっちだけ残った
    1. Sectioning を意識したスタむルの実装
  2. 「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせる こっちが頓挫した
    1. Outline Algorithm を実装する
      • <h> の提案は Reject
      • Anne の Heading Level Concept (v1)は頓挫
      • Outline Algorithm を仕様から削陀

30 幎以䞊、「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合ずいう問題を抱え続け、ずっず「「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせる」方向で解決しようずしおいたのに、結局ずっず䞍敎合なたただった

問題: 「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合

解決策: 以䞋の 2 条件が揃うこず

  1. ✅ 「芖芚的な Semantics」を 「構造的な Semantics」 に合わせるこっちを削陀する方向で揃えるずきが来た
    1. Sectioning を意識したスタむルの実装
  2. 「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせる こっちが頓挫した
    1. Outline Algorithm を実装する
      • <h> の提案は Reject
      • Anne の Heading Level Concept (v1)は頓挫
      • Outline Algorithm を仕様から削陀

ブラりザからのお知らせ: UA Style が倉わりたす

Intent to unship: UA styles for h1 in article, aside, nav, section

これが削陀される

In the following CSS block, x is shorthand for the following selector: :is(article, aside, nav, section)

@namespace "http://www.w3.org/1999/xhtml";

x h1 { margin-block: 0.83em; font-size: 1.50em; }
x x h1 { margin-block: 1.00em; font-size: 1.17em; }
x x x h1 { margin-block: 1.33em; font-size: 1.00em; }
x x x x h1 { margin-block: 1.67em; font-size: 0.83em; }
x x x x x h1 { margin-block: 2.33em; font-size: 0.67em; }

15.3.6 Sections and headings | HTML Standard

問題: 「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合

解決策: 以䞋の 2 条件が揃うこず

  1. 「芖芚的な Semantics」を 「構造的な Semantics」 に合わせる
    1. Outline Algorithm の UA Style を実装する
  2. 「構造的な Semantics」 を 「芖芚的な Semantics」 に合わせる
    1. Outline Algorithm を実装する
      • <h> の提案は Reject
      • Anne の Heading Level Concept (v1)は頓挫
      • Outline Algorithm を仕様から削陀

→ どっちも削陀するずいうこずで敎合した

Outline Algorithm の閉幕

Outline Algorithm を取り巻く 30 䜙幎の䞭で、䜕がどう倉わった・・・

「芖芚的な Semantics」ず「構造的な Semantics」の䞍敎合は、30 幎以䞊かけおやっず解消されたけど、

ずっず Outline Algorithm は実装されず、フラットな文曞構造の䞭にいた

Outline Algorithm の閉幕が瀺唆するこず:

ずりあえず今は・・・構造的に正しいマヌクアップを

  • 芋出しレベルを適切に䜿甚するh1 から順に階局的に䜿い、レベルをスキップしない
  • 芋た目ではなく構造でCSSで芋た目を調敎するのは自由だが、たずは意味的に正しい構造を構築する
  • アクセシビリティを念頭に眮くスクリヌンリヌダヌなどの支揎技術が正しく解釈できる文曞構造の構築をする

markuplint ずか、HTML validator ずか...

次に䜕が埅っおいる

[WIP!] Mechanism for opting-in for Heading Level Concept

🀩 Heading Level Concept (v2) 🀩

Heading Level Concept (v2)

  • Anne の Heading Level Concept を実珟する新たな解決策ずしお、headingoffset & headingreset を導入
    • 「h1 がドキュメントから消滅する」などの問題を解消し぀぀、Heading Level Concept をオプトむン
    • Outline Algorithm でない方法で芋出しの自動調敎
  • 芋出しレベルが h1~6 に限られなくなる → :heading&:heading(N)

More Details #[WIP!] Mechanism for opting-in for Heading Level Concept

headingoffset & headingreset attributes

Outline Algorithm 亡き今、 ✹ Heading Level Concept ✹ による芋出しの自動調敎に期埅・・・

Thank you!

Appendix