Hardcoding the Bootstrap breakpoints in media queries of converted CSS

Hi!

Context

As part of moving away from LESS (umbrella XWIKI-22668), we keep hitting the same blocker: CSS variables cannot be used in media queries. @media (max-width: var(--screen-xs-max)) is not valid CSS, so browsers drop the whole media query and the rules inside it silently never apply. This is tracked in XWIKI-23315.

The native solution, @custom-media, is not usable yet. According to caniuse, it is unsupported in Chrome, Edge and Safari, and disabled by default in Firefox, for 0% of global usage. There is no ETA for it.

Meanwhile, 12 LESS sources still use @screen-* variables in media queries: 9 skin files (action-menus, admin, annotations, edit, forms, layout, livetable, misc, tables), the PDF export sheet, Help.Code.VelocityMacros and the menu macro. As long as XWIKI-23315 is open, none of these can become plain CSS, and neither can reactive.less (XWIKI-23666).

Some facts about the breakpoint values:

  • They come from Bootstrap’s variables.less: @screen-xs 480px, @screen-sm 768px, @screen-md 992px, @screen-lg 1200px. The -max variants are the next breakpoint minus 1px, e.g. @screen-xs-max is 767px.
  • 16 of the 23 color themes we ship redefine them, all with exactly these default values.
  • Beyond XWiki Standard, I searched all 484 repositories of the xwiki, xwiki-contrib and xwiki-labs GitHub organizations, leaving out the security advisory forks of xwiki-platform, for any definition of a @screen-* or $screen-* variable or a --screen-* CSS property. Of the 663 definitions found, all but 8 repeat Bootstrap’s default values. The 8 others come from 2 places, and neither changes the screen breakpoints of an XWiki skin:
    • The PDF export sheet redefines @screen-sm-min, @screen-md-min and @screen-lg-min to paper sizes, only to regenerate the Bootstrap grid under @media print in its own skin extension. It doesn’t affect the skin’s compiled CSS today, so hardcoding the values elsewhere changes nothing for it.
    • xwiki-labs/openpaas-esn is a fork of Linagora’s OpenPaaS ESN, not an XWiki extension.
  • Only 2 extensions outside xwiki-platform use the breakpoint variables in their media queries, searchgrid and captcha-recaptcha. They keep working, since the proposal doesn’t remove the LESS variables.
  • They are not a W3C standard, but they have become de facto conventions, and the one we rely on most is the most widely shared. Our media queries outside of Bootstrap mostly use the 768px split: 12 times for @screen-xs-max, @screen-sm-min or @screen-sm, against 9 for 992px, 3 for 1200px and 3 for 480px.
Phone / tablet split Next breakpoints
Bootstrap 3, our fork 768px 992px, 1200px
Bootstrap 5.3 768px (md), plus 576px (sm) 992px, 1200px, 1400px
Tailwind CSS 768px (md), plus 640px (sm) 1024px, 1280px, 1536px
Bulma 769px, mobile is up to 768px 1024px, 1216px, 1408px
Foundation 640px 1024px, 1200px, 1440px
MUI 600px 900px, 1200px, 1536px
  • Bootstrap kept 768px, 992px and 1200px unchanged from version 3 to 5.3. Its documentation says they are “representative of a subset of common device sizes and viewport dimensions”.
  • Real devices fall clearly on each side of 768px. The 6 most common phone resolutions are between 360px and 414px wide, and the most common tablet resolution is 768x1024 (StatCounter, tablets, September 2026). Customizing the breakpoint a bit would not change which side a common phone or tablet lands on.
  • --screen-xs-max already exists as a CSS variable, but the file that defines it says these CSS variables “should not be considered as API yet”.
  • We already hardcode the breakpoints in 12 media queries without any agreed rule.

Proposal

At least until browsers support custom media queries:

  1. The Bootstrap breakpoints are not considered as API. Customizing them would not be supported. A theme or skin that changes @screen-* is not guaranteed to change every media query in XWiki Standard.
  2. Converted CSS are allowed to hardcode the breakpoint value in their media queries, with a comment naming the LESS variable it stands for.
  3. We document this rule in the XHTML & CSS code style and rediscuss it once @custom-media is usable. Searching for the comment would then find every place to update easily.

Opinion

Alternatives I considered:

  • Keep variable media queries in LESS until XWIKI-23315 is done. Customization is preserved, but the 12 files above and reactive.less stay in LESS for an unknown time, compiled on every color theme change. Since the native fix has no date, this means blocking part of the migration indefinitely.
  • Toggle a class from JavaScript, by reading --screen-xs-max with matchMedia and setting a class on <body>. This keeps the value customizable, but the layout depends on JavaScript, flickers on load, and adds a pattern used nowhere else.

+1 for the proposal because:

  • The customization it gives up is theoretical: no theme we ship, and no skin, theme or extension in the xwiki and xwiki-contrib organizations, changes the screen breakpoints.
  • There is little reason to customize them anyway: 768px is the split used by Bootstrap, Tailwind and Bulma, and it sits nicely between the standard phone and tablet widths.
  • It unblocks the conversion of 13 LESS sources, which is the point of XWIKI-22668: performance, and no recompilation on color theme changes.
  • It turns the 12 existing hardcoded breakpoints from an accident into a rule, and fixes the 767/768px inconsistency.
  • The comment keeps the decision reversible: once @custom-media lands, we can restart a discussion to figure if we want them back.

The risk is a custom skin or theme that does change the breakpoints. After this change, the Bootstrap grid, which stays in LESS, would follow it while the converted XWiki rules would not. I think that’s acceptable if we mention it in the release notes, but I’d like to know whether anyone knows of such customizations.

Conclusion

  • Do you agree to make explicit that the Bootstrap breakpoints are not customizable API at least until custom media queries are supported?
  • Do you agree with hardcoding those values in converted CSS, with a comment referencing the variable?
  • Do you know of any skin or theme that changes those breakpoints?

I’ll close this topic in a week if it doesn’t spur a large discussion :slight_smile:

Thank you!
Lucas C.

AFAICS Cristal hardcodes its breakpoints too, this decision could make it easier to share the design system between the current XS and Cristal :slight_smile:

@tkrieck The hard-coded value in Cristal is 600px though, which is different from what we have in XS so far. Was this value discussed and thought about or is it just an arbitrary value that was picked during Cristal dev?

The latter, I think it was based on Shoelace at the time, but I might be wrong. But I agree that both should be the same.

@mleduc @mflorea What do you think of this proposal? This could be considered a breakage for some use cases, so I want to make sure we’re agreeing before I spend time on those migrations.

+1

Thanks,
Marius

I’ll close this discussion for now and propose hard-coded values implementations for the LESS to CSS migrations. :slight_smile: