Skip to content

Consider avoiding whitespace minification in custom property values #2864

Description

@nex3

In the 2021 draft of CSS variables 1, it was explicitly specified that custom properties should be serialized exactly as specified by the author, including whitespace. This is counter to the behavior widely implemented by browsers before that point, in which whitespace in the serialized property values was collapsed into a single space character.

Based on the old browser behavior, Sass also collapses custom property whitespace in order to emit smaller stylesheets and avoid unsightly whitespace artifacts from custom properties that include newlines. However, that is now contrary to the CSS specification and so a CSS compatibility issue. Browsers currently somewhat follow the specification, preserving whitespace (and comments) everywhere except for the beginning and (on Chrome) the end of property values.

I do feel some amount of hesitation here, though. Although Sass is committed to meticulous CSS compatibility, I don't know of any evidence of an actual use-case for not folding whitespace; the motivating example given in the spec for preserving the exact format focuses on non-whitespace characters. What's more, it's likely that this would be seen as a behavior regression for the users (likely a substantial majority) who want Sass to emit minimal or visually-attractive stylesheets.

See also cssnano/cssnano#1457 (comment), where this same concern is being considered by cssnano.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions