CSS Expressive Generalizations and Gadgetry Level 1

Editor’s Draft,

This version:
https://drafts.csswg.org/css-egg/
Latest published version:
https://www.w3.org/TR/css-egg/
Issue Tracking:
GitHub
Inline In Spec
Editor:
Florian Rivoal (Vivliostyle)

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, in speech, 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.

GitHub Issues are preferred for discussion of this specification. When filing an issue, please put the text “css-egg” in the title, preferably like this: “[css-egg] …summary of comment…”. All issues and comments are archived, and there is also a historical archive.

This document was produced by the CSS Working Group (part of the Style Activity).

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 September 2015 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:

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?

3. Double Rainbow

<gradient> allows sophisticated visual effects, but they are tedious to write, review and maintain as non trivial gradients cannot easily be visualised 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>]]?
)
<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.

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.

Requirements for Responsible Implementation of CSS

The following sections define several conformance requirements for implementing CSS responsibly, in a way that promotes interoperability in the present and future.

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 property 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.

Implementations of CR-level Features

Once a specification reaches the Candidate Recommendation stage, implementers should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec, and should avoid exposing a prefixed variant of that feature.

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-BACKGROUNDS-3]
CSS Backgrounds and Borders Module Level 3 URL: https://drafts.csswg.org/css-backgrounds-3/
[CSS-IMAGES-3]
CSS Image Values and Replaced Content Module Level 3 URL: https://drafts.csswg.org/css-images-3/
[CSS-IMAGES-4]
CSS Image Values and Replaced Content Module Level 4 URL: https://drafts.csswg.org/css-images-4/
[CSS-SPEECH-1]
CSS Speech Module Level 1 URL: https://drafts.csswg.org/css-speech-1/
[CSS3-VALUES]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 3. 11 June 2015. CR. URL: http://dev.w3.org/csswg/css-values/
[CSS3SPEECH]
Daniel Weck. CSS Speech Module. 20 March 2012. CR. URL: https://www.w3.org/TR/css3-speech/
[CSS4-IMAGES]
Elika Etemad; Tab Atkins Jr.. CSS Image Values and Replaced Content Module Level 4. 11 September 2012. WD. URL: https://www.w3.org/TR/css4-images/
[FILTERS-1]
Filter Effects Level 1 URL: https://drafts.fxtf.org/filters-1/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Informative References

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

Property Index

No properties defined.

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?