Choose an if() example

1. Feature queries: supports()

The condition can be a feature query, so a value can upgrade itself only where the browser can actually render it. Here the card asks for an oklch() background and falls back to a plain grey when oklch() is unavailable — one declaration instead of a @supports block plus an override.

.preview {
  background-color: if(
    supports(color: oklch(60% 0.2 250)):
      color-mix(in oklch, var(--c-primary) 20%, var(--c-bg));
    else: #cfd8e3;
  );
}

if() demo

One value, many conditions

Every example on this page styles this exact card. Switch the pill above and a different if() rule takes over — the markup never changes.

resize · toggle · inspect