Style variables

Last modified by Lucas Charpentier (Sereza7) on 2025/03/27

Currently, XWiki Standard with its Flamingo Skin support three kinds of style variables. They are (ranging from the oldest to the newest):

  • The old colorTheme variables
  • The LESS variables (Flamingo colorTheme + design system inherited from bootstrap + Misc additions from the Flamingo skin)
  • XWiki 17.3.0+ The CSS properties

Migrating from LESS to CSS properties

This section contains a few points that could be important when migrating LESS styles to using the CSS properties. Those are not community rules to be followed, but just indications to make it easier to migrate emoticon_smile

Warning

Today, there is no way to migrate any LESS mixin to CSS one to one. In order to migrate any advanced use of mixins, an additional class should be added for the styles on the HTML.

Syntax sugar

Native CSS is a bit more wordy than LESS:

  • Variables start with a double dash (--) instead of an arobase (@)
  • All use of a CSS variable should be made in a var block.
  • All operations that you could write in your LESS must be made in a calc block.
--popover-arrow-color:                 var(--popover-bg);
--popover-arrow-outer-width:           calc(var(--popover-arrow-width) + 1px);

Units in CSS calculus

LESS doesn't have any clearly defined unit system. CSS has a very strict unit system (some improvements to make it a bit looser and easier to use are discussed though). If a formula doesn't work in CSS, it's probably because the units do not respect the constraint of the operators:

  • Addition and substraction, both values must have the same unit
  • Multiplications and divisions, only one value has an unit, the second one is unitless.

The exact rules are more precise than that.

Migrating color functions

To migrate LESS color functions, you can use the CSS color or hsl functions:

hsl(from var(--well-bg) h s calc(l - 0.07))

HSL is useful for most operations, color is really only useful for transparency calculations.
LESS color functions work directly with additions: darken(@well-bg, 7%) is the same as the snippet above. This is slightly different from calc( l * (1-0.07)) which was how I assumed LESS handled its operations at first.

Information

You can also use the CSS color-mix with black or white to darken or lighten a color.

Using CSS variables in LESS

Sometimes you want to start migrating a file without being able to move it all at once. In this kind of situation, you'll need to know about how to use CSS variables in a LESS file.

The LESS parser we use in XWiki standard is not maintained enough to ensure a good compatibility with current CSS. It does not work well with CSS variables directly. The usual solution to escape things in LESS works well for most cases: a tilde and the escaped content in between quotes.

-/**/-navbar-default-bg:                ~"var(--brand-primary)";
-/**/-navbar-default-border:            ~"color-mix(in srgb, var(--navbar-default-bg), black 6.5%)";

But, a quirk of the parser is that this syntax does not work when we're trying to use it for an assignation. One hack that's not too bad looking that works for those variable assignations is to add an empty comment block in the middle. It prevents the LESS parser from associating the two dashes together and assume this is the end of an HTML comment. You can see this workaround in the example above.

Warning

Contrary to LESS variables that are global by default, CSS properties should be defined in a block. Either their own with the @property query, or inside a ruleset. Typically, in order to make CSS properties global, just put their assignations in a :root { } block.

 

Get Connected