# CSS: Unrecognized at-rule “@font-feature-values”

> Canonical HTML version: https://rocketvalidator.com/html-validation/css-unrecognized-at-rule-font-feature-values
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `@font-feature-values` at-rule lets you define human-readable names for OpenType font feature indexes, which you can then reference using properties like `font-variant-alternates`. For example, instead of remembering that swash index `1` maps to a "fancy" style, you can define a named value and use it semantically throughout your CSS. This is a legitimate and useful feature defined in the [CSS Fonts Module Level 4](https://drafts.csswg.org/css-fonts-4/#font-feature-values) specification.

The validation error occurs because the W3C CSS validator does not always keep pace with newer CSS specifications. The `@font-feature-values` rule, along with its associated feature type blocks like `@swash`, `@styleset`, `@character-variant`, `@ornaments`, `@annotation`, and `@stylistic`, may simply not be in the validator's recognized grammar yet. This does not mean your CSS is broken or invalid — it means the validator has a gap in its coverage.

That said, there are practical reasons to consider alternatives. If you need to pass strict W3C validation (for example, as a project requirement or contractual obligation), or if you need to support older browsers that lack `@font-feature-values` support, the `font-feature-settings` property offers a more widely recognized way to activate OpenType features. The tradeoff is that `font-feature-settings` uses raw four-character OpenType feature tags instead of friendly names, making it less readable but more portable.

## How to Fix

You have several options:

1. **Ignore the warning.** If your target browsers support `@font-feature-values`, the CSS is valid per the spec. The validator error is a false positive.
2. **Move the at-rule to an external stylesheet.** If you're validating HTML and the CSS is in a `<style>` block, moving it to an external `.css` file may help you separate concerns and skip CSS validation during HTML checks.
3. **Replace with `font-feature-settings`.** Use the lower-level property to activate OpenType features directly by their tag codes.

## Examples

### Code that triggers the validation error

```css
@font-feature-values "MyFamily" {
  @swash {
    fancy: 1;
  }
}

p {
  font-family: "MyFamily", serif;
  font-variant-alternates: swash(fancy);
}
```

The validator does not recognize `@font-feature-values` and flags it as an error, even though this is spec-compliant CSS.

### Fixed: Using `font-feature-settings` instead

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Font Feature Example</title>
    <style>
      p {
        font-family: "MyFamily", serif;
        font-feature-settings: "swsh" 1;
      }
    </style>
  </head>
  <body>
    <p>This text uses OpenType swash glyphs via font-feature-settings.</p>
  </body>
</html>
```

The `font-feature-settings` property accepts OpenType feature tags directly. Common tags include `"swsh"` for swashes, `"smcp"` for small caps, `"liga"` for standard ligatures, and `"onum"` for oldstyle numerals. This approach avoids the unrecognized at-rule error entirely.

### Fixed: Keeping `@font-feature-values` with a fallback

If you want to use the more readable `@font-feature-values` syntax while also providing fallback support, you can combine both approaches:

```css
p {
  font-family: "MyFamily", serif;
  font-feature-settings: "swsh" 1;
  font-variant-alternates: swash(fancy);
}

@font-feature-values "MyFamily" {
  @swash {
    fancy: 1;
  }
}
```

Browsers that understand `font-variant-alternates` and `@font-feature-values` will use the named value. Others will fall back to `font-feature-settings`. The validation error will persist with this approach, but your CSS will be robust and spec-compliant regardless.
