Skip to content

🐛 HTML format result can produce visual difference in Firefox #7304

Description

@tats-u

Environment information

Online playground ([2f9d7c9](https://github.com/biomejs/biome/tree/2f9d7c9476f2cfd5eee865ea16d5ba4456ceaa55))

What happened?

https://biomejs.dev/playground/?code=PABkAGkAdgAgAGwAYQBuAGcAPQAiAHoAaAAtAEgAYQBuAHQALQBUAFcAIgA%2BAAoAIAAgABmQC1C1az2EL2ajkLyed5UM%2FwoAKFcATkyI61sNTkyIAjAAZ31ZCgAodQlOTIjrWwIwCgA8AC8AZABpAHYAPgA%3D&language=html

Input:

<div lang="zh-Hant-TW">
  這個段落是那麼長,
在一行寫不行。最好
用三行寫。
</div>

Output:

<div lang="zh-Hant-TW">這個段落是那麼長, 在一行寫不行。最好 用三行寫。</div>

Expected result

New lines surrounded only Chinese/Japanese characters should be kept as are as for the time being:

<div lang=zh-Hant-TW>
  這個段落是那麼長,
在一行寫不行。最好
用三行寫。
</div>

https://drafts.csswg.org/css-text-4/#line-break-transform

In languages that have no word separators, such as Chinese, “unbreaking” a line requires joining the two lines with no intervening space.

這個段落是那麼長,
在一行寫不行。最好
用三行寫。

這個段落是那麼長,在一行寫不行。最好用三行寫。

Figure 7: Eliminating a line break in Chinese requires eliminating any intervening white space.

The segment break transformation rules can use adjacent context to either transform the segment break into a space or eliminate it entirely.

https://codepen.io/tats-u/pen/GgpGpZQ

Only Firefox does not insert spaces there:

Image

On the contrary, Chromium/Safari:

Image

Prettier considers this rule to some extent in Markdown, but does not use the same rule as Firefox, so we should not reuse the logic used in Prettier to check the character is Chinese/Japanese.

Prettier (HTML): prettier/prettier#16837
dprint (Markdown): dprint/dprint-plugin-markdown#127

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Activity

  1. added
    S-Needs triage
    on Aug 23, 2025
  2. added theissue type on Aug 23, 2025
  3. tats-u commented on Aug 25, 2025

    @tats-u
    ContributorAuthor

    Firefox's Chinese/Japanese character meets all of:

    • East Asian Width is F, W, or H
    • Script is not Hangul
    • Does not have Emoji property
    • Not the half-width won sign

    A variation selector before the newline is ignored. (Update: Firefox's implementation is to check the Default_Ignorable_Code_Point (DI) property of one or more preceding characters)


    Additional rules in Chinese & Japanse:

    If at least one of the sides is CJK punctuations, the space is removed, too. The CJK punctuation meets all:

    • East Asian Width is F, W, or H
    • Either of:
      • General Category is P and not half-width won sign U+20A9 ₩
      • Is full-width tilde U+FF5E ~
      • (Update) ideographic space U+3000 (since 145)

    https://github.com/mozilla-firefox/firefox/blob/66bb0c6d60554576b420b8e7138554c9edcdcc17/intl/unicharutil/util/nsUnicharUtils.cpp#L524 (Caution: the code is MPL!)

    w3c/csswg-drafts#5086

  4. dyc3 commented on Aug 25, 2025

    @dyc3
    Contributor

    Ok, I think I understand the issue. With regards to whitespace sensitivity, we can't add spaces between characters belonging to languages that don't use spaces as word separators. But it is OK to add newlines because the browser accounts for that.

    Note this excerpt from the spec:

    Historically, HTML and CSS have unconditionally converted segment breaks to spaces, which has prevented content authored in languages such as Chinese from being able to break lines within the source. Thus UA heuristics need to be conservative about where they discard segment breaks even as they strive to improve support for such languages.

    I think it makes sense to diverge from prettier for this case.

  5. added
    A-Formatter
    S-Bug-confirmed
    L-HTML
    on Aug 25, 2025
  6. removed
    S-Needs triage
    on Aug 25, 2025
  7. tats-u commented on Aug 25, 2025

    @tats-u
    ContributorAuthor

    Web Platform Tests: https://wpt.fyi/results/css/css-text/line-breaking?label=master&label=experimental&aligned&q=segment-break-transformation-

    I think it makes sense to diverge from prettier for this case.

    Prettier's behavior should be changed. Biome is going to be just ahead of the curve. We have to report an issue in Prettier's repo but it is difficult to generate an example that is different between the current Prettier and Firefox.

    But it is OK to add newlines because the browser accounts for that.

    If "add newlines" means "break the line into two in a Chinese/Japanese line at an arbitrary point", we should avoid it as for now. It causes an extra space there like the above screenshots in unsupported (KHTML/WebKit-derived) browsers. Biome should try to provide the same appearance in all browsers before and after formatting.


    FYI Prettier's algorithm:

    https://github.com/prettier/prettier/blob/main/src/language-markdown/utils.js
    https://github.com/prettier/prettier/blob/main/src/language-markdown/constants.evaluate.js
    https://github.com/ikatyang-collab/cjk-regex/blob/main/src/index.ts

  8. self-assigned this
    on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-FormatterL-HTMLS-Bug-confirmed

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions