CSS Expressive Generalizations and Gadgetry Level 1

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-egg/
Latest published version:
https://www.w3.org/TR/css-egg/
Feedback:
CSSWG Issues Repository
Inline In Spec
Editor:
Florian Rivoal (Invited Expert)
Suggest an Edit for this Spec:
GitHub Editor

Abstract

This module extends the vocabulary of CSS with terms frequently used in certain domains, making it easier for authors to write understandable and maintainable style sheets.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-egg” in the title, like this: “[css-egg] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 2 November 2021 W3C Process Document.

1. Introduction

This section is not normative.

As evidenced by the extraordinary variety of designs found on the web, CSS is a very expressive language, capable of describing unlimited styles and layouts. However, one of the design goal of CSS was also to make it easy to learn and to read by people. Making it simple for untrained authors to read and guess the meaning of a style sheet after only a basic introduction to CSS has contributed greatly to the success of the language.

In addition, easy-to-read style sheets are also easier to maintain.

In this spirit, this specification introduces a few new values and units, which, while not bringing significant new capabilities to the web platform, makes it possible to write style sheets that are easier to read than ever before, by enabling authors to use values and units that are familiar and appropriate for the domain they are working on.

1.1. Module Interactions

This module extends:

1.2. Value Definitions

This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS3-VALUES]. Value types not defined in this specification are defined in CSS Values & Units [CSS3-VALUES]. Combination with other CSS modules may expand the definitions of these value types.

In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.

2. Extended Units

CSS provides several absolute length units such as cm or in, as well as several <time> units such as s or ms They can all be converted between each other at fixed ratios, but are nonetheless provided in recognition that it is most convenient for authors to use units that they are most familiar with, or that some designs are more naturally expressed in some units than others.

2.1. Astronomical units

This specification adds four absolute length units which should be appreciated by authors in fields such as astronomy and fundamental physics. The new units are ls, pc and their sub multiples pls and apc. They are defined as physical units.
unit name equivalence
apc attoparsec 1 apc = 3.086 cm
pls picolightsecond 1 pls = 1.133 px
ls lightsecond 1 ls = 1012 pls
pc parsec 1 pc = 1018 apc

Note: Lightsecond was chosen instead of the more familiar lightyear to make sure that layouts computed during leap years would be unambiguously identical to those computed during non-leap years.

Note: This specification does not address relativistic effects of scrolling or animations and transitions at (or beyond) the speed of light.

When writing a page representing the inner solar system at scale, the following markup and style could be used.
<div id=space>
  <div class=celestial-body id=sun data-color=yellow
    data-radius=2.3ls>
    <div class=celestial-body id=mercury data-color=lightgray
      data-radius=0.0081ls data-semimajor-axis=193ls data-orbital-period=6.278ftn></div>
    <div class=celestial-body id=venus data-color=#FFD881
      data-radius=0.020ls data-semimajor-axis=361ls data-orbital-period=16.05ftn></div>
    <div class=celestial-body id=earth data-color=blue
      data-radius=0.021ls data-semimajor-axis=499ls data-orbital-period=26.09ftn>
      <div class=celestial-body id=moon data-color=#E0E0E0
        data-radius=0.0057ls data-semimajor-axis=1.28ls data-orbital-period=2.109ftn></div>
    </div>
    <div class=celestial-body id=mars data-color=#AD674D
      data-radius=0.011ls data-semimajor-axis=760ls data-orbital-period=49.07ftn></div>
</div></div>
<style>#space {
  background:black;
  overflow:hidden;
  position: relative;
}
.celestial-body {
  position:absolute;
  left: 50%; top: 50%;
  border-radius: 50%;
  border-style:solid attr(data-radius length, 0) attr(data-color color, white);
  margin: calc(-1 * attr(data-radius length, 0));
  transform-origin: attr(data-radius length, 0)
                    calc(attr(data-radius length, 0) + attr(data-semimajor-axis length, 0));
  animation: orbit linear infinite attr(data-orbital-period time, 0);
}
@keyframes orbit {
  from { transform: translateY(calc(attr(data-semimajor-axis length, 0) * -1)) rotate(0); }
  to { transform: translateY(calc(attr(data-semimajor-axis length, 0) * -1)) rotate(-360deg); }
}
</style>

The following is a disappointingly small sample rendering (not at scale) of what this would look like. With the new units and more space than this specification can offer, this would instead be overwhelmingly awesome.

2.2. Traditional time units

While the s and ms units defined in [CSS3-VALUES] are appropriate for very short durations, their use to express longer time spans is inadequate. Moreover, authors may sometimes wish to use less dry terminology and prefer more expressive and vivid language. This specification therefore introduces two <time> units: ftn and its subdivision mftn.

unit name equivalence
ftn Fortnight 1 ftn = 1209600 s
mftn Millifortnight 1 ftn = 1000 mftn

2.3. Speech rate

This specification introduces an new dimension, together with a new unit to be used with this dimension. The <speech-rate> described the speed at which a text is read aloud. It can be expressed using the tmbl unit, as defined below.

unit name definition
tmbl Timble This is the rate of speech of Sir Tim Berners-Lee when delivering a speech.

Note: Authors are advised to be cautious when using this unit, as it can easily lead to rates of speech that are too high for the listener to follow. 1tmbl is generally considered to be about the maximum rate a listener without special training can sustainably understand while paying close attention. Consider reducing the speed when the audience is distracted, tired, or comprises many non-native speakers. These factors are cumulative. For dictation or during meetings for which live minutes are taken, a rate of 0.3tmbl is more appropriate.

For languages other than English, should 1tmbl be defined as the same number of words per minute as 1tmbl in English? This seems problematic as we do not have a precise definition for word, and because average word length can vary significantly per language. Alternatively, defining 1tmbl as the speed at which Tim Berners-Lee speaks in that language is also problematic, given that there are languages that He does not speak at all. Tim Berners-Lee has provided an alternative definition of the timble, as documented by Doug Schepers: speech at more than 1 timble is difficult to understand; speech below 1 timble is simply boring. Doug himself defines it as the uppermost rate of speech at which a normal person can understand what’s being said in their native language.

2.3.1. Extension to the voice-rate property

This specification extends the voice-rate property, so that the tmbl unit can be used.

Name: voice-rate
New values: [normal | x-slow | slow | medium | fast | x-fast | <speech-rate>] || <percentage>

Should negative values be allowed for <speech-rate> for reversed speech?

2.4. Device performance

Device performance is known to be a perfectly linear quantity with a total ordering consistent across different kinds of workloads. It is desirable to be able to design adaptive content that works across a range of user agent and device performance.

This specification introduces an new dimension, together with a new unit to be used with this dimension.

The <device-performance> describes the performance of the current device and user agent combination. It can be expressed using the adafish unit, as defined below.

unit name definition
adafish Adafish This is the maximum number of fish that can be displayed on the current device and user agent combination in Ada Rose Cannon’s Fish Garden without the user agent dropping any frames.

Note: Ada Rose Cannon’s Fish Garden supports changing the number of fish through the `?fish=` query parameter, e.g. this link will show 50 fish

2.4.1. Extension to the @media rule: The performance feature

Name: performance
For: @media
Value: <device-performance>
Type: range

The performance media feature describes the performance characteristics of the current device and user agent combination at the current time. It SHOULD incorporate transient and permanent environmental factors affecting performance such as the current room temperature, the accumulation of dust in the device’s cooling system, and the existence of spilled lemonade or coffee on the device’s motherboard.

When querying the performance feature the user agent SHOULD ensure that it is querying a recent value. The user agent MAY in the background run Ada’s Fish Garden with various parameters to estimate this value. If device performance characteristics change while content is being viewed, the user agent MUST recompute its value for performance, potentially restyling the document.

This feature is useful for designing robust content that adapts to different device characteristics.
@media (min-performance: 1000adafish) {
  #very-cool-demo-with-blinky-lights {
    display: block;
  }
}

@media (max-performance: 1000adafish) {
  #really-bad-demo-with-no-blinky-lights-whatsoever {
    display: block;
  }
}

2.4.2. Fingerprinting concerns

This API may be used for gleaning information about the user’s environment, which may be used to fingerprint them. This is recognized to be an acceptable loss for the momentous benefits this API is expected to provide the web platform.

3. Double Rainbow

<gradient> allows sophisticated visual effects, but they are tedious to write, review and maintain as non trivial gradients cannot easily be visualized by merely reading the source. This specification introduces a new syntax to describe a particular kind of <radial-gradient()>: double rainbows. This spectacular visual effect which would improve most web pages is currently underused due to the difficulty of specifying it correctly.

The <gradient> syntax is extended to accept <double-rainbow()> in addition to the other values defined in [CSS4-IMAGES]

double-rainbow() = double-rainbow(
   <position> [, [ <extent> | <length-percentage [0,∞]>]]?
)
<extent> = closest-corner | closest-side | farthest-corner | farthest-side

<length> or <percentage> gives the radius of the outermost circle of the double rainbow explicitly. Percentages values are relative to the corresponding dimension of the gradient box. Negative values are invalid.

If the second argument is omitted, the default value is farthest-side.

This feature was initially introduced by Opera Software. The following page, when viewed in Opera (between version 11.60 and 12.16), demonstrates tasteful use of double rainbows: http://media.opera.com/media/press/2011/unicorn/

By combining double-rainbow() with about:unicorn [FETCH], modern web standards can be used to achieve a similar effect.

<img src="about:unicorn"
style="background: double-rainbow(bottom, closest-corner)">

Acknowledgments

Thanks especially to the following people for their ideas, feedback, and experimental implementations (in alphabetical order by first name): Anne van Kesteren, Bruce Lawson, Chris Mills, Doug Schepers, Daniel Glazman, Leif Arne Storset, Paul Verbeek, Peter Linss, Tim Berners-Lee (assuming the quotation by Doug correctly records what Tim said).

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-COLOR-5]
Chris Lilley; et al. CSS Color Module Level 5. URL: https://andreubotella.com/csswg-auto-build/test/css-color-5/
[CSS-CONDITIONAL-3]
David Baron; Elika Etemad; Chris Lilley. CSS Conditional Rules Module Level 3. URL: https://andreubotella.com/csswg-auto-build/test/css-conditional-3/
[CSS-IMAGES-3]
Tab Atkins Jr.; Elika Etemad; Lea Verou. CSS Images Module Level 3. URL: https://andreubotella.com/csswg-auto-build/test/css-images-3/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. URL: https://andreubotella.com/csswg-auto-build/test/css-values-4/
[CSS2]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. URL: https://andreubotella.com/csswg-auto-build/test/css2/
[CSS3-VALUES]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. URL: https://andreubotella.com/csswg-auto-build/test/css-values-3/
[CSS3SPEECH]
Daniel Weck. CSS Speech Module. URL: https://andreubotella.com/csswg-auto-build/test/css-speech-1/
[CSS4-IMAGES]
Tab Atkins Jr.; Elika Etemad; Lea Verou. CSS Image Values and Replaced Content Module Level 4. URL: https://andreubotella.com/csswg-auto-build/test/css-images-4/
[MEDIAQUERIES-5]
Dean Jackson; et al. Media Queries Level 5. URL: https://andreubotella.com/csswg-auto-build/test/mediaqueries-5/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119

Informative References

[FETCH]
Anne van Kesteren. Fetch Standard. Living Standard. URL: https://fetch.spec.whatwg.org/

Property Index

No properties defined.

@media Descriptors

Name Value Initial Type
performance <device-performance> range

Issues Index

For languages other than English, should 1tmbl be defined as the same number of words per minute as 1tmbl in English? This seems problematic as we do not have a precise definition for word, and because average word length can vary significantly per language. Alternatively, defining 1tmbl as the speed at which Tim Berners-Lee speaks in that language is also problematic, given that there are languages that He does not speak at all. Tim Berners-Lee has provided an alternative definition of the timble, as documented by Doug Schepers: speech at more than 1 timble is difficult to understand; speech below 1 timble is simply boring. Doug himself defines it as the uppermost rate of speech at which a normal person can understand what’s being said in their native language.
Should negative values be allowed for <speech-rate> for reversed speech?