Skip to main content

HTML Guide

CSS: “font-weight”: “X” is not a “font-weight” value.

The W3C Validator error “CSS: “font-weight”: “X” is not a “font-weight” value” indicates that an incorrect value has been assigned to the font-weight CSS property. The font-weight property controls the boldness or weight of the font, but it only accepts specific values, not a measurement like pixels.

Accepted Values for font-weight:

  1. Keywords: normal, bold, bolder, lighter.
  2. Numeric Values: 100, 200, 300, 400 (equivalent to normal), 500, 600, 700 (equivalent to bold), 800, 900.

Fixing the Issue:

You need to replace the incorrect value with one of the accepted values for font-weight.

Incorrect CSS:

p {
    font-weight: 20px; /* Invalid value */
}

Corrected CSS:

If you want to use a lighter weight, you can choose one of the valid numeric values.

  • For a thin font weight:

    p {
      font-weight: 100; /* Thin weight */
    }
  • For normal (default) font weight:

    p {
      font-weight: 400; /* Normal weight */
    }
  • For bold font weight:

    p {
      font-weight: bold; /* Bold keyword */
    }

Example in HTML:

Here’s how you might use the corrected font-weight property in a simple HTML document:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        /* Corrected font-weight values */
        .thin {
            font-weight: 100;
        }
        .normal {
            font-weight: 400;
        }
        .bold {
            font-weight: bold;
        }
    </style>
    <title>Font Weight Example</title>
</head>
<body>
    <p class="thin">This is thin font weight.</p>
    <p class="normal">This is normal font weight.</p>
    <p class="bold">This is bold font weight.</p>
</body>
</html>

Learn more:

Related W3C validator issues