HTML Guides
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The @container at-rule enables container queries, allowing you to apply styles to elements based on the size or inline-size of a parent container rather than the viewport. It was introduced as part of the CSS Containment Module Level 3 specification and has been supported in all major browsers (Chrome, Edge, Firefox, Safari) since early 2023.
The W3C CSS validator uses its own CSS parsing engine, which sometimes lags behind the latest CSS specifications. Because @container is relatively new compared to long-established at-rules like @media or @keyframes, the validator may flag it as unrecognized. This does not mean your CSS is invalid or broken — it simply means the validator hasn't caught up with the spec yet.
Why This Warning Appears
The W3C validator checks your CSS against known grammar rules. When it encounters an at-rule it doesn't have in its internal dictionary, it reports it as unrecognized. Other modern CSS features like @layer and @property have historically triggered the same kind of false positive before being added to the validator's parser.
Since this is a validator limitation and not an actual code issue, there's no required "fix." However, you should still make sure your @container usage is syntactically correct and that you've properly set up containment on the parent element.
How Container Queries Work
For @container to function, a parent element must be designated as a containment context using the container-type property (or the container shorthand). Without this, the browser won't know which ancestor to query against.
Examples
Correct usage of @container
The parent element needs container-type set to inline-size or size so its descendants can query against it:
<div class="card-wrapper">
<div class="card">
<h2>Title</h2>
<p>Some content here.</p>
</div>
</div>
.card-wrapper {
container-type: inline-size;
container-name: card-container;
}
@container card-container (min-width: 400px) {
.card {
display: flex;
gap: 1rem;
}
}
In this example, .card-wrapper is established as a containment context. When its inline size is at least 400px, the .card inside switches to a flex layout. The validator may flag the @container block, but this CSS is perfectly valid and works in all modern browsers.
Using @container without a named container
You can omit the container name, and the query will match the nearest ancestor with a container-type set:
.sidebar {
container-type: inline-size;
}
@container (max-width: 300px) {
.sidebar-nav {
flex-direction: column;
}
}
Common mistake: forgetting container-type
If you use @container without declaring a containment context on a parent, the query will never match and your styles won't apply. This won't cause a validator error, but it's a logical bug:
/* Missing container-type — the @container query has nothing to query against */
.wrapper {
max-width: 600px;
}
@container (min-width: 400px) {
.content {
font-size: 1.25rem;
}
}
The fix is to add container-type to the intended parent:
.wrapper {
max-width: 600px;
container-type: inline-size;
}
@container (min-width: 400px) {
.content {
font-size: 1.25rem;
}
}
What You Should Do
- Verify your syntax — make sure you're using
container-typeon a parent element and that your@containerquery follows the correct grammar. - Ignore the validator warning — this is a known limitation of the W3C CSS validator. Your CSS is valid per the specification.
- Check browser support —
@containeris supported in Chrome 105+, Edge 105+, Firefox 110+, and Safari 16+. If you need to support older browsers, consider using@containeras a progressive enhancement alongside a fallback layout.
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 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:
- 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. - 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.cssfile may help you separate concerns and skip CSS validation during HTML checks. - 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
@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
<!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:
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.
The @if at-rule is not part of the CSS specification and is not recognized by browsers or the W3C validator.
CSS does not have conditional @if logic the way preprocessors like Sass or LESS do. If @if appears in a <style> block or linked stylesheet, it likely means preprocessor code was included directly in the HTML without being compiled first. The W3C validator flags this because it parses the CSS according to the official specification, where @if does not exist.
There is a CSS Conditional Rules specification, but it covers @media and @supports, not a general purpose @if. To apply styles conditionally in plain CSS, use one of those two at-rules instead.
If the intent was to check for browser support of a CSS feature, @supports is the correct replacement. If the intent was to apply styles based on viewport size or device characteristics, @media is the correct replacement.
If the code comes from a Sass or LESS source file, compile it to plain CSS before including it in HTML.
Example with the issue
<style>
@if (color: red) {
.box {
color: red;
}
}
</style>
Fixed example using @supports
<style>
@supports (color: red) {
.box {
color: red;
}
}
</style>
Fixed example using @media
<style>
@media (min-width: 768px) {
.box {
color: red;
}
}
</style>
The @media screen rule without a condition after the media type is invalid CSS syntax and will be flagged by the W3C validator.
A @media rule requires either a complete media query or a media type combined with a media feature expression. Writing @media screen alone followed by a block is actually valid CSS, so this error typically appears when the syntax inside the rule is malformed, the rule is missing curly braces, or extra characters appear between screen and the opening brace.
Common causes include:
- A missing opening or closing curly brace
{}around the media block. - Stray characters or typos between the media type and the brace.
- Placing
@mediarules inside astyleattribute (inline styles do not support at-rules). - The CSS appears inside an HTML context where the validator cannot parse it correctly, such as a malformed
<style>element.
If the intent is to target screens of a specific size, a media feature expression is required, like @media screen and (min-width: 768px). If the intent is to target all screen devices with no further conditions, @media screen is valid CSS on its own, and the real problem is likely a syntax error nearby.
Example with the issue
<style>
@media screen
.container {
width: 80%;
}
</style>
The opening curly brace for the @media block is missing, so the validator cannot recognize the rule.
Fixed example
<style>
@media screen {
.container {
width: 80%;
}
}
</style>
If the goal is to restrict styles to a specific viewport width, add a media feature:
<style>
@media screen and (min-width: 768px) {
.container {
width: 80%;
}
}
</style>
Both examples use properly matched curly braces and valid @media syntax, which resolves the validator error.
The validator doesn't know the @property at-rule yet, but it is valid CSS from the CSS Properties and Values API and works in all major browsers, so you don't need to change it.
@property registers a custom property with a type. The syntax descriptor sets the kind of value it accepts, such as "<angle>" or "<length>". inherits says whether child elements inherit the value, and initial-value is the value the property has when nothing sets it. Once the browser knows the type, it can interpolate the property, so a transition or animation on it changes smoothly. To the browser, an unregistered custom property is just a sequence of tokens, and an animation on it jumps from the start value to the end value halfway through. That is why @property often shows up next to a rotating gradient, like the one in the examples below.
Chrome and Edge have supported @property since version 85, Safari since 16.4 and Firefox since 128, which made it Baseline in July 2024.
The validator skips the whole block, so it can't tell you when the rule itself is broken. syntax and inherits are required, and so is initial-value unless syntax is "*". If one of them is missing, browsers ignore the whole rule and the property behaves like an ordinary custom property.
Keep the rule and mute this message. If you want a clean report instead, move the @property rules to an external stylesheet: the validator checks the CSS in <style> elements and style attributes, but it doesn't load linked stylesheets. Wrapping the rule in @supports, @media or @layer doesn't help, because the validator still reports the @property inside it.
Example that triggers the message
<head>
<title>Rotating gradient</title>
<style>
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
.card {
background: linear-gradient(var(--angle), #4f46e5, #ec4899);
animation: spin 4s linear infinite;
}
@keyframes spin {
to {
--angle: 360deg;
}
}
</style>
</head>
Example with the rule in an external stylesheet
<head>
<title>Rotating gradient</title>
<link rel="stylesheet" href="gradient.css">
</head>
The same CSS goes into gradient.css, unchanged:
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
.card {
background: linear-gradient(var(--angle), #4f46e5, #ec4899);
animation: spin 4s linear infinite;
}
@keyframes spin {
to {
--angle: 360deg;
}
}
The validator doesn't know the @starting-style at-rule yet, but it is valid CSS from CSS Transitions Level 2 and works in all major browsers, so you don't need to change it.
Browsers don't run a CSS transition the first time they style an element, so an element that a script adds to the page, or one that goes from display: none to visible like an opened <dialog> or popover, shows up in its final state at once. @starting-style gives the browser the values to start from in that case, and the element transitions from them to its normal styles. That is how you fade in a toast or slide in a dialog with CSS alone.
You can write @starting-style as a top-level block around whole rules, or nest it inside a rule, where it holds plain declarations for that rule's selector. The validator reports both forms, once for each @starting-style block.
Chrome and Edge have supported @starting-style since version 117, Safari since 17.5 and Firefox since 129, which made it Baseline in August 2024. A browser without support ignores the rule, and the element appears without the entry transition, so nothing breaks.
The validator skips everything inside the block, so it won't report a typo in a property or value there. It still checks the CSS that comes after the block.
Keep the rule and mute this message. If you want a clean report instead, move the CSS that uses @starting-style to an external stylesheet: the validator checks the CSS in <style> elements and style attributes, but it doesn't load linked stylesheets. Wrapping the block in @supports, @media or @layer doesn't help, because the validator still reports the @starting-style inside it.
Example that triggers the message
<head>
<title>Toast notification</title>
<style>
.toast {
opacity: 1;
transform: translateY(0);
transition: opacity 0.3s, transform 0.3s;
}
@starting-style {
.toast {
opacity: 0;
transform: translateY(1rem);
}
}
</style>
</head>
Example with the rule in an external stylesheet
<head>
<title>Toast notification</title>
<link rel="stylesheet" href="toast.css">
</head>
The same CSS goes into toast.css, unchanged:
.toast {
opacity: 1;
transform: translateY(0);
transition: opacity 0.3s, transform 0.3s;
}
@starting-style {
.toast {
opacity: 0;
transform: translateY(1rem);
}
}
The @tailwind directive is used in Tailwind CSS source files to inject Tailwind's generated styles into your stylesheet. Common usages include @tailwind base;, @tailwind components;, and @tailwind utilities;. These directives act as placeholders that Tailwind's build tool (such as the Tailwind CLI or PostCSS plugin) replaces with actual CSS rules during compilation.
The W3C CSS Validator checks stylesheets against official CSS specifications maintained by the W3C. Since @tailwind is not defined in any CSS specification — it's a framework-specific extension — the validator correctly flags it as unrecognized. This doesn't mean your CSS is broken or will cause problems in browsers; it simply means the validator doesn't know what @tailwind is.
This distinction matters because the @tailwind directives should never appear in production CSS served to browsers. If you're seeing this validation error on a live website, it could indicate one of two things: either you're linking directly to your uncompiled Tailwind source file (which is a problem), or the validator is checking your source CSS rather than the compiled output.
How to Fix It
Ensure you're serving compiled CSS
The most important step is to make sure your build pipeline is correctly processing your Tailwind source files. The compiled output should contain only standard CSS — no @tailwind directives. Verify that your <link> tags point to the compiled CSS file, not the source file.
Use the Tailwind CDN or CLI correctly
If you're using the Tailwind CLI, run the build command to generate a compiled stylesheet and reference that file in your HTML. The compiled file will contain only valid CSS.
Consider suppressing the warning
If the validator is checking your source CSS (for example, inline <style> blocks that get processed client-side), and you're confident the directives are being handled correctly, you can safely suppress or ignore this specific warning in your validation reports.
Examples
Source CSS that triggers the warning
This is a typical Tailwind CSS source file that the validator will flag:
@tailwind base;
@tailwind components;
@tailwind utilities;
.custom-button {
padding: 0.5rem 1rem;
border-radius: 0.25rem;
}
Each @tailwind line will produce an "Unrecognized at-rule" warning from the W3C Validator.
Correct approach: serve compiled CSS
After running the Tailwind build process, the output file contains only standard CSS:
*, ::before, ::after {
box-sizing: border-box;
}
.custom-button {
padding: 0.5rem 1rem;
border-radius: 0.25rem;
}
.flex {
display: flex;
}
.text-center {
text-align: center;
}
Reference this compiled file in your HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Page</title>
<link rel="stylesheet" href="css/output.css">
</head>
<body>
<p class="text-center">Hello, world!</p>
</body>
</html>
Avoid linking to uncompiled source files
This is incorrect — it links directly to the source file containing @tailwind directives:
<!-- Don't do this -->
<link rel="stylesheet" href="css/input.css">
Instead, always link to the build output:
<!-- Do this -->
<link rel="stylesheet" href="css/output.css">
By ensuring your production site serves only the compiled CSS output, you eliminate the @tailwind at-rule warnings entirely and deliver valid, standards-compliant stylesheets to your users.
The @view-transition at-rule is valid CSS but is not yet recognized by the W3C CSS validator because it is a relatively new feature defined in the CSS View Transitions Module Level 2 specification.
The @view-transition at-rule opts a document into cross-document view transitions when navigating between two same-origin pages. It is placed in the CSS of the destination page (the page being navigated to) and accepts a navigation descriptor that controls when the transition activates.
@view-transition {
navigation: auto;
}
The navigation descriptor accepts these values:
none— no cross-document view transition occurs (default).auto— the transition activates for same-origin navigations where the navigation type is traverse, push, or replace, as long as the navigation does not include a cross-origin redirect.
Because the W3C CSS validator has not yet added support for this at-rule, the warning cannot be fixed by changing your code. The CSS itself is correct per the specification. Browser support is available in Chromium-based browsers (Chrome 126+, Edge 126+).
You can safely ignore this validator warning. If you want a completely clean validation output, move the @view-transition rule into a separate stylesheet so it does not interfere with validation of the rest of your CSS, or suppress the warning in your CI pipeline.
The vertical-align property controls the vertical positioning of inline-level elements (like <span>, <img>, and <a>) and table-cell elements (<td>, <th>) relative to their surrounding content or cell. Unlike some other CSS properties (such as float or border), vertical-align has no none keyword. Attempting to use none results in an invalid declaration that browsers will ignore, meaning the element will fall back to the default value of baseline.
This mistake often happens when a developer wants to "reset" or "remove" vertical alignment. Since there is no none value, the correct approach is to either set vertical-align: baseline (the initial value) or remove the vertical-align declaration altogether.
The valid keyword values for vertical-align are:
baseline— aligns the element's baseline with the parent's baseline (default)sub— aligns as a subscriptsuper— aligns as a superscripttext-top— aligns with the top of the parent's fonttext-bottom— aligns with the bottom of the parent's fontmiddle— aligns the middle of the element with the baseline plus half the x-height of the parenttop— aligns the top of the element with the top of the tallest element on the linebottom— aligns the bottom of the element with the bottom of the lowest element on the line
In addition to keywords, vertical-align also accepts length values (e.g., 5px, 0.5em) and percentage values (e.g., 50%), which offset the element relative to the baseline.
Using an invalid value like none causes a W3C validation error and means your intended styling is silently ignored by the browser. This can lead to unexpected layout results that are difficult to debug, especially in table layouts or inline formatting contexts where vertical alignment significantly affects appearance.
Examples
❌ Invalid: using none
<p>
Text with an <img src="icon.png" alt="icon" style="vertical-align: none;"> inline image.
</p>
The validator will report that none is not a valid vertical-align value. The browser ignores the declaration and defaults to baseline.
✅ Fixed: using a valid keyword
If you want the image vertically centered with the text, use middle:
<p>
Text with an <img src="icon.png" alt="icon" style="vertical-align: middle;"> inline image.
</p>
✅ Fixed: resetting to the default
If your intent was to "remove" any vertical alignment, use baseline (the initial value) or simply remove the property:
<p>
Text with an <img src="icon.png" alt="icon" style="vertical-align: baseline;"> inline image.
</p>
❌ Invalid: none in a stylesheet for table cells
<style>
td.reset {
vertical-align: none;
}
</style>
<table>
<tr>
<td class="reset">Cell content</td>
</tr>
</table>
✅ Fixed: valid value for table cells
For table cells, the default vertical-align value is middle in most browsers. To explicitly reset it or set a specific alignment:
<style>
td.top-aligned {
vertical-align: top;
}
</style>
<table>
<tr>
<td class="top-aligned">Cell content</td>
</tr>
</table>
✅ Fixed: using a length value
You can also use a specific length to offset the element from the baseline:
<p>
Text with a <span style="vertical-align: 4px;">slightly raised</span> word.
</p>
Choose the value that matches your design intent — baseline to reset, middle or top for common alignment needs, or a specific length or percentage for precise control.
An invalid value was assigned to the CSS visibility property inside your HTML document.
The visibility property controls whether an element is visually displayed without affecting the document layout. Unlike display: none, a hidden element still occupies space on the page.
The accepted values for visibility are:
visible— the element is shown (default).hidden— the element is invisible but still takes up space.collapse— used primarily with table rows and columns to remove them without affecting the table layout. On non-table elements, it behaves likehidden.
This error typically occurs when you use a value meant for a different property, such as none (which belongs to display), or a misspelled value like hiden or visble.
Invalid Example
<p style="visibility: none;">This text is hidden.</p>
The value none is not valid for visibility. You likely meant hidden or intended to use the display property instead.
Fixed Example
Using the correct visibility value:
<p style="visibility: hidden;">This text is hidden but still takes up space.</p>
Or, if you want the element to be fully removed from the layout, use display instead:
<p style="display: none;">This text is completely removed from the layout.</p>
The white-space property is a shorthand that combines the behavior of white-space-collapse and text-wrap-mode. When you use a value that doesn't match any of the accepted keywords — whether due to a typo, a made-up value, or a value that belongs to a different CSS property — the W3C validator flags it as invalid. This commonly happens when authors confuse values from related properties (like using break-spaces where it isn't supported in inline styles being validated, or misspelling nowrap as no-wrap).
Using invalid CSS values means browsers will ignore the declaration entirely, falling back to the default behavior (white-space: normal). This can cause unexpected text wrapping or whitespace collapsing that breaks your layout. Keeping your CSS valid ensures consistent rendering across browsers and makes your stylesheets easier to maintain and debug.
The accepted values for white-space are:
normal— Collapses whitespace sequences, wraps text as needed (default).nowrap— Collapses whitespace but suppresses line breaks; text won't wrap.pre— Preserves whitespace and line breaks exactly as written, like the<pre>element.pre-wrap— Preserves whitespace and line breaks, but also allows text to wrap when necessary.pre-line— Collapses whitespace sequences into a single space, but preserves explicit line breaks and allows wrapping.break-spaces— Similar topre-wrap, but trailing spaces and spaces at the end of lines don't hang and do affect box sizing.
Additionally, CSS Text Level 4 introduced shorthand combinations using white-space-collapse and text-wrap-mode keywords, such as collapse, preserve, wrap, and preserve nowrap. However, support for these newer shorthand forms varies, and older validators or browsers may not recognize them.
Global CSS values (inherit, initial, revert, revert-layer, unset) are also valid.
Examples
Incorrect: invalid value triggers the error
A common mistake is using no-wrap (with a hyphen) instead of the correct nowrap:
<p style="white-space: no-wrap;">This text should not wrap.</p>
Another common mistake is using a value from a different property entirely:
<p style="white-space: hidden;">This text has an invalid white-space value.</p>
Correct: using valid white-space values
<p style="white-space: nowrap;">This text will not wrap to a new line.</p>
<p style="white-space: pre-wrap;">This text preserves whitespace
and line breaks, but also wraps when needed.</p>
<p style="white-space: pre-line;">This collapses extra spaces
but preserves explicit line breaks.</p>
Correct: using the property in a <style> block
<!DOCTYPE html>
<html lang="en">
<head>
<title>White-space example</title>
<style>
.no-wrap {
white-space: nowrap;
}
.preserve {
white-space: pre-wrap;
}
</style>
</head>
<body>
<p class="no-wrap">This long paragraph will stay on a single line without wrapping.</p>
<p class="preserve">This preserves multiple spaces
and line breaks exactly as written.</p>
</body>
</html>
If you encounter this validation error, double-check your white-space value for typos and confirm it matches one of the recognized keywords listed above.
The widows property only accepts a positive whole number, so a keyword such as auto or none is invalid.
widows sets the minimum number of lines of a block that must appear at the top of the next page or column when the browser splits the block. The initial value is 2. Apart from the global keywords (inherit, initial, unset), the property takes no keywords, so a declaration like widows: auto is dropped and the element keeps the value it would have without it.
This declaration often arrives with formatted text copied from Safari and pasted into a rich text editor. Safari reports auto as the computed value of both widows and orphans, and the pasted markup carries those computed styles in a long inline style attribute. The same elements then usually trigger the matching orphans error too.
Replace the keyword with a number such as 2 or 3, or remove the declaration to keep the default. In pasted content, deleting both widows and orphans from the style attribute is the simplest fix. The value must be an integer of at least 1: 0 and decimals such as 1.5 get their own validator errors.
Invalid example
<p style="widows: auto;">
A paragraph of text that may break across pages when printed.
</p>
Valid example
<p style="widows: 2;">
A paragraph of text that may break across pages when printed.
</p>
This error originates from CSS validation, not HTML element validation. It typically appears when the validator encounters a width value in a style attribute or <style> block that doesn't conform to the CSS specification for the width property. The CSS width property accepts <length>, <percentage>, auto, min-content, max-content, fit-content, or fit-content(<length-percentage>) values. Anything outside these types—or an expression that produces an incompatible type—will trigger this error.
Common causes include:
- Missing units on a numeric value. In CSS,
width: 400is invalid (unlike the HTMLwidthattribute on elements like<img>, which expects a unitless integer). CSS requires a unit such aspx,em,rem,%,vw, etc., unless the value is0. - Invalid
calc()expressions. For example,calc(100% - 20)is invalid because100%is a percentage and20has no unit—you cannot subtract a unitless number from a percentage. It should becalc(100% - 20px). - Typos or unrecognized values. Things like
width: 50 px(space between number and unit),width: autopx, orwidth: 100pixelsare not valid CSS. - Using HTML attribute syntax in CSS. Writing
width: 400in a stylesheet because you're used to writing<img width="400">in HTML.
This matters for standards compliance and cross-browser reliability. While some browsers may attempt to interpret invalid values, the behavior is undefined and inconsistent. Relying on invalid CSS can lead to broken layouts in certain browsers or future browser versions.
How to Fix It
- Add proper units to any bare numeric
widthvalue in your CSS. Usepx,em,rem,%,vw, or another valid CSS length unit. - Check
calc()expressions to ensure both sides of addition or subtraction are compatible types (e.g., length with length, or percentage with length—both are valid incalc()). Unitless numbers (other than0) cannot be mixed with lengths or percentages in addition/subtraction. - Remove spaces between numbers and their units.
50pxis valid;50 pxis not. - Use valid keywords only:
auto,min-content,max-content,fit-content.
Examples
Incorrect: Missing unit in inline style
<div style="width: 400;">Content</div>
Correct: Adding a proper unit
<div style="width: 400px;">Content</div>
Incorrect: Incompatible types in calc()
<div style="width: calc(100% - 20);">Content</div>
The value 20 has no unit, so it cannot be subtracted from a percentage.
Correct: Compatible types in calc()
<div style="width: calc(100% - 20px);">Content</div>
Incorrect: Space between number and unit
<p style="width: 50 %;">Some text</p>
Correct: No space between number and unit
<p style="width: 50%;">Some text</p>
Incorrect: Unitless number in a <style> block
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example</title>
<style>
.sidebar {
width: 300;
}
</style>
</head>
<body>
<aside class="sidebar">Sidebar content</aside>
</body>
</html>
Correct: Valid length value in a <style> block
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example</title>
<style>
.sidebar {
width: 300px;
}
</style>
</head>
<body>
<aside class="sidebar">Sidebar content</aside>
</body>
</html>
Note on the HTML width attribute
Don't confuse CSS width with the HTML width attribute. The HTML width attribute on elements like <img>, <video>, and <canvas> expects a unitless integer:
<img src="photo.jpg" width="400" alt="A sample photo">
Writing width="400px" in an HTML attribute is a separate validation error. The CSS error discussed in this guide specifically concerns width values in stylesheets or style attributes where a valid CSS length is required.
The CSS width property sets an element's width and accepts a single value. The W3C validator reports this error when it encounters something it cannot parse as a valid width declaration. Common causes include:
- Missing units: Writing
width: 300instead ofwidth: 300px. CSS requires explicit units for non-zero lengths. - Multiple values: Writing
width: 100px 200pxas ifwidthaccepted shorthand-style multiple values (it doesn't). - Typos or invalid keywords: Writing
width: auotinstead ofwidth: auto, or using a made-up keyword. - Invalid functions or syntax: Using incorrect function syntax like
width: calc(100% - 20px)with missing spaces around operators, or using browser-prefixed values without a standard fallback. - Unsupported values: Using newer CSS values like
fit-contentormax-contentin a context where the validator's CSS level doesn't recognize them.
This matters because invalid CSS can cause browsers to silently discard the entire declaration, meaning your intended layout won't be applied. Different browsers may handle invalid values differently, leading to inconsistent rendering. Keeping your CSS valid ensures predictable, cross-browser behavior.
Valid values for width
The width property accepts exactly one of the following:
- Length values: A number with a unit, such as
300px,25em,10rem,5vw. - Percentage values: A percentage relative to the containing block, such as
75%. - Keyword values:
auto,max-content,min-content,fit-content. - Function values:
fit-content(20em),calc(100% - 40px),min(300px, 100%),max(200px, 50%),clamp(200px, 50%, 600px). - Global values:
inherit,initial,revert,revert-layer,unset.
Note that 0 is the only numeric value that does not require a unit.
Examples
Incorrect: missing unit
<style>
.box {
width: 300;
}
</style>
<div class="box">Content</div>
A bare number (other than 0) is not valid. The browser won't know if you mean pixels, ems, or something else.
Correct: unit provided
<style>
.box {
width: 300px;
}
</style>
<div class="box">Content</div>
Incorrect: too many values
<style>
.sidebar {
width: 200px 400px;
}
</style>
<aside class="sidebar">Sidebar</aside>
Unlike properties such as margin or padding, width only accepts a single value.
Correct: single value
<style>
.sidebar {
width: 200px;
}
</style>
<aside class="sidebar">Sidebar</aside>
Incorrect: typo in keyword
<style>
.container {
width: auot;
}
</style>
<div class="container">Content</div>
Correct: proper keyword
<style>
.container {
width: auto;
}
</style>
<div class="container">Content</div>
Incorrect: malformed calc() expression
<style>
.panel {
width: calc(100%-40px);
}
</style>
<div class="panel">Content</div>
The calc() function requires spaces around + and - operators.
Correct: properly spaced calc() expression
<style>
.panel {
width: calc(100% - 40px);
}
</style>
<div class="panel">Content</div>
Incorrect: accidental semicolon or extra text
<style>
.card {
width: 50% important;
}
</style>
<div class="card">Content</div>
If you intended to use !important, the ! is required.
Correct: proper !important syntax
<style>
.card {
width: 50% !important;
}
</style>
<div class="card">Content</div>
The CSS width property contains an invalid value.
The width property accepts specific types of values: lengths (like 100px, 10em, 5rem), percentages (50%), viewport units (100vw), the keyword auto, and sizing keywords like max-content, min-content, or fit-content. The validator rejects anything that doesn't match these formats.
Common mistakes that trigger this error:
- Missing a unit:
width: 100instead ofwidth: 100px. Plain numbers (other than0) are not valid CSS lengths. - Using an invalid unit or typo:
width: 100 px(with a space),width: 100ppx. - Passing a non-length value:
width: red,width: bold,width: none. The keywordnoneworks formax-widthbut not forwidth. - Including extra characters:
width: 100px;50pxorwidth: 100px !importnt.
Invalid example
<div style="width: 600">
<p>This box has no unit on its width value.</p>
</div>
The value 600 is not valid because it lacks a CSS unit.
Fixed example
<div style="width: 600px">
<p>This box now has a valid width.</p>
</div>
Adding px (or another appropriate unit like em, %, rem, vw) makes the value valid. If the intent is to let the element size itself naturally, use width: auto instead.
The value of the --wp--style--global--content-size custom property has a math expression that combines values of incompatible types.
WordPress block themes create this variable from the content width in theme.json (settings.layout.contentSize), or from the layout width set in the Site Editor. WordPress copies that value into a <style> element without changing it, so the validator checks exactly what the theme or the site settings contain.
A custom property can hold almost any value, so the validator doesn't care whether the result is a length. It does check the math inside calc(), min(), max() and clamp(): when you add or subtract two values, both must have the same type. Subtracting a unitless number from a length, as in calc(720px - 40), triggers this error. Browsers reject that expression too. Every property that reads the variable through var() becomes invalid at computed-value time and behaves as if it were unset, so the content width setting stops working.
To fix the error, edit contentSize in theme.json (or the content width in the Site Editor) and add the missing unit.
Invalid example
<style>
body {
--wp--style--global--content-size: calc(720px - 40);
}
</style>
Valid example
<style>
body {
--wp--style--global--content-size: calc(720px - 40px);
}
</style>
The value of the --wp--style--global--wide-size custom property has a math expression that combines values of incompatible types.
WordPress block themes create this variable from the wide width in theme.json (settings.layout.wideSize), or from the wide width set in the Site Editor. It controls how far blocks with the "Wide width" alignment can stretch. WordPress copies the value into a <style> element as is, so the validator checks exactly what the theme or the site settings contain.
A custom property can hold almost any value, and the validator doesn't check whether the result is a length. It does check the math inside calc(), min(), max() and clamp(), where every value you add, subtract or compare must have the same type. A unitless number next to a length breaks that rule, as in calc(1200px - 40) or clamp(800px, 90vw, 1200). Browsers reject those expressions too: any property that reads the variable through var() becomes invalid at computed-value time and acts as if it were unset. Wide blocks then lose their maximum width.
To fix the error, edit wideSize in theme.json (or the wide width in the Site Editor) and add the missing unit.
Invalid example
<style>
body {
--wp--style--global--wide-size: calc(1200px - 40);
}
</style>
Valid example
<style>
body {
--wp--style--global--wide-size: calc(1200px - 40px);
}
</style>
This is an internal error from the W3C validator's CSS checking engine (the Jigsaw CSS validator). The message Cannot invoke "org.w3c.css.values.CssValue.getType()" because "Y" is null is a Java NullPointerException surfacing from the validator's source code. In practical terms, it means the validator tried to determine the type of a CSS value, but that value didn't exist or couldn't be computed.
There are several common causes for this error:
- Malformed or incomplete CSS values — A property is missing part of its value, such as a shorthand with too few components, or a function with missing arguments.
- Unsupported CSS features — Newer CSS features or non-standard syntax that the validator's CSS engine doesn't fully support can trigger internal failures rather than clean error messages.
- Invalid value combinations — Using values together in a way that doesn't match any known CSS grammar rule can cause the parser to fail unexpectedly.
- Syntax errors in custom properties or functions — Mistakes inside
calc(),var(), or other CSS functions can sometimes cause this kind of crash in the validator.
While this error technically originates from the validator itself (and could be considered a validator bug), it almost always points to CSS that is non-standard, malformed, or pushing the boundaries of what the validator can parse. Fixing the underlying CSS issue resolves the error.
How to Fix It
- Locate the CSS property referenced in the error — The
"X"in the error message identifies the CSS property or value that caused the failure. - Check for syntax errors — Look for missing values, unclosed parentheses, stray commas, or incomplete shorthand declarations.
- Simplify complex expressions — If you're using
calc(), nested functions, or complex shorthand values, try breaking them into simpler, longhand declarations. - Check for unsupported features — Some modern CSS (e.g., certain uses of
color-mix(), newer color syntaxes, or container query units) may not yet be supported by the validator. Consider whether validation of that specific rule is critical. - Validate CSS separately — Paste your CSS into the W3C CSS Validator directly to isolate the problematic rule.
Examples
Malformed shorthand value
A missing value in a shorthand property can trigger this internal error:
<div style="border: 1px solid;">Content</div>
The border shorthand here has a trailing space after solid with no color specified. While browsers handle this gracefully by using a default, the validator may fail to process the incomplete value. Fix it by providing all intended values explicitly:
<div style="border: 1px solid black;">Content</div>
Incomplete function syntax
Missing arguments inside CSS functions are another common trigger:
<style>
.box {
width: calc(100% - );
background-color: rgb(255, 128);
}
</style>
The calc() expression is missing its second operand, and rgb() is missing its third argument. Fix both by providing complete values:
<style>
.box {
width: calc(100% - 20px);
background-color: rgb(255, 128, 0);
}
</style>
Complex expressions the validator cannot parse
Sometimes valid, modern CSS triggers this error because the validator's engine doesn't fully support it:
<style>
.card {
background: color-mix(in srgb, #3498db 70%, transparent);
}
</style>
If this triggers the internal error, you can provide a fallback or simplify:
<style>
.card {
background: rgba(52, 152, 219, 0.7);
}
</style>
Accidental double values
A typo that results in two values where one is expected can also cause this:
<style>
.text {
font-size: 16px 14px;
}
</style>
Fix by providing only the single expected value:
<style>
.text {
font-size: 16px;
}
</style>
If you believe your CSS is correct and the validator is producing this error incorrectly, it may be a genuine bug in the validator. You can report it at the W3C CSS Validator's GitHub repository. In the meantime, check that your CSS works correctly across target browsers and consider adding a /* validated */ comment near the line so you can track intentional exceptions.
A color written with rgb() or rgba() mixes the comma and space syntaxes, or is missing one of its values.
CSS has two ways to write rgb(), and a single function has to use one of them. The legacy syntax separates three or four values with commas, as in rgb(0, 0, 0) or rgba(0, 0, 0, 0.5). The modern syntax separates the three channels with spaces and puts the alpha after a slash, as in rgb(0 0 0 / 0.5). Values like rgb(0, 0, 0 / 0.5) and rgb(0 0, 0) combine the two, and rgb(255, 0) has only two channels. rgb() and rgba() are aliases, so either name works with either syntax.
The "X" in the message is the property that holds the color. It can be a regular property such as color or box-shadow, or a custom property such as --tw-shadow, which Tailwind CSS uses for box shadows. A browser drops a regular declaration with a broken color. A custom property keeps the value as written, and the problem shows up where var() reads it: the box-shadow that uses it becomes invalid, and the element has no shadow.
Rewrite the color in one syntax. If the value comes from a framework or from a build step such as a minifier, fix it there and rebuild, because the next build overwrites any edit to the generated file.
Invalid example
<style>
.card {
--card-shadow: 0 1px 3px rgb(0, 0, 0 / 0.1);
box-shadow: var(--card-shadow);
}
</style>
Valid example
<style>
.card {
--card-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
box-shadow: var(--card-shadow);
}
</style>
An expression inside calc(), min(), max() or clamp() uses a value of a type that math functions can't compute with, most often the fr unit, or it combines var() with a percentage, which older versions of the CSS validator rejected by mistake.
Math functions compute with lengths, percentages, numbers, angles, times and frequencies. The validator checks the type of each operand and of the result. When one falls outside that list, it reports "Invalid type" and quotes the expression without the function name, so calc(2 * 1fr) shows up as 2 * 1fr.
The fr unit is a common cause. It's a flexible length for grid tracks, and the CSS Grid specification says fr values can't be represented in or combined with other units inside calc(). Browsers drop a declaration like grid-template-columns: calc(2 * 1fr) 1fr, and the grid falls back to the track sizes from earlier rules, or to a single column when there are none. Write the fraction directly as 2fr instead, and use minmax() when a track needs a minimum or maximum size.
When the quoted expression contains var(), as in 100% - var(--site-width) or 100% - var(--padding) * 2, the CSS is valid. A custom property has no type until the browser substitutes its value, and older versions of the CSS validator treated it as a value of the wrong type when it was combined with a percentage. The CSS validator fixed this in October 2026, and the validator Rocket Validator uses now accepts these expressions. You don't need to change your CSS. If a report from before the fix still lists the message, run a new report or mute the issue.
Invalid example
<style>
.layout {
display: grid;
grid-template-columns: calc(2 * 1fr) 1fr;
}
</style>
Valid example
<style>
.layout {
display: grid;
grid-template-columns: 2fr 1fr;
}
</style>
Valid var() expressions
These declarations are valid CSS and pass the current validator:
<style>
:root {
--header-height: 64px;
--padding: 16px;
--offset-x: 20px;
}
.content {
width: calc(100% - var(--padding) * 2);
height: calc(100% - var(--header-height));
background-position: calc(50% + var(--offset-x)) center;
}
</style>
CSS uses semicolons as delimiters between declarations. When you forget one, the parser tries to interpret the next property name as part of the previous declaration's value. For example, if you write z-index: auto content: "", the parser reads auto content as if it were the value of z-index, which is invalid. It then encounters the colon after what it expected to be a value, resulting in a parsing error that can cause one or more of your declarations to be silently ignored.
This is a problem for several reasons:
- Broken styles: The browser will typically discard the malformed declaration and potentially subsequent ones, leading to unexpected visual results that can be difficult to debug.
- Standards compliance: The CSS specification requires semicolons between declarations. While the last declaration in a block technically doesn't need a trailing semicolon, omitting it is a common source of bugs when new declarations are added later.
- Maintainability: Always including semicolons — even on the last declaration — is a widely recommended best practice. It prevents this exact class of errors when code is edited or rearranged in the future.
To fix this issue, locate the line referenced in the error message and check the declaration immediately before it. Add the missing semicolon at the end of that declaration.
Examples
❌ Missing semicolon between declarations
The semicolon is missing after z-index: auto, so the parser cannot recognize content as a new property:
<style>
.overlay {
z-index: auto
content: "";
display: block;
}
</style>
✅ Fixed with semicolon added
Adding the semicolon after auto properly terminates the z-index declaration:
<style>
.overlay {
z-index: auto;
content: "";
display: block;
}
</style>
❌ Missing semicolon with shorthand properties
Shorthand values with multiple parts can make it harder to spot the missing semicolon:
<style>
.card {
margin: 10px 20px 10px 20px
padding: 1em;
border: 1px solid #ccc;
}
</style>
✅ Fixed shorthand example
<style>
.card {
margin: 10px 20px 10px 20px;
padding: 1em;
border: 1px solid #ccc;
}
</style>
❌ Missing semicolon on the last declaration causes issues when editing
While technically valid, omitting the trailing semicolon on the last declaration becomes a bug the moment a new line is added:
<style>
.button {
color: white;
background: blue
border-radius: 4px;
}
</style>
Here, background: blue was originally the last declaration (without a semicolon). When border-radius was added afterward, the missing semicolon was not noticed.
✅ Best practice: always include a trailing semicolon
<style>
.button {
color: white;
background: blue;
border-radius: 4px;
}
</style>
By consistently ending every declaration with a semicolon — including the last one in each rule block — you avoid this error entirely and make your stylesheets easier to maintain.
CSS math functions like calc(), min(), max(), and clamp() follow strict rules about how operands and operators interact. The error "one operand must be a number" most commonly fires in two scenarios: either an operand is missing entirely (e.g., calc(100% - )), or both operands in a multiplication or division carry units (e.g., calc(10px * 5px)). The CSS Values and Units specification requires that for * (multiplication), at least one side must be a unitless <number>. For / (division), the right-hand side must always be a unitless <number>. You cannot multiply two lengths together or divide a length by another length within calc().
This matters for several reasons. Browsers will discard the entire property declaration if the calc() expression is invalid, which can cause layout breakage or fallback to unexpected default values. The W3C validator catches these errors in inline style attributes and embedded <style> blocks, helping you identify expressions that will silently fail in production. Fixing these issues ensures predictable rendering across all browsers.
How the rules work
- Addition and subtraction (
+,-): Both operands must have compatible types (e.g., both lengths, or both percentages, or a mix of length and percentage). Both must be present. - Multiplication (
*): At least one operand must be a plain<number>(unitless). You can writecalc(10px * 3)orcalc(3 * 10px), but notcalc(10px * 5px). - Division (
/): The right-hand operand must be a plain<number>(unitless and non-zero). You can writecalc(100px / 2), but notcalc(100px / 2px).
Examples
Missing operand
A common mistake is leaving out a value on one side of an operator:
<!-- ❌ Wrong: missing operand after the minus sign -->
<div style="width: calc(100% - );"></div>
<!-- ✅ Fixed: both operands are present -->
<div style="width: calc(100% - 50px);"></div>
Multiplying two values with units
You cannot multiply two unit-bearing values together, because the result would be a meaningless type like "px²":
<!-- ❌ Wrong: both operands have units -->
<div style="width: calc(10px * 5px);"></div>
<!-- ✅ Fixed: one operand is a unitless number -->
<div style="width: calc(10px * 5);"></div>
Dividing by a value with units
The divisor in a / operation must be a unitless number:
<!-- ❌ Wrong: dividing by a value with units -->
<div style="height: calc(500px / 2em);"></div>
<!-- ✅ Fixed: divisor is a unitless number -->
<div style="height: calc(500px / 2);"></div>
Nested calc() with a missing value
Errors can hide inside nested expressions:
<!-- ❌ Wrong: inner calc has an incomplete expression -->
<p style="margin-top: calc(2rem + calc(100% * ));"></p>
<!-- ✅ Fixed: all operands are present and valid -->
<p style="margin-top: calc(2rem + calc(100% * 0.5));"></p>
Using variables or keywords where a number is expected
Sometimes a typo or misunderstanding leads to a non-numeric token where a number is required:
<!-- ❌ Wrong: "auto" is not a valid operand in calc() -->
<div style="width: calc(auto * 2);"></div>
<!-- ✅ Fixed: use a numeric value or percentage -->
<div style="width: calc(100% * 2);"></div>
To resolve this error, review every calc(), min(), max(), and clamp() expression in your inline styles and stylesheets. Confirm that all operators have valid operands on both sides, that * always has at least one unitless number, and that / always has a unitless number on the right. If you're building expressions dynamically (e.g., via JavaScript or a templating engine), double-check that variables are being interpolated correctly and not producing empty or invalid values.
When the W3C HTML Validator checks your document, it also validates any inline styles (in style attributes) and embedded stylesheets (in <style> elements). A CSS parse error occurs when the parser encounters something it cannot interpret according to CSS specifications. The "X" in the error message refers to the specific property, value, or token that triggered the failure.
Understanding CSS Parse Errors
CSS parse errors can stem from many different causes:
- Typos in property names or values — e.g.,
colrinstead ofcolor, or10xpinstead of10px. - Missing or extra punctuation — a forgotten semicolon, an extra colon, unmatched braces or parentheses.
- Invalid values for a property — using a value that doesn't belong to that property's grammar.
- Vendor-prefixed or non-standard syntax — properties like
-webkit-appearanceor-moz-osx-font-smoothingare not part of the CSS standard and will trigger parse errors in the validator. - Modern CSS features not yet recognized — some newer CSS syntax may not be supported by the validator's parser yet.
- Stray characters or encoding issues — invisible characters, smart quotes, or copy-paste artifacts from word processors.
While browsers are generally forgiving and will skip CSS they don't understand, parse errors can indicate real bugs that cause styles to silently fail. Fixing them ensures your CSS is standards-compliant and behaves predictably across all browsers.
Common Causes and Fixes
Typos and syntax mistakes
The most frequent cause is a simple typo or a missing character. Always double-check the exact line the validator points to.
Missing semicolons
A forgotten semicolon between declarations can cause the parser to misinterpret subsequent properties.
Invalid or malformed values
Using values that don't match the property's expected syntax — such as omitting units, using incorrect function syntax, or providing the wrong number of arguments — will trigger parse errors.
Vendor prefixes
The W3C validator checks against the CSS specification. Vendor-prefixed properties and values are non-standard and will produce parse errors. While you may still need them in production, be aware that these will always flag in validation.
Examples
❌ Missing semicolon between declarations
<p style="color: red background-color: blue;">Hello</p>
The missing semicolon after red causes the parser to try to interpret red background-color: blue as a single value, resulting in a parse error.
✅ Fixed: semicolons separating declarations
<p style="color: red; background-color: blue;">Hello</p>
❌ Typo in property name
<style>
.box {
widht: 100px;
hieght: 200px;
}
</style>
✅ Fixed: correct property names
<style>
.box {
width: 100px;
height: 200px;
}
</style>
❌ Missing unit on a value
<style>
.container {
margin: 10;
padding: 20px;
}
</style>
Numeric values (other than 0) require a unit. The value 10 without a unit like px, em, or rem is invalid.
✅ Fixed: unit included
<style>
.container {
margin: 10px;
padding: 20px;
}
</style>
❌ Extra or misplaced characters
<style>
.title {
font-size:: 16px;
color: #3333;
}
</style>
The double colon after font-size and the 4-digit hex color #3333 (which is valid in CSS Color Level 4 but may not be recognized by all validator parsers) can trigger errors.
✅ Fixed: correct syntax
<style>
.title {
font-size: 16px;
color: #333333;
}
</style>
❌ Unmatched parentheses in a function
<style>
.overlay {
background: rgba(0, 0, 0, 0.5;
}
</style>
✅ Fixed: closing parenthesis added
<style>
.overlay {
background: rgba(0, 0, 0, 0.5);
}
</style>
Tips for Debugging Parse Errors
- Read the error message carefully. The validator usually points to the specific token or line that caused the failure.
- Validate CSS separately. Use the W3C CSS Validation Service for more detailed CSS-specific error messages.
- Check for invisible characters. If you copied CSS from a word processor, PDF, or website, hidden characters like zero-width spaces or smart quotes (
"instead of") may be present. Retype the line manually if in doubt. - Simplify and isolate. If you can't find the error, remove declarations one at a time until the error disappears, then inspect the last removed declaration closely.
The validator flags any declaration where the property token doesn’t match a known CSS property in its ruleset. Common causes include typos, wrong hyphenation, using values where property names should go, properties from older drafts that were renamed, or relying solely on vendor-prefixed/experimental properties without a standard equivalent. It can also show up when copy-pasting snippets that include custom, nonstandard properties.
Why this matters:
- Browser compatibility: Unknown properties are ignored, causing styles to silently fail.
- Maintainability: Typos and nonstandard syntax make CSS harder to debug.
- Standards compliance: Clean, validated CSS reduces cross-browser surprises and eases future maintenance.
How to fix it:
- Check spelling and hyphenation exactly (e.g.,
text-decoration-skip-ink, nottext-decoration-skipink). - Verify the property exists on MDN or in the CSS specifications; if it’s not documented, it’s likely invalid.
- Replace deprecated or draft names with current standardized ones.
- If using experimental features, include a standard fallback and keep vendor-prefixed versions alongside the unprefixed property when supported.
- Remove framework- or tool-specific tokens that aren’t valid CSS at runtime.
- Don’t invent properties. If you need custom data for JS, use
data-*attributes in HTML, not fake CSS properties.
Examples
Example that triggers the error (typo) and the corrected version
Invalid:
<p style="colr: red;">Hello</p>
Valid:
<p style="color: red;">Hello</p>
Example using a deprecated/draft name replaced with the current property
Invalid (older draft name):
<div style="gap: 1rem; grid-row-gap: 8px;"></div>
Valid (current, standardized property):
<div style="row-gap: 8px; gap: 1rem;"></div>
Example with vendor-prefixed property plus standard fallback
Invalid (only vendor-prefixed, missing standard property):
<div style="-webkit-user-select: none;"></div>
Valid (fallback plus prefix):
<div style="user-select: none; -webkit-user-select: none;"></div>
Example removing a nonstandard custom property name misuse
Invalid (attempting to invent a property):
<div style="button-style: primary;"></div>
Valid (use classes and real CSS properties):
<style>
.btn--primary {
background-color: #0b5fff;
color: #fff;
}
</style>
<button class="btn--primary">Submit</button>
Example with custom properties (variables) used correctly
Valid use of CSS custom properties (won’t trigger the error because the property is standard and custom properties start with --):
<style>
:root {
--brand-color: #0b5fff;
}
.tag {
color: var(--brand-color);
}
</style>
<span class="tag">Tag</span>
Full document with corrected properties
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Property Validation Fixes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card {
display: grid;
gap: 1rem;
row-gap: 0.5rem;
user-select: none;
-webkit-user-select: none;
color: #222;
}
</style>
</head>
<body>
<div class="card">Valid CSS properties in use</div>
</body>
</html>
Quick checklist:
- Confirm the property on MDN. If not found, it’s probably invalid.
- Fix spelling/casing; CSS properties are lowercase with hyphens.
- Prefer standardized names; keep prefixes only as supplements.
- Use CSS custom properties starting with
--if you need variables. - Remove tool-specific placeholders before validation.
In the standard linear-gradient() syntax, a side keyword such as top or left must follow the word to, so a gradient whose first argument is a bare keyword is invalid.
The bare form comes from the vendor-prefixed gradients that browsers shipped before the syntax was standardized, such as -webkit-linear-gradient(top, #fff, #000). There, the keyword names the side where the gradient starts. The CSS Images specification changed that: the keyword now comes after to and names the side where the gradient ends. Older stylesheets often repeat the prefixed declaration without the prefix, which leaves the old argument inside the standard function. Current browsers ignore that whole declaration, so the gradient only appears when an earlier prefixed declaration provides it. The validator reports the error on any property that takes an image, such as background, background-image, border-image or list-style-image, and on repeating-linear-gradient() as well.
Writing exactly what the message suggests flips the gradient. The old top means "start at the top", so linear-gradient(top, #fff, #000) was meant to paint white at the top and black at the bottom, while to top paints white at the bottom. To keep the intended look, point to the opposite side: top becomes to bottom, bottom becomes to top, left becomes to right, and right becomes to left. For a corner such as top left, the message names only the first keyword, but both change, so it becomes to bottom right. Because to bottom is the default direction, a gradient that started with top can also drop its first argument.
Invalid example
<style>
.banner {
background-image: linear-gradient(top, #ffffff, #dddddd);
}
</style>
<div class="banner">Free shipping on all orders</div>
Valid example
<style>
.banner {
background-image: linear-gradient(to bottom, #ffffff, #dddddd);
}
</style>
<div class="banner">Free shipping on all orders</div>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries