Package detail

@webref/css

w3c24.2kMIT7.0.1-alpha

CSS definitions of the web platform

readme

CSS definitions of the web platform

This package contains a consolidated list of CSS features defined across specs, scraped from the latest versions of web platform specifications in webref. Fixes are applied to ensure that guarantees hold, including the ability to parse syntaxes associated with CSS features with CSSTree.

Important: If you're migrating from version 6, see the changelog for "How to upgrade" considerations.

API

The async listAll() method resolves with an object that contains lists of features grouped by feature type: atrules, functions, properties, selectors and types. Example:

const css = require('@webref/css');

const { atrules, functions, properties, selectors, types } = await css.listAll();

for (const feature of functions) {
  // do something with the object that describes the CSS function
}

Each CSS feature is described by:

  • a name key that contains the name of the feature
  • an href key that contains the URL (with a fragment) of the CSS spec that defines the feature

Many CSS features also have a value key that describes the syntax of the feature, as defined in the spec. This syntax can be parsed with the CSSTree Value Definition Syntax parser. Example:

const css = require('@webref/css');
const { definitionSyntax } = require('css-tree');

const { properties } = await css.listAll();
for (const property of properties) {
  if (!property.value) {
    continue;
  }
  const ast = definitionSyntax.parse(property.value);
  // do something with the abstract syntax tree
}

Additional keys may be set depending on the type of the CSS feature. For example:

  • At-rules have a descriptors key that contains the list of descriptors defined for the given at-rule.
  • Functions and types that are scoped to a property or other feature have a for key that contains the name of the scoping property or other feature.
  • Properties have a styleDeclaration key that contains the list of IDL attribute names that the property generates. A number of other keys may be set to describe the property's initial value, animation type and other parameters.

Additional notes:

  • Type names are enclosed in <>. For example: <frequency-percentage>.
  • When a feature is defined across different levels in the same spec series, the definition from the latest level is used.
  • When a property is extended with new values in different specs, href links to the base definition and value is the union (using |) of the syntaxes of the base and extended definitions.
  • When new descriptors are defined for an at-rule in different specs, descriptors contains the merged list of known descriptors.
  • When specs define the syntax of an at-rule in terms of <declaration-list> or <declaration-rule-list>, the value key contains an "expanded" syntax that leverages the syntax of the at-rule's descriptors.

Guarantees

The following guarantees are provided by this package:

  • All syntax values (the value keys) can be parsed by the version of CSSTree set in peerDependencies in package.json.
  • Feature names (the name keys) are unique per type provided that the for key is also taken into account for functions and types.
  • All features have an href key that targets the CSS spec that defines the feature. When the feature is extended across CSS specs, this URL targets the base definition.

Note: there is no guarantee that functions, properties and types referenced by other constructs actually exist. The grammar is known to be incomplete.

changelog

Changelog

This file documents breaking changes introduced in major releases of the @webref/css NPM package.

Webref adheres to Semantic Versioning, applied to data. A new major version is released whenever a breaking change is made to the data structure.

v7.0.0-alpha - 2025-06-10

CSS extracts are now consolidated into a single file.

Breaking changes

  • A single consolidated css.json file replaces CSS extracts per spec.

How to upgrade

In version 6, listAll() resolved with an object where the keys were spec shortnames, and the values mostly matched the structure of the consolidated object that the function now returns. On top of the consolidation itself, main differences are:

  • Functions and types were merged in a values category in version 6, they now appear in separate functions and types categories.
  • Functions and types that were scoped to another CSS feature appeared nested under that CSS feature in version 6. They now appear directly under functions and types with a for key that contains the name of the scoping feature.
  • The shortname of the spec (or specs) that defines a feature is no longer readily available (but note the href key targets the defining spec). If you need the specs' shortnames, please raise an issue to describe your use case.
  • The consolidation removes duplicates, merging extended definitions into a single feature. The definition from the latest spec level is used when a feature is defined in more than one level. If you need the definition from earlier levels, please raise an issue to describe your needs!
  • Some of the possible values that a CSS feature could take appeared nested under that feature definition in a values key in version 6. Such values are no longer reported in the new version: they were confusing in any case because they did not cover the whole range of values that a feature could take, and could contain values that were not atomic keyword values. Values could be re-introduced when CSS specs are more systematic about them. In the meantime, you will need to parse the feature's syntax (the value key) to extract keyword values.

v6.0.0 - 2022-11-28

Major re-write of CSS extracts listed in the package, following the release of Reffy v11.0.0

Breaking changes

  • Arrays are now used throughout instead of indexed objects.
  • Function names are no longer enclosed in < and > because they are not defined in specs with these characters (as opposed to types). Beware though, references to functions in value syntax do use enclosing < and > characters.
  • The property valuespaces at the root level is now named values. An array is used there as well. The values property lists both function and type definitions that are not namespaced to anything in particular (it used to also contain namespaced definitions).

Added

  • Selectors are now reported under a selectors property at the root level.
  • Possible values that some definition may take are now reported under a values property directly within the definition.
  • Functions and types that are namespaced to some other definition are included in the list of values of that definition.
  • Anomalies detected in the spec are now reported under a warnings property at the root of the extract. Four types of anomalies are reported:
    1. Missing definition: when a production rule was found but when the spec does not include a corresponding <dfn> (or when that <dfn> does not have a data-dfn-type attribute that identifies a CSS construct)
    2. Duplicate definition: when the spec defines the same term twice.
    3. Unmergeable definition: when the spec defines the same property twice and both definitions cannot be merged.
    4. Dangling value: when the spec defines a CSS "value" definition (value, function or type) for something and that something cannot be found in the spec
  • To distinguish between function, type and value definitions listed in a values property, definitions that appear in a values property have a type property.

Additional notes

  • Only namespaced values associated with a definition are listed under its values property. Non-namespaced values are not. For instance, <quote> is not listed as a value of the <content-list> type, even though its value syntax references it. This is to avoid duplicating constructs in the extracts.
  • Values are only listed under the deepest definition to which they apply. For instance, open-quote is only listed as a value of <quote> but neither as a value of the <content-list> type that references <quote> nor as a value of the content property that references <content-list>. This is also to avoid duplicating constructs in the extracts.
  • Some of the extracts contain things that may look weird at first, but that is "by design". For instance, CSS Will change defines a <custom-ident> value construct whose actual value is the <custom-ident> type construct defined in CSS Values. Having both a namespaced value and a non-namespaced <type> is somewhat common in CSS specs.