Why is this an issue?

Browsers discard a declaration whose value its property does not accept, so the intended style never applies and the element keeps the value from an earlier declaration, or its inherited or initial value. This rule raises an issue on the first part of a value that the property’s CSS grammar rejects, such as a misspelled or borrowed keyword, a quoted keyword, or a number where a length is required. Replace that part with a value the property accepts.

This rule applies only to plain CSS. It does not raise issues in SCSS, Sass, or Less files.

Code examples

Replace the misspelled keyword and the keyword that the property does not accept:

Noncompliant code example

.card {
  position: absolut; /* Noncompliant: misspelled keyword */
  border-radius: none; /* Noncompliant: "none" is not a "border-radius" value */
}

Compliant solution

.card {
  position: absolute;
  border-radius: 0;
}

Other values that a property does not accept include a quoted keyword, a space inside a dimension, and a keyword copied from another property:

Noncompliant code example

.card {
  transition: opacity 0.1 s; /* Noncompliant: space inside the dimension */
  display: 'inline'; /* Noncompliant: quoted keyword */
  top: red; /* Noncompliant: "red" is not a valid "top" value */
}

Compliant solution

.card {
  transition: opacity 0.1s;
  display: inline;
  top: 0;
}

A math expression cannot add or subtract a number and a length or percentage:

Noncompliant code example

.card {
  width: calc(100% + 10); /* Noncompliant: cannot add a number to a percentage */
}

Compliant solution

.card {
  width: calc(100% + 10px);
}

A custom property registered with @property in the same file must receive a value matching its declared syntax. Otherwise, it falls back to its inherited or initial value. Change the value, or change the syntax descriptor if the value is the intended one:

Noncompliant code example

@property --gap {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

.card {
  --gap: red; /* Noncompliant: "--gap" only accepts lengths */
}

Compliant solution

@property --gap {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

.card {
  --gap: 1rem;
}

Parts of a value that other rules check

Some parts of a value are checked by related rules instead:

A valid hex color or a number with a known unit is not checked against the property, so top: 10deg does not raise an issue.

Only the first part of a value that the property does not accept is reported. When that part is not checked by this rule, the declaration does not raise an issue, but it can once the related rule’s issue is fixed.

Exceptions

This rule does not raise an issue for deliberate compatibility patterns and for values that it cannot check reliably:

None of the following declarations raise an issue:

.legacy {
  display: -ms-flexbox;
  filter: alpha(opacity=50);
  margin-top: 1px \9;
  -webkit-perspective: 1000;
  color: theme('colors.gray.400');
  margin: var(--spacing);
  --anything: red;
}

Resources

Documentation

Related rules