Skip to content

[Meta] CSS Writing Modes #2560

Open
Open

Description

@SimonSapin

Roadmap Issue

Description:
The goal would be to add support for writing modes in Servo's layout engine, this is a key feature that interacts with the rest of layout features. This is an important feature for internationalization specially for non-latin scripts.

Tracking issue. http://dev.w3.org/csswg/css-writing-modes/

Area: Layout

People: We at https://github.com/Igalia have plans to work on this, starting at some point in 2026, but we cannot commit to the task just yet.


  • Implement logic for propagating the principal writing mode from the root element or <body> to the initial containing block.
  • Implement support for documents written entirely using a vertical-lr writing mode, or a vertical-rl writing mode.
  • Implement support for documents mixing vertical-lr and vertical-rl writing modes.
  • Implement orthogonal flows in block layout.
  • Implement orthogonal flows in inline layout.
  • Implement orthogonal flows in table layout.
  • Implement orthogonal flows in flex layout.
  • Implement orthogonal flows in absolutely positioned layout.

Activity

  1. Gankra commented on Jan 15, 2018

    @Gankra
    Contributor

    upstream webrender work just landed: servo/webrender#2288

  2. Gankra commented on Jan 15, 2018

    @Gankra
    Contributor

    (well bors is throwing a fit but, you know)

  3. tigercosmos commented on May 26, 2018

    @tigercosmos
    Contributor

    @SimonSapin So do we still have not implement writing-mode yet?

  4. SimonSapin commented on May 27, 2018

    @SimonSapin
    MemberAuthor

    We do have some support behind the layout.writing-mode.enabled pref. But it’s buggy, in particular orthogonal flows (a change of horizontal v.s. vertical direction in the same document) are very broken.

  5. mrobinson commented on Nov 2, 2026

    @mrobinson
    Member

    The main issue we have when implementing full support for CSS writing modes is that we readily convert logical fragment rectangles to physical rectangles when creating them. With writing modes enabled, we do not know the physical rectangle that corresponds to a fragment's logical rectangle until we know the block size of its parent fragment. Typically during layout of children, we only know the inline size of the parent during layout. Only after layout of the children do we know the block size.

    In order to solve this issue, we need to more thoroughly do layout in logical coordinates and collect a vector of child fragments and their logical rectangles that are resolved when the parent fragment is created. This implies a new call to BaseFragment::set_rect when child fragments are added to their
    parent.

    We already do something like this to support RTL in line layout, where the final inline size of the containing boxes is used to flip rectangles in the inline axis as the final step. We need to do this flipping now in the block axis for vertical-rl and sideways-rl writing modes. The main idea of this work is that we would extend this approach to all of layout.

    1. FragmentAndData is used in line layout to hold a Fragment and its logical rectangle. This would be generalized and we would start using it in other layout modes. This data structure could be called FragmentAndLogicalRect.
    2. Currently LogicalRect::as_physical in geom.rs takes an argument for the container size now, an optional ContainingBlock. This ContainingBlock does not necessarily have a definite block size.
      • The Option needs to be removed. All callers should pass container size information.
      • The full dimensions need to be known when passed. A temporary deprecated version of this can take a ContainingBlock, but these should eventually be moved when logical rectangles are converted to physical ones later in layout.
      • Conversion needs to be implemented for all writing modes in geom.rs and unit tests should be written proving these conversions are correct and as we expect them to be.
    3. We should convert block-based / absolute layout modes to produce our new FragmentAndLogicalRect data structure. Floats will require particular care. We need to stop converting quickly to physical rectangles and we need to look at how to delay this conversion across various layout modes. This can be done by moving all conversion to physical rectangles to the point where fragments are added to their parents. In addition we need more work to support orthogonal flows, which should start at the places where we removed assertions about orthogonal writing modes.
    4. Inline layout needs to support vertical writing modes:
      • Fonts and rendering:
        • All system-specific font implementations need support for vertical metrics.
        • Shaping needs to be informed of glyph orientation and writing direction.
        • Glyph rendering needs to be taught about sideways glyphs.
      • Inline layout should be taught to determine the proper metrics for things like the strut, line-height, and the baseline in vertical writing modes.
      • Text decoration and shadow painting should respect writing modes.
      • Hit testing should no longer assume the inline axis is horizontal.
    5. Flexbox, tables, grid, and replaced elements need to be modified to do the late conversion to physical rectangles and also polished to ensure that there are no remaining assumptions about writing modes such as that flows are never orthogonal.
    6. The viewport and viewport-level APIs / measurement should no longer assume a horizontal / LTR writing mode. This affects scrolling.
  6. pinned and unpinned a comment on Nov 2, 2026
  7. added
    B-roadmap
    on Nov 4, 2026
  8. 5 remaining items

  9. nicoburns commented on Nov 18, 2026

    @nicoburns
    Contributor

    @SimonSapin Is there are design doc somewhere for how we're planning to implement writing-mode in Servo?

    The issue description above (admittedly written in 2014) seems to suggest that there will be per-layout algorithm changes. But Blink and Blitz both implement writing-mode without changing the layout algorithms meaningfully. And I think that strategy would make a lot of sense in Servo too. The method I'm proposing is: For vertical writing modes: transpose styles on the way in to the algorithm, transpose fragments on the way out. Add a little logic in the glue between layout modes to account for orthogonal flows. And... that's it

    (perhaps that's already what's planned, but I can't tell either from what's been posted publicly)

    The implementation in Blitz was surprisingly small (~1k Loc): DioxusLabs/blitz#1090

  10. SimonSapin commented on Nov 18, 2026

    @SimonSapin
    MemberAuthor

    The issue description as it is now was written somewhat recently. I the bullet points listing per-layout algorithm changes refers to the same as what you describe as:

    Add a little logic in the glue between layout modes to account for orthogonal flows.

    As to this strategy:

    For vertical writing modes: transpose styles on the way in to the algorithm, transpose fragments on the way out.

    This means having most of the layout code work with logical aka flow-relative coordinates while pretending its not. This says “width” but really means “inline size”, that says “height” but really means “block size”. That doesn’t sound great because you have to know somehow where the boundary of pretending is exactly.

    Instead, part of the “Layout 2020” rewrite was using logical terminology in code from the start.

    (Also, just swapping dimensions works for sizes but is not enough for positions: the inline-start block-start corner used as the origin for relative logical positions maps do different physical corners in different writing modes.)

    I don’t think we have a formal design doc, #2560 (comment) highlights the current and next steps.

    It’s not gonna be a single PR but given the code already uses logical terminology I expect the overall diff for “most of the feature” won’t be huge, then there’ll be a long tail of bug fixes for unusual combinations like orthogonal float that is also replaced

  11. nicoburns commented on Nov 18, 2026

    @nicoburns
    Contributor

    Ok cool. I'm glad to hear it's mostly a style swapping solution.

    This means having most of the layout code work with logical aka flow-relative coordinates while pretending its not. This says “width” but really means “inline size”, that says “height” but really means “block size”. That doesn’t sound great because you have to know somehow where the boundary of pretending is exactly.

    Yeah, that's fair. In Taffy that boundary reasonably clear because it's the entire crate! But explicitly using logical terminology would make sense. I think everything being physical in Taffy helped, because at least it was consistent.

    #2560 (comment) highlights the current and next steps.

    Interesting that your going with logical fragments. Blitz has physical outputs (it doesn't really have fragments at all yet). I wonder if there's a real trade-off there. Or it's mostly equivalent. Perhaps it only starts to matter once you're actually doing fragmented layout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/blockA-layout/floatsA-layout/inlineA-layout/textA-layout/writing-modeB-feature-trackingB-roadmap

    Type

    No type

    Projects

    • Status
      In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions