Skip to content

[css-values-5] Allow if() in descriptors #11941

Open
@valtlai

Description

@valtlai

Spec: https://drafts.csswg.org/css-values-5/#if-notation

Could we allow using the if() function in at-rule descriptors (if not already the case)?

My use case would be conditionally loading a hinted or unhinted font:

@font-face {
  font-family: 'The Font';
  src: if(
    media(resolution < 2x): url(the-font-hinted.woff2);
    else: url(the-font-unhinted.woff2)
  );
}

Without if() support (or nesting support, see #11940), we have to needlessly repeat the unchanged descriptors:

@media (resolution < 2x) {
  @font-face {
    font-family: 'The Font';
    src: url(the-font-hinted.woff2);
  }
}

@media (resolution >= 2x) {
  @font-face {
    font-family: 'The Font';
    src: url(the-font-unhinted.woff2);
  }
}

This isn’t DRY and is annoying when there are a lot of @font-face rules.

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