Skip to content

[css-text-4 / css-overflow-4] Interaction of text-wrap: balance and (-webkit-)line-clamp #9310

Closed

Description

@jfkthame

It would be good to clarify how text-wrap: balance interacts with line-clamp.

Specifically, when both balancing and clamping are requested, in which order do these effects operate? Does the block first have its lines wrapped using the balance algorithm, and then clamping applied to the resulting lines (without affecting how they wrap), or is clamping applied first and then balancing applied only to the lines up to the clamp limit?

Or in simpler terms, is it expected that (-webkit-)line-clamp may change the line-breaks used in a block?

It seems most intuitive to me that line-clamp applies after the line-breaks for a block have been determined, as it is defined in terms of lines. But the test at https://wpt.live/css/css-text/white-space/text-wrap-balance-line-clamp-001.html appears to assume that text-wrap: balance will be applied only to the lines up to the -webkit-line-clamp limit.

This codepen has an example where this effect is visible. In current Chrome Canary, varying the line-clamp limit results in changes to the line-breaking throughout the paragraph. Is this the expected/desired behavior, or should it be considered a bug?

Depending on the answer to this, the text-wrap-balance-line-clamp-001.html test may need revision.

Activity

  1. bfgeek commented on Sep 6, 2023

    @bfgeek

    It seems most intuitive to me that line-clamp applies after the line-breaks for a block have been determined

    FWIW we (Blink) previously had this behaviour - but after web-developers tested this interaction they were confused believing that text-wrap: balance was broken for this case.

    Based on this feedback we changed it to only balance the lines within the line-clamp range. We haven't received any bug reports since for this interaction.

    cc/ @kojiishi

  2. jfkthame commented on Sep 8, 2023

    @jfkthame
    ContributorAuthor

    Thanks for the comment, Ian, that's interesting. I'm curious if people considered the implications of this for dynamically-varying line-clamp, or looked only at static examples?

    In the purely static case, balancing only the displayed lines makes good sense, but I find the dynamic behavior where changing the line-clamp value causes line-wrapping to change to be a bit disconcerting. Interested to hear what other people think...?

  3. bfgeek commented on Sep 8, 2023

    @bfgeek

    I'm curious if people considered the implications of this for dynamically-varying line-clamp, or looked only at static examples?

    From examples I've seen - most folks have a non-dynamic line-clamp (super rare to animate this). If it does change (say based on viewport/container width, etc) I suspect most web developers would still expect it to balance the visible lines.

    (FWIW we received this feedback from more that one set of developers trying the API - e.g. wasn't a single voice).

  4. 35 remaining items

  5. added a commit that references this issue on May 29, 2024
  6. frivoal commented on May 29, 2024

    @frivoal
    Collaborator

    Fixed by 32dee03

  7. added a commit that references this issue on Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions