There is a proposal for user agent properties. To sum things up, browsers would expose user settings so that you can use them in your CSS.
For instance:
body {
font-size: const(user-font-size);
font-family: const(user-font-family);
/* And so on and so forth… */
}
As a matter of fact, we have something like this in Readium CSS, it is used for internal purposes but, on the authoring side, there are issues to deal with:
- doesn’t work in Kindle;
- crashes Adobe’s RMSDK ePub2 parser;
- ePubCheck currently reports CSS custom properties as errors (it shouldn’t once support for EPUB 3.1 is added);
- it requires progressive enhancement, therefore extra work.
What you would have to do:
body {
text-align: justify;
hyphens: auto;
}
@supports (--var: a) {
body {
text-align: var(--USER__textAlign, justify);
hyphens: var(--USER__bodyHyphens, auto);
}
}
To clarify:
- you write styles for Reading Systems which don’t support CSS custom properties (a.k.a. CSS variables);
- you write a feature query for Reading Systems which support them;
- you use those user properties, with a fallback if they’re not set e.g. if the user hasn’t set
text-align
, thenjustify
is the fallback.
Examples of what you could currently do with those custom properties:
- full-width containers;
- icons and/or text in the margins;
- inverting images in night mode;
- adjusting
background-color
+border-color
in night modes; - adjusting the font-sizes based on the
font-size
user setting; - more generally, authoring your CSS so that it is 100% compatible with user settings.
After thorough testing, I do believe this is the simplest way forward for both authors and developers. But it implies a new paradigm and best practices.
Finally, it could probably make a “Do Not Touch my CSS” switch an easier implem, as user settings would be an integral part of the authors’ CSS. Indeed, this is by far the biggest pain point we have to deal with at the RS’ CSS level—i.e. a lot of !important
s + a whole lot more of details to take into account for each user setting. In other words, for such a mechanism to exist, the author’s CSS must be user-centric.
What a user-centric stylesheet would look like (sort of, this is still a proposal in its early days).
The author’s styles could be defined as fallbacks there, in case the user setting is not set. Once again, this is a simplistic example and we need to wait and see where the proposal is going.