Skip to content

[css-grid-2] Subgrid auto repeat calculation when <line-name-list> size isn't a multiple of remaining subgrid tracks #8493

Open

Description

@KurtCattiSchmidt

https://www.w3.org/TR/css-grid-2/#auto-repeat

If we have a subgrid with the following column definition:

grid-template-columns: subgrid repeat(auto-fill, [y] [z]);

...and a subgrid that spans 1 column, should the auto-repeat count be 0? This is how Firefox and Safari have implemented it (and how I'm working on implementing it on Chromium).

Another option would be to just insert the [y] once, and have a half repetition. The spec says "repeats enough times for the name list to match the subgrid’s specified grid span (falling back to 0 if the span is already fulfilled).", but I would argue that in this example, the span isn't fulfilled, so it could be clarified further.

To generalize, this situation involves any time the remaining tracks for calculating a subgrid's auto-repeat is not a multiple of the size of the numbers of lines in the auto repeater's . Should the number of repetitions be maximized (and thus allow for a non-integer number of repeats), or should it be floored at the largest whole number that will fit?

Note that the spec linked above indicates that the number of repetitions should be an integer, but only in the standalone grid section. For subgrids, this is ambiguous, but I do think that the current interoperable behavior makes sense.

There are some WPT tests reinforcing that it should be an integer value floored at 0, such as http://wpt.live/css/css-grid/subgrid/repeat-auto-fill-008.html - see sub-case fill-0t. An extra half repetition could be used, so instead of:

grid-template-columns: subgrid [w] repeat(auto-fill, [y] [z]) [x]; /* [w] [y] [z] [y] [z] [x] [] */

It could be resolved to:

grid-template-columns: subgrid [w] repeat(auto-fill, [y] [z]) [x]; /* [w] [y] [z] [y] [z] [y] [x] */

Activity

  1. bfgeek commented on Feb 23, 2023

    @bfgeek
  2. Loirooriol commented on Feb 24, 2023

    @Loirooriol
    Contributor

    I'd keep it consistent with the standalone axis and do not allow half repetitions.

  3. Loirooriol commented on Feb 24, 2023

    @Loirooriol
    Contributor

    If authors want partial repetitions, we could add something like repeat(auto-fit partial, ...) and use it for both standalone and subgrid cases.

  4. tabatkins commented on Feb 24, 2023

    @tabatkins
    Member

    Yeah, the spec needs fixing, but it definitely is intended to be an integer number of whole repetitions. Partial repetitions are fragile and unlikely to be what the author wants.

  5. fantasai commented on Mar 28, 2025

    @fantasai
    Collaborator

    My reading is actually the opposite: that we should be allowing partial repetitions in this case. That's more likely to be what the author wants than to have a handful of unnamed lines at the end, imho.

  6. css-meeting-bot commented on Aug 13, 2025

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-grid-2] Subgrid auto repeat calculation when <line-name-list> size isn't a multiple of remaining subgrid tracks, and agreed to the following:

    • RESOLVED: define that subgrid repeat works exactly the same as grid repeat
    The full IRC log of that discussion <JoshT> fantasai: there was a question of what to do if the subgrid has a repeat() with multiple line names
    <Kurt> q+
    <TabAtkins> q+
    <JoshT> ... let's say two line names but the number of lines in subgrid is odd. do you just cut the last repetition or just the names don't ger assigned for the last section
    <JoshT> ... my intent when I wrote the spec was that we only do whole numbers in repetitions in the repeat functions
    <JoshT> ... here the number of lines is set and we just have to give names
    <JoshT> ... if we cut off at the last rep, there are some lines that don't get names
    <JoshT> ... but if we clamp, they all get names
    <astearns> ack Kurt
    <JoshT> ... that seems more reasonable than cutting up the last repetition
    <JoshT> Kurt: was going to distingush between whether subgrid span size is large enough for a single repeat
    <JoshT> ... but I see that's generalised to fantasai's case for splitting the remainder
    <JoshT> ... that was my question. i think it's the same problem
    <JoshT> ... but my concern with changing this is: is it safe to change at this point?
    <astearns> ack TabAtkins
    <JoshT> ... subgrid is shipped. are we OK changing how auto-repeat changes in these scenarios?
    <JoshT> TabAtkins: I do not think we should change behaviour
    <JoshT> ... if you have several repeated lines, you are probably depending on them as a block
    <JoshT> ... and putting things next to those lines. so if you have partial repetition, your layout will be broken
    <JoshT> ... they'll be too short or ???, etc
    <JoshT> ... in normal grid, we don't allow partial repetitions to prevent accidentally getting a partial bit of something the author intended to be a unit
    <JoshT> ... so like here if you're just defining line names
    <oriol> q+
    <JoshT> ... if there was a great reason to diverge, we should be self-consistent when we can. so I think the argument here is to be consistent anyway
    <astearns> ack oriol
    <JoshT> oriol: I agree with TabAtkins about consistency argumeny
    <JoshT> ... I had idea in issue. maybe partial keyword to provide to repeat function to opt into this behaviour
    <kizu> +1 to `partial` keyword, including in regular grids as well
    <JoshT> fantasai: I'm OK with it!
    <JoshT> astearns: resolution for this issue is to keep the subgrid autorepeat consistent with the grid autorepeat, but make a new issue for the partial keyword in the repeat function if we find a use case for it
    <JoshT> ... is there any spec change for this issue needed?
    <JoshT> fantasai: seems like there should be some clarification
    <JoshT> TabAtkins: this was raised on the assumption that something is missing in the spec
    <JoshT> RESOLVED: define that subgrid repeat works exactly the same as grid repeat
    <JoshT> Kurt: that resolves things
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