Skip to content

Add support for CSS reading-flow - #10613

Open
dizhang168 wants to merge 25 commits into
whatwg:mainfrom
dizhang168:reading-flow
Open

dizhang168 wants to merge 25 commits into
whatwg:mainfrom
dizhang168:reading-flow

Conversation

@dizhang168

@dizhang168 dizhang168 commented Sep 10, 2024 •

Copy link
Copy Markdown
Contributor

The CSSWG resolved to add the new CSS property reading-flow: (w3c/csswg-drafts#7387, spec). Chrome has been working on a prototype for how to change the sequential focus navigation order within a container that has reading-flow.
This PR specs the new CSS property reading-flow per proposal described at #10407.

(See WHATWG Working Mode: Changes for more details.)


/index.html ( diff )
/infrastructure.html ( diff )
/interaction.html ( diff )

Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
@domfarolino

Copy link
Copy Markdown
Member

By the way, in the OP you have "At least two implementers are interested (and none opposed):" checked, but neither of the two linked standards positions have been resolved yet, so I'd uncheck that unless you you have other cross-browser support to point to.

@dizhang168

Copy link
Copy Markdown
Contributor Author

Thanks for the first pass!

By the way, in the OP you have "At least two implementers are interested (and none opposed):" checked, but neither of the two linked standards positions have been resolved yet, so I'd uncheck that unless you you have other cross-browser support to point to.

Thanks for the call out. There has been conversation in meetings and implementers from non-chromium browsers are interested and none opposed. But I will wait for their comments on the official position issues before checking the checkbox.

Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
@dizhang168

Copy link
Copy Markdown
Contributor Author

Status update: I have addressed all the formatting comments. @domfarolino and other reviewers proposed more suggestions and changes at TPAC 2024. I will go back to working on the proposal before making more changes to this spec PR.

@annevk annevk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for writing this! It looks quite clear. One thing I'm missing from the surrounding discussion we had are the examples. I thought those would be added to the specification in some fashion.

Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
Comment thread source Resolved
@annevk annevk added the topic: focus Focus, sequential focus navigation, tabindex, autofocus and inert label Nov 8, 2024

@fantasai fantasai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HTML spec shouldn't be written in a way that depends on specific CSS properties, because these can change--we shouldn't need to change the HTML spec to change how CSS calculates the reading order.

HTML should use a generic concept of a "rendering-defined sibling reading order" or something like that, which both specs can refer to. Then CSS can say how that order is calculated, and HTML can say how it interacts with HTML features and algorithms.

There have been multiple different proposals for how CSS calculates reading order, only some of which depend on values of reading-flow. For example, we have discussed a property on the items (reading-order), a property on the container (reading-flow), a variety of different types of values for each, and the possibility of even changing behavior for effects like dense packing to perform layout-based reordering by default (no specific property). All of this is out of scope for the HTML spec, and shouldn't be locked down into it as if it were the defining spec for these features.

@dizhang168

dizhang168 commented Nov 12, 2024 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I will update this spec to remove any specific CSS properties and instead refer to CSS Display 4 for rendering-defined sibling reading order and reading flow container.

Next, I will refactor this PR accordingly to have only the reading flow order in the context of a focus navigation scope and illustrate the steps with a detailed example.

@dizhang168

Copy link
Copy Markdown
Contributor Author

I have updated the PR with a thorough example for the reading flow order algorithm without referring directly to any 'reading-flow' property. Would appreciate your review, thanks.
@domfarolino @annevk @emilio

Note: I am working with @rachelandrew to update the definitions in css-display-4.

@rachelandrew

Copy link
Copy Markdown

The spec is now published on TR https://www.w3.org/TR/css-display-4/ my understanding is that the outstanding CSS things to discuss shouldn't impact the HTML side, as Di mentioned in her comment.

@domfarolino

Copy link
Copy Markdown
Member

RE #10613 (comment): this is great to hear! I'll remove the do not merge label from our end, given that update.

@domfarolino domfarolino removed the do not merge yet Pull request must not be merged per rationale in comment label Dec 19, 2024
Comment thread source Resolved
@annevk annevk added the do not merge yet Pull request must not be merged per rationale in comment label Dec 19, 2024
@annevk

annevk commented Dec 19, 2024

Copy link
Copy Markdown
Member

My understanding is different and I'd appreciate it if you could leave the label intact.

@rachelandrew

Copy link
Copy Markdown

@annevk can you explain what you are concerned about (and the relationship to the HTML spec) so we can get those issues prioritized in the CSSWG? I'd be happy to focus on the issues that allow us to get this landed.

@annevk

annevk commented Dec 19, 2024

Copy link
Copy Markdown
Member

@fantasai raised a number of issues on the CSS side and I believe she intends to raise more. And we need the CSS side to be stable (which FPWD does not indicate at all; the CSS WG is quite notorious for renaming things late in the game) to be able to fully test this feature end-to-end, which is a pre-requisite for our criteria: https://whatwg.org/working-mode#changes. (@fantasai did indicate above that she hoped that it didn't matter whether the CSS side was stable or not, but it does matter to our process.)

@rachelandrew

Copy link
Copy Markdown

@fantasai if you have more issues in mind, could you raise them? I can get them on the agenda and work through them once we know what they are.

Comment thread source Resolved
Comment thread source Resolved
@dizhang168

Copy link
Copy Markdown
Contributor Author

We should move the conversation about CSS+HTML integration to w3c/csswg-drafts#11328 and keep this PR about HTML spec changes only.

Comment thread source Resolved
Comment thread source Resolved

@domfarolino domfarolino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I've done another pass and I think this LGTM to me. There are two things I find a little funny but not blocking.

  1. It's a little strange that nothing actually calls the reading flow order "algorithm" like a normal algorithm, despite it being written algorithmically. This is an artifact of how focus navigation scopes are constructed—they are not done so algorithmically, but rather descriptively. Therefore the reference to how they're ordered by "tabindex value" is also descriptive, instead of calling the algorithm and working on its return value etc. This quirk predates this PR, and we pile on with how we reference reading flow order—the definition is written very algorithmically and has a return value and everything, but we reference it descriptively. I think this is fine since it sets us up for a more ideal future where all of these things become more algorithmic in nature, but it's just worth pointing out.
  2. The second thing is we're introducing another ordering type for focus navigation scopes but we're keeping the old name—that mentions "tabindex-ordered" directly—for the general concept of all ordered scopes: "tabindex-ordered focus navigation scope" and "flattened tabindex-ordered focus navigation scope". We sidestep this weirdness by specializing some "tabindex-ordered focus navigation scopes" to actually be "reading-flow-ordered focus navigation scopes", which isn't totally weird since reading-flow-ordered scopes are still partially influenced by tabindex. Another way to do this would be to rename all of the tabindex-ordered scopes to a generic "ordered focus navigation scope" and require that some kind of order type (tabindex value or reading flow) be supplied in order to use them. I'm not sure it's necessary, but I'd also be fine with this as a follow-up or general refactoring to this area. I'm fine with things as they are though.

Comment thread source
<li><p>If <var>element</var> is in the <span data-x="popover-showing-state">popover showing
state</span> and has a <span>popover invoker</span> set, then return <var>element</var>.</p></li>

<li><p>If <var>element</var>'s parent is a <span>reading-flow-ordered scope owner</span>, then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we should probably make all of the items in this list properly link to "parent", but keeping consistency in this PR, as you do, is I think fine.

@mfreed7

mfreed7 commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

Two comments here:

  1. It seems like the reading-flow spec has been "stable" for some time now. Perhaps we could re-evaluate this spec PR and get it landed?

  2. One issue has been raised by a developer (see https://crbug.com/436071736) based on the shipped implementation in Chrome. See this repro:

<dialog> <button>B</button> <button>A</button> </dialog>
<style> dialog:open { display: flex; flex-direction: row-reverse; reading-flow: flex-visual; } </style>
<script> document.querySelector('dialog').showModal(); </script>

The dialog is opened with <button>B</button> focused, because that's the first one in the DOM tree. That's correct according to the current spec:

  1. The dialog focusing steps step 4 says to set control to the focus delegate of subject.
  2. The focus delegate algorithm step 6 looks at the children of the dialog in tree order. I.e. in the repro for this bug, the "B" button.
  3. Step 6.2 of the focus delegate algorithm says that if focusTarget is a dialog element and descendant is sequentially focusable, then set focusableArea to descendant. So "B" gets focused.

But it seems like if reading-flow is being used, perhaps this algorithm should change to focus the first thing that would be focused by the "normal" sequential focus algorithm, as defined in this spec PR? For the above repro, that'd be "A".

@mfreed7 mfreed7 added the agenda+ To be discussed at a triage meeting label Nov 9, 2026
bcardarella added a commit to zig-whatwg/crane that referenced this pull request Nov 19, 2026
…dered focus navigation scopes

CSS Display 4 §4: reading-flow (normal | source-order | flex-visual |
flex-flow | grid-rows | grid-columns | grid-order) and reading-order
(<integer>) in the style system - parsed, computed, serialized - neither
affecting anything drawn.

whatwg/html#10613 (sequential focus navigation): a reading flow container (a
block, flex or grid container whose reading-flow applies and is not normal),
a display: contents element whose CSS parent box is one, and each reading
flow item (an element whose parent element is such an owner) are focus
navigation scope owners; an owner's scope is ordered by the reading flow
order - the container's rendering-defined sibling reading flow, each item's
first inclusive ancestor in the scope, then the rest of the scope in tree
order - with tabindex deciding only focusability (src/html/reading_flow.zig,
focus_navigation.zig). Without a renderer the sibling reading flow is the
box children in order-modified document order, then by reading-order;
flex-visual, grid-rows and grid-columns take that order too (stated: the
visual positions are a renderer's).

Golden rule 2: the newer spec. Chrome ships it
(shadow-dom/focus-navigation/reading-flow/source-order-valid.html: Chrome 157
5/5, Firefox 160 0/5, Safari 27.2 0/5; css/css-display/reading-flow/*-valid
and *-computed: Chrome only); whatwg/html#10613 is open with engine bugs open
in all three (Chromium 40932006, Gecko 1854017, WebKit 285029).
bcardarella added a commit to zig-whatwg/crane that referenced this pull request Nov 19, 2026
… (tip incl. tonight's merges): 1,899,048 -> 1,899,516 passing, 0 losses, 0 crashes; css2's 6 unblocked: CSS.highlights (WebIDL maplike in codegen + the V8 binding, Highlight setlike<AbstractRange>, HighlightRegistry per Window), an inserted @import is fetched and data: style sheets apply synchronously (Chrome's static-data model; HTMLLinkElement-load-event), reading-flow/reading-order + reading-flow-ordered focus scopes (whatwg/html#10613, Chrome ships), Element.scrollIntoView updates style first and the runner's Element Click step 5 calls it (fullscreen-css-transition), view-transition pseudo-elements run their animations + getAnimations({pseudoElement, subtree}) (Firefox = spec); TimelineTrigger follows-majority entry. CSSStyleProperties accessors held back (+1.2 MB/isolate; lane css3). Bug-finding PASS (one known sweep-load flake); lifetime 558/558 x3; timers equal; window2 dom clean; gates green both OSes. Cost within the bar except page.fetch memory 1.041 - RULED by the user 2026-11-19 as a build-layout level shift (scoped).
@jstenback jstenback removed the agenda+ To be discussed at a triage meeting label Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge yet Pull request must not be merged per rationale in comment topic: focus Focus, sequential focus navigation, tabindex, autofocus and inert

Development

Successfully merging this pull request may close these issues.

9 participants