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.
Negative values for the CSS line-height property are invalid and browsers reject them.
The line-height property sets the height of each line box, so a negative value has no meaning and violates the CSS specification. Valid values are normal, a unitless multiplier like 1.5, a length like 24px or 1.5em, or a percentage like 150%. A unitless number is usually the best choice, since it scales with the element's font size and avoids the inheritance quirks that fixed lengths can cause.
This error usually appears when line-height is set inline through the style attribute, where the W3C validator catches it during HTML validation. A common cause is a calculation in a template or script that produces a negative number and writes it into the markup.
To fix it, replace the negative value with a positive one, or use normal for the browser's default spacing. Tighter lines are fine as long as the value stays positive, such as line-height: 0.9.
HTML examples
Invalid: negative line-height value
<p style="line-height: -0.5em;">
Paragraph text
</p>
Valid: positive value or normal
<!-- Unitless multiplier, scales with font size -->
<p style="line-height: 1.5;">
Paragraph text
</p>
<!-- Browser default spacing -->
<p style="line-height: normal;">
Paragraph text
</p>
The W3C validator raises this error when it encounters a bare unit like px used as the value for margin-bottom without an accompanying number. In CSS, length values are always composed of two parts: a <number> and a <unit>. The token px alone is not a valid <length> value — it's just a unit identifier with no magnitude. This typically happens due to a typo, an accidental deletion of the numeric portion, or a templating/build tool that outputs an empty variable before the unit.
This matters for several reasons. First, browsers will discard the invalid declaration entirely, meaning margin-bottom will fall back to its default or inherited value — likely not what you intended. This can cause unexpected layout shifts across different pages or components. Second, invalid CSS can make debugging harder, since the silent failure may not be obvious until the layout breaks in a specific context. Third, clean, valid CSS is easier to maintain and signals code quality to collaborators.
How to fix it
- Add a numeric value before the unit: change
pxto something like10px,1.5em, or20%. - Use
0without a unit if you want zero margin:margin-bottom: 0is valid and preferred overmargin-bottom: 0px. - Use a keyword value if appropriate:
margin-bottomalso acceptsauto,inherit,initial,revert, andunset. - Check template variables: if you're using a preprocessor like Sass or a JavaScript framework that injects values, make sure the variable isn't empty or undefined before concatenation with the unit.
Examples
Incorrect: bare unit with no number
<div style="margin-bottom: px;">Content</div>
The value px is not a valid margin-bottom value. The browser will ignore this declaration.
Correct: numeric value with unit
<div style="margin-bottom: 10px;">Content</div>
Correct: zero margin (no unit needed)
<div style="margin-bottom: 0;">Content</div>
Correct: using a keyword value
<div style="margin-bottom: auto;">Content</div>
Incorrect in a stylesheet
<html lang="en">
<head>
<title>Example</title>
<style>
.card {
margin-bottom: px;
}
</style>
</head>
<body>
<div class="card">Content</div>
</body>
</html>
Fixed stylesheet
<html lang="en">
<head>
<title>Example</title>
<style>
.card {
margin-bottom: 16px;
}
</style>
</head>
<body>
<div class="card">Content</div>
</body>
</html>
Watch out for preprocessor issues
If you use a CSS preprocessor like Sass or Less, a common source of this error is an empty or undefined variable:
/* If $spacing resolves to empty, this produces "margin-bottom: px;" */
.card {
margin-bottom: $spacing + px;
}
Instead, ensure the variable includes the unit or has a valid fallback:
$spacing: 16px;
.card {
margin-bottom: $spacing;
}
The same principle applies to any CSS property that expects a <length> value — always pair a number with its unit, or use 0 when no spacing is needed.
The spacing() function is not a valid CSS value. It does not exist in any CSS specification.
The spacing() notation is commonly found in utility-based frameworks like Tailwind CSS or custom design systems where it acts as a shorthand for spacing scales. However, browsers and the W3C validator do not recognize it as valid CSS.
If you're using a build tool or preprocessor, make sure spacing() is being compiled into a valid CSS value before it reaches the browser. If you're writing plain CSS, replace it with a standard CSS length value such as px, rem, em, or use a CSS custom property.
How to Fix
Replace spacing(3) with a valid CSS length value:
#content::after {
margin-bottom: 0.75rem;
}
Or use a CSS custom property to create your own spacing scale:
:root {
--spacing-3: 0.75rem;
}
#content::after {
margin-bottom: var(--spacing-3);
}
Both approaches produce valid CSS that the W3C validator will accept. If your project relies on a framework that provides spacing(), check that your build pipeline (e.g., PostCSS, Sass, or Tailwind) is correctly transforming it into standard CSS before deployment.
An invalid value was assigned to the margin-bottom CSS property, and the W3C validator rejected it because it does not match any accepted syntax for that property.
The margin-bottom property accepts a length (e.g., 10px, 2em), a percentage (e.g., 5%), auto, or the global keywords inherit, initial, revert, and unset. The validator raises this error when the value is misspelled, uses a wrong unit, is missing a unit entirely, or contains an otherwise unrecognized token.
Common causes:
- A bare number without a unit, like
margin-bottom: 10instead ofmargin-bottom: 10px. Zero is the only length value that does not require a unit. - A typo in the unit or keyword, like
margin-bottom: 10 px(with a space) ormargin-bottom: auто(mixed character encodings). - An invalid keyword, like
margin-bottom: none. Themargin-bottomproperty does not acceptnone.
Example with the error
<p style="margin-bottom: 10">This paragraph has an invalid margin.</p>
The value 10 is not valid because it lacks a unit.
Fixed example
<p style="margin-bottom: 10px">This paragraph has a valid margin.</p>
Adding a recognized unit like px, em, rem, or % fixes the error. If the intended value is zero, margin-bottom: 0 is valid without a unit.
When the W3C validator reports that "px" is not a valid margin-left value, it means the CSS declaration is missing its numeric component. A bare unit like px is meaningless on its own — CSS needs to know how many pixels you want. This typically happens due to a typo, an accidental deletion, or a templating/build tool that outputted an empty variable before the unit.
This matters because browsers will discard the entire declaration as invalid, meaning margin-left will fall back to its default or inherited value. This can cause unexpected layout shifts and make your design behave inconsistently. The issue applies equally to any CSS length property, not just margin-left.
Valid values for margin-left
The margin-left property accepts:
- A length value: a number followed by a unit, such as
10px,2em,1.5rem,5vw - A percentage: e.g.,
5% - The keyword
auto - The value
0(which requires no unit)
A unit without a preceding number (like px, em, or %) is never valid.
Examples
Incorrect: unit with no number
<div style="margin-left: px;">Content</div>
The browser cannot interpret px alone and will ignore the declaration entirely.
Correct: number with a unit
<div style="margin-left: 10px;">Content</div>
Correct: zero margin (no unit needed)
<div style="margin-left: 0;">Content</div>
Incorrect: empty variable in a template
This issue often appears when a dynamic value is missing. For example, in a template:
<!-- If "spacing" is empty, this produces "margin-left: px;" -->
<div style="margin-left: {{spacing}}px;">Content</div>
To guard against this, ensure the variable always contains a valid number, or provide a fallback default.
Correct: using CSS custom properties with a fallback
If you're working with CSS custom properties, you can use var() with a fallback value to prevent invalid declarations:
<div style="margin-left: var(--spacing, 10px);">Content</div>
Correct: in an external stylesheet
If the issue is in a linked stylesheet rather than inline styles, the same fix applies:
/* Incorrect */
.sidebar {
margin-left: px;
}
/* Correct */
.sidebar {
margin-left: 20px;
}
Quick checklist
- Ensure every length value has a number before the unit (e.g.,
16px,1em,2rem). - If you want no margin, use
0— it's the only numeric value that doesn't need a unit. - If using templates or preprocessors, verify that variables resolve to actual numbers before being concatenated with units.
- Consider using CSS
calc()if you need computed values:margin-left: calc(2em + 4px);.
CSS length values must always pair a number with a unit — writing just px, em, %, or any other unit without a preceding number is meaningless to the browser and will be ignored. This typically happens due to a typo, a copy-paste error, or a build tool / template that outputs a unit without its corresponding numeric value (e.g., a variable that resolved to an empty string concatenated with px).
When the W3C validator encounters margin: px in an inline style attribute, it flags the error because px on its own does not match any valid CSS value for the margin property. Valid values include lengths like 10px or 2em, percentages like 5%, the keyword auto, or the number 0 (which doesn't need a unit). Browsers will discard the invalid declaration, meaning your intended spacing won't be applied — potentially breaking your layout in subtle ways that are hard to debug.
This issue also applies to other CSS properties that accept length values, such as padding, width, height, top, left, border-width, font-size, and many more. The fix is always the same: ensure every unit has an accompanying number.
How to Fix It
- Add the missing number before the unit: change
pxto something like10px,1.5em, or20%. - Use
0without a unit if you want zero margin — writingmargin: 0is valid and preferred overmargin: 0px. - Use a keyword if appropriate, such as
margin: autofor centering. - Remove the declaration if the margin value was unintentional or unnecessary.
If the value comes from a preprocessor, template engine, or JavaScript, check that the variable being interpolated is not empty or undefined before it gets concatenated with the unit string.
Examples
Incorrect: Unit Without a Number
<div style="margin: px;">Content</div>
The value px has no number, so this is invalid CSS.
Correct: Number Paired With Unit
<div style="margin: 10px;">Content</div>
Correct: Zero Margin (No Unit Needed)
<div style="margin: 0;">Content</div>
Correct: Using a Keyword
<div style="margin: auto;">Content</div>
Incorrect in an External Stylesheet
This same error can appear in a <style> block or linked stylesheet:
<style>
.card {
margin: px;
}
</style>
Correct in an External Stylesheet
<style>
.card {
margin: 16px;
}
</style>
Watch Out for Template Variables
A common cause in templating systems is an empty variable:
<!-- If spacing is empty, this produces "margin: px;" -->
<div style="margin: {{ spacing }}px;">Content</div>
To prevent this, ensure the variable contains the full value including the number, or add a fallback:
<div style="margin: 16px;">Content</div>
When you write margin-right: px, the browser cannot determine what margin to apply because px alone is not a recognized CSS value — it's just a unit suffix without a quantity. CSS length values are always a combination of a number and a unit (e.g., 10px, 1.5em, 20%), or a specific keyword like auto, inherit, or 0 (which doesn't require a unit). The lone px is meaningless on its own and will be ignored by browsers, which means your intended spacing won't be applied.
This issue typically arises in a few common scenarios:
- A number was accidentally deleted during editing, leaving behind just the unit.
- A CSS preprocessor variable or template expression failed to output a value, resulting in only the unit being rendered.
- A typo or copy-paste error stripped the numeric portion.
Beyond simply not working, invalid CSS can cause unpredictable rendering differences across browsers. It also makes your code harder to maintain, as other developers may not understand the intended value.
To fix this, determine what numeric value you intended and place it directly before the px unit with no space between the number and unit. If no margin is needed, either remove the property entirely or set it to 0.
Examples
Incorrect: unit without a number
<div style="margin-right: px;">Content</div>
The validator reports that px is not a valid margin-right value because no number precedes the unit.
Fixed: complete value with number and unit
<div style="margin-right: 10px;">Content</div>
Fixed: using zero (no unit required)
<div style="margin-right: 0;">Content</div>
When the value is 0, no unit is needed since zero is the same in all units.
Fixed: using a keyword value
<div style="margin-right: auto;">Content</div>
The auto keyword is a valid value for margin-right and is commonly used for centering or pushing elements.
Watch for preprocessor or template issues
If you're using a CSS preprocessor or a templating language, make sure your variables resolve to complete values:
/* Incorrect — if $spacing is empty, this outputs "margin-right: px;" */
.sidebar {
margin-right: px;
}
/* Correct */
.sidebar {
margin-right: 16px;
}
Other valid units
Any valid CSS length unit works, as long as a number precedes it:
<div style="margin-right: 2em;">Em-based margin</div>
<div style="margin-right: 5%;">Percentage-based margin</div>
<div style="margin-right: 1.5rem;">Rem-based margin</div>
The margin shorthand property sets the margin area on all four sides of an element. It accepts one to four values, where each value must be a valid CSS length (e.g., 10px, 1em, 0), a percentage, or the keyword auto. When the validator reports "Too many values or values are not recognized," it means either more than four values were supplied, or at least one of the values is something CSS doesn't understand — such as a misspelled unit, a missing unit on a non-zero number, or an invalid keyword.
Common causes of this error include:
- Too many values: Providing five or more values (e.g.,
margin: 1px 2px 3px 4px 5px). The shorthand accepts a maximum of four. - Missing units: Writing a non-zero number without a unit (e.g.,
margin: 10instead ofmargin: 10px). Only0is valid without a unit. - Typos or invalid units: Using a misspelled or nonexistent unit like
margin: 10xpormargin: 10pixels. - Invalid keywords: Using a keyword that isn't recognized in the
margincontext (e.g.,margin: none). The only non-global keywordmarginaccepts isauto. - Missing separators or extra characters: Including commas or other unexpected characters between values (e.g.,
margin: 10px, 20px). Values should be separated by spaces, not commas.
This matters because browsers may ignore or misinterpret an invalid margin declaration entirely, leading to broken or inconsistent layouts across different browsers. Writing valid CSS ensures predictable rendering and easier maintenance.
How margin shorthand values work
The number of values you provide determines how they are applied:
- 1 value: Applied to all four sides.
margin: 10px→ top, right, bottom, and left all get10px. - 2 values: First is top and bottom, second is left and right.
margin: 10px 20px→ top/bottom10px, left/right20px. - 3 values: First is top, second is left and right, third is bottom.
margin: 10px 20px 30px. - 4 values: Applied clockwise — top, right, bottom, left.
margin: 10px 20px 30px 40px.
Examples
❌ Too many values
/* Five values — invalid */
.box {
margin: 10px 20px 30px 40px 50px;
}
❌ Missing unit on a non-zero number
.box {
margin: 10 20px;
}
❌ Invalid keyword
.box {
margin: none;
}
❌ Comma-separated values
.box {
margin: 10px, 20px;
}
✅ Correct: one to four valid values
/* All four sides */
.box {
margin: 10px;
}
/* Top/bottom and left/right */
.box {
margin: 10px 20px;
}
/* Top, left/right, bottom */
.box {
margin: 10px auto 20px;
}
/* Top, right, bottom, left */
.box {
margin: 10px 20px 30px 40px;
}
✅ Correct: using auto for centering
.container {
margin: 0 auto;
}
✅ Correct: zero without a unit
.box {
margin: 0;
}
✅ Correct: using global keywords
.box {
margin: inherit;
}
If you need to set margins on more than four sides independently (which isn't possible — elements only have four sides), you likely have a logic error. If you want fine-grained control, use the individual longhand properties (margin-top, margin-right, margin-bottom, margin-left) instead of the shorthand.
The margin-top property accepts several types of values: lengths (like 10px, 1.5em, 2rem), percentages (like 5%), the keyword auto, or the value 0. When you write margin-top: px, the browser encounters a bare unit with no associated number, which is meaningless — it doesn't know how many pixels you want. Browsers will ignore the invalid declaration entirely, which means margin-top will fall back to its default or inherited value. This can lead to unexpected layout results that may differ across browsers.
This error commonly happens due to a typo, an accidental deletion of the numeric portion, or a templating/build tool that failed to interpolate a variable (e.g., margin-top: ${value}px where value was empty). It can also occur when editing CSS quickly and removing the number while intending to change it.
Beyond just margin-top, this same principle applies to all CSS properties that accept length values — margin, padding, width, height, font-size, border-width, and many others. A bare unit without a number is never valid.
Note: The value 0 is the only numeric length that does not require a unit. Writing margin-top: 0 is perfectly valid and equivalent to margin-top: 0px.
How to fix it
- Add the missing number before the unit. Determine the spacing you need and prepend it to the unit (e.g.,
10px,1.5em). - Use a valid keyword if you don't need a specific numeric value —
autoorinherit, for example. - Check template variables if you use a preprocessor or templating system. Make sure the variable that provides the number is defined and not empty.
Examples
Incorrect: bare unit with no number
<div style="margin-top: px;">Content</div>
The validator reports that "px" is not a valid margin-top value because it lacks a numeric component.
Correct: number followed by a unit
<div style="margin-top: 10px;">Content</div>
Correct: using zero without a unit
<div style="margin-top: 0;">Content</div>
Correct: using a keyword value
<div style="margin-top: auto;">Content</div>
Incorrect in a stylesheet
<style>
.box {
margin-top: px;
}
</style>
<div class="box">Content</div>
Correct in a stylesheet
<style>
.box {
margin-top: 16px;
}
</style>
<div class="box">Content</div>
Incorrect with CSS preprocessor output
If you use a preprocessor like Sass or a JavaScript framework, an undefined or empty variable can produce this error:
<!-- If the variable was empty, the rendered output becomes: -->
<div style="margin-top: px;">Content</div>
Ensure the variable has a valid numeric value so the rendered CSS is complete:
<div style="margin-top: 20px;">Content</div>
In CSS, property values such as lengths, percentages, and keywords are written without quotation marks. Quotes in CSS are reserved for specific contexts like content property strings, font family names with spaces, and url() paths. When you wrap a margin value (or any similar CSS property value) in double or single quotes, the CSS parser interprets it as a string literal rather than a set of length or keyword values. Since "0 0 1em 0" is a string and not a valid margin value, the declaration is ignored by browsers and flagged by the W3C validator.
This is a problem for several reasons. First, the style will silently fail — browsers discard CSS declarations they can't parse, so your intended margins won't be applied, potentially breaking your layout. Second, it indicates a misunderstanding of CSS syntax that could lead to similar errors in other properties. This mistake commonly occurs when developers confuse HTML attribute quoting rules with CSS value syntax, especially when writing inline style attributes where the attribute value itself is already quoted.
The margin property accepts one to four values, each of which can be a length (e.g., 10px, 1em), a percentage, auto, or a global keyword like inherit. None of these require quotes. The fix is straightforward: remove the quotation marks around the CSS value.
Examples
❌ Incorrect: margin value wrapped in quotes
In a <style> block:
<style>
.card {
margin: "0 0 1em 0";
}
</style>
In an inline style:
<p style="margin: '10px auto'">Hello</p>
Both of these produce the validator error because the CSS parser sees a quoted string instead of valid margin values.
✅ Correct: margin value without quotes
In a <style> block:
<style>
.card {
margin: 0 0 1em 0;
}
</style>
In an inline style:
<p style="margin: 10px auto">Hello</p>
Valid margin value formats
For reference, here are the accepted patterns for the margin property — none of which use quotes:
/* All four sides */
margin: 1em;
/* Vertical | Horizontal */
margin: 5% auto;
/* Top | Horizontal | Bottom */
margin: 1em auto 2em;
/* Top | Right | Bottom | Left */
margin: 2px 1em 0 auto;
/* Global keywords */
margin: inherit;
margin: initial;
margin: unset;
Watch out for inline style quoting confusion
A common source of this mistake is confusion about the quotes used for the HTML style attribute versus the CSS values inside it. The outer quotes delimit the attribute value for HTML — the CSS inside should not have its own quotes around property values:
<!-- ❌ Wrong: extra quotes around the CSS value -->
<div style="margin: '1em'"></div>
<!-- ✅ Correct: only the HTML attribute is quoted -->
<div style="margin: 1em"></div>
This same rule applies to other CSS properties like padding, border, font-size, color, and so on. If you see a similar validator error for any CSS property, check whether you've accidentally quoted the value.
The value given to a single-side margin property such as margin-left or margin-right does not match the syntax CSS allows for it, so browsers ignore the whole declaration.
Each side property (margin-top, margin-right, margin-bottom and margin-left) takes one value: a length like 10px or -1.5rem, a percentage like 5%, the keyword auto, or a global keyword such as inherit. Negative lengths are allowed, so -21px on its own is fine.
A common cause is wrapping the value in quotes, as in margin-left: '-21px'. Quotes turn the value into a CSS string, and no margin property accepts a string. This tends to happen when the style is built by code that quotes values the way JavaScript does (element.style.marginLeft = '-21px'). Putting !important inside the quotes makes it part of the string as well, so the priority flag is lost along with the value.
A keyword the property doesn't support, like margin-right: none, triggers the same message.
Invalid example
<div style="margin-left: '-21px !important'; margin-right: '-21px !important';">
Wide banner
</div>
Valid example
Remove the quotes and keep !important after the value:
<div style="margin-left: -21px !important; margin-right: -21px !important;">
Wide banner
</div>
The mask-image CSS property sets one or more mask layers for an element, controlling which parts are visible based on the mask's alpha channel or luminance. According to the CSS Masking specification, the property accepts a comma-separated list of mask references, where each individual value must be one of:
none— No mask layer is applied.- A
<image>value — This includesurl()references to image files (PNG, SVG, etc.) and CSS image functions likeimage(). - A CSS gradient — Functions like
linear-gradient(),radial-gradient(),conic-gradient(), and their repeating variants (repeating-linear-gradient(), etc.).
When the validator encounters a value that doesn't match any of these accepted forms, it flags the error. This matters because browsers will silently discard invalid mask-image declarations, meaning your intended masking effect won't apply, and the element will render as if no mask were set.
Common causes
Typos in gradient or function names are a frequent trigger. For example, writing linear-gradiant() instead of linear-gradient(), or radial-grad() instead of radial-gradient().
Bare image paths without url() will also cause this error. The value mask.png is not valid on its own — it must be wrapped as url('mask.png').
Unsupported keywords or arbitrary strings like mask-image: circle or mask-image: overlay are not valid. The only keyword mask-image accepts is none.
Malformed gradient syntax such as missing parentheses, invalid color stops, or incorrect direction keywords can also produce this error. For instance, linear-gradient(right, red, blue) is invalid because directional keywords require the to prefix.
Vendor-prefixed values used without the matching prefix on the property can trigger issues as well. Using -webkit-gradient() as a value for the standard mask-image property may not validate.
Examples
Incorrect: bare image path without url()
<div style="mask-image: mask.png;">
Content here
</div>
Correct: image path wrapped in url()
<div style="mask-image: url('mask.png');">
Content here
</div>
Incorrect: typo in gradient function name
<div style="mask-image: linear-gradiant(to right, transparent, black);">
Content here
</div>
Correct: properly spelled gradient function
<div style="mask-image: linear-gradient(to right, transparent, black);">
Content here
</div>
Incorrect: missing to keyword in gradient direction
<div style="mask-image: linear-gradient(right, transparent, black);">
Content here
</div>
Correct: direction uses the to keyword
<div style="mask-image: linear-gradient(to right, transparent, black);">
Content here
</div>
Incorrect: unsupported keyword
<div style="mask-image: overlay;">
Content here
</div>
Correct: using none to explicitly disable masking
<div style="mask-image: none;">
Content here
</div>
Correct: multiple mask layers
<div style="mask-image: url('star.svg'), linear-gradient(to bottom, black, transparent);">
Content here
</div>
Correct: radial gradient as a mask
<div style="mask-image: radial-gradient(circle, black 50%, transparent 100%);">
Content here
</div>
Note that browser support for the unprefixed mask-image property has improved significantly, but some older browsers may still require the -webkit-mask-image prefix. When using the prefixed version, make sure to also include the standard property for forward compatibility. The W3C validator checks against the standard syntax, so always ensure your standard mask-image declaration uses valid values even if you also include prefixed versions.
The mask CSS shorthand property allows you to hide parts of an element by masking or clipping it at specific points. It combines several longhand properties into one declaration: mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-size, and mask-composite.
Because mask is a shorthand that accepts values for many sub-properties, it's easy to trigger validation errors. Common causes include:
- Too many values: Providing more values than the shorthand grammar allows, or duplicating values for the same sub-property.
- Unrecognized values: Using vendor-specific values (like
-webkit-prefixed keywords), typos, or values that belong to a different CSS property. - Incorrect value order: The shorthand has a specific grammar. For example,
mask-sizevalues must followmask-positionvalues and be separated by a/, similar to thebackgroundshorthand. - Mixing shorthand and longhand concepts: Trying to set values that aren't part of the
maskshorthand grammar.
The formal syntax for a single mask layer is:
<mask-layer> = <mask-reference> || <position> [ / <bg-size> ]? || <repeat-style> ||
<geometry-box> || [ <geometry-box> | no-clip ] || <compositing-operator> ||
<masking-mode>
This is a problem for standards compliance because invalid CSS can lead to the entire declaration being ignored by browsers, causing your masking effect to silently fail. It also affects cross-browser compatibility — different browsers have varying levels of support for the mask shorthand, and using individual longhand properties is often more reliable.
To fix this issue:
- Check each value in your
maskdeclaration and ensure it's a valid value for one of the mask sub-properties. - Use longhand properties instead of the shorthand if you only need to set one or two aspects of the mask. This avoids ambiguity and improves readability.
- Separate position and size with
/if you're specifying both, e.g.,center / contain. - Remove or separate vendor prefixes — use
-webkit-maskfor WebKit-specific syntax and the standardmaskfor standards-compliant syntax, but don't mix prefixed values into the unprefixed property.
Examples
Incorrect: too many or unrecognized values in the shorthand
<style>
.masked {
/* Error: too many values / unrecognized combination */
mask: url(mask.svg) center center no-repeat contain;
}
</style>
<div class="masked">Content</div>
Here, contain is a mask-size value but it must be separated from the position with a /. Without the slash, the validator sees an extra unrecognized value.
Correct: proper shorthand syntax with position and size
<style>
.masked {
mask: url(mask.svg) center / contain no-repeat;
}
</style>
<div class="masked">Content</div>
The / separates mask-position (center) from mask-size (contain), just like in the background shorthand.
Correct: using longhand properties for clarity and compatibility
<style>
.masked {
width: 100px;
height: 100px;
background-color: #8cffb0;
-webkit-mask-image: url(sun.svg);
mask-image: url(sun.svg);
mask-repeat: no-repeat;
mask-position: center;
mask-size: contain;
}
</style>
<div class="masked">Content</div>
Using individual longhand properties avoids shorthand parsing issues entirely. Including the -webkit-mask-image prefix alongside the standard mask-image ensures broader browser support.
Incorrect: unrecognized value in the shorthand
<style>
.masked {
/* "luminance" is a mask-mode value but may not be recognized in the shorthand by all validators */
mask: url(mask.png) luminance;
}
</style>
<div class="masked">Content</div>
Correct: using the longhand for mask mode
<style>
.masked {
mask-image: url(mask.png);
mask-mode: luminance;
}
</style>
<div class="masked">Content</div>
When in doubt, splitting the mask shorthand into its individual longhand properties is the safest approach. It makes your intent explicit, avoids validation errors, and tends to have better cross-browser support.
The mask CSS shorthand property allows you to partially or fully hide portions of an element by applying a graphical mask. It is a shorthand for several sub-properties including mask-image, mask-mode, mask-repeat, mask-position, mask-clip, mask-origin, mask-size, and mask-composite. Because it's a shorthand, each value you provide must correspond to one of these sub-properties' accepted values. The validator triggers this error when it encounters a value that doesn't fit any of them — for example, an arbitrary keyword, a misspelled function name, or an unsupported syntax.
Common causes of this error include:
- Arbitrary keywords — Using made-up names like
star-shapeorcircle-maskthat aren't valid CSS values. - Misspelled functions or keywords — Typos such as
lnear-gradient()instead oflinear-gradient(), ornoeninstead ofnone. - Browser-prefixed values without the standard value — Using
-webkit-masksyntax or values that don't align with the standardmaskproperty. - Invalid shorthand combinations — Providing sub-property values in an order or combination the shorthand doesn't accept.
- Missing
url()wrapper — Referencing an image file path directly without wrapping it in theurl()function.
This matters for standards compliance because browsers may silently ignore invalid mask values, resulting in the mask not being applied at all. Your design could look completely different than intended, and the failure may be hard to debug without validation.
Valid mask values
The mask property accepts one or more comma-separated mask layers. Each layer can include:
none— No mask is applied.url()— A reference to an SVG mask element or an image file (e.g.,url(mask.svg),url(mask.png)).- CSS image functions — Such as
linear-gradient(),radial-gradient(),conic-gradient(),image(), etc. - Geometry box keywords (for
mask-clip/mask-origin) — Such ascontent-box,padding-box,border-box,fill-box,stroke-box,view-box. - Compositing keywords (for
mask-composite) — Such asadd,subtract,intersect,exclude.
Examples
Incorrect: arbitrary keyword as a mask value
<div style="mask: star-shape;">
Masked Content
</div>
The value star-shape is not a recognized mask value and will be rejected by the validator.
Incorrect: missing url() function
<div style="mask: star.svg;">
Masked Content
</div>
A bare file path is not valid. Image references must be wrapped in the url() function.
Correct: using url() to reference a mask image
<div style="mask: url(star.svg);">
Masked Content
</div>
Correct: using none to explicitly disable masking
<div style="mask: none;">
No Mask Applied
</div>
Correct: using a gradient as a mask
<div style="mask: linear-gradient(to right, transparent, black);">
Fading Content
</div>
Correct: combining multiple shorthand values
<div style="mask: url(mask.png) no-repeat center / contain;">
Masked Content
</div>
This sets the mask image, repeat behavior, position, and size in a single shorthand declaration.
Correct: multiple mask layers
<div style="mask: url(shape.svg) no-repeat, linear-gradient(to bottom, black, transparent);">
Multi-layer Mask
</div>
When fixing this error, double-check your value against the CSS Masking specification on MDN. If you're using vendor-prefixed versions like -webkit-mask, also ensure the standard mask property is present with valid values for forward compatibility.
max-height takes none, a length, a percentage or a sizing keyword such as fit-content, and the validator rejects anything else, including auto.
auto is valid for height and min-height, so it's easy to carry it over to max-height. That property has no automatic value. Its initial value is none, meaning no limit, and a browser that reads max-height: auto drops the declaration as invalid.
That matters when auto is meant to undo a limit from another rule, such as a collapsed panel with max-height: 0 that opens when a class is added, or a fixed cap that a media query should lift. The browser skips the auto, the earlier value still applies, and the content remains clipped. Write none to remove the limit.
Made-up keywords such as full get the same message. Besides none, the property accepts lengths like 300px or 80vh, percentages of the containing block's height, the keywords min-content, max-content and fit-content, and global keywords such as inherit and initial.
Invalid example
<style>
.panel {
max-height: 0;
overflow: hidden;
}
.panel.is-open {
max-height: auto;
}
</style>
Valid example
<style>
.panel {
max-height: 0;
overflow: hidden;
}
.panel.is-open {
max-height: none;
}
</style>
The max-width property sets the maximum width an element can grow to, preventing the computed value of width from exceeding the specified limit. While many CSS sizing properties accept auto as a value (for example, width: auto and margin: auto are perfectly valid), the max-width property does not. This is a common mistake because developers often assume auto is universally accepted across similar properties.
When a browser encounters max-width: auto, it will typically ignore the invalid declaration and fall back to the default value of none. While the page may still render as expected in some browsers, relying on this behavior is unreliable and non-standard. Writing valid CSS ensures consistent rendering across all browsers and makes your stylesheets easier to maintain and debug.
If your intent is to remove a maximum width constraint (effectively making max-width have no effect), use none — this is the default value. If you want the element to size itself based on its content, use max-content, min-content, or fit-content. If you need to reset the property to its initial value, use initial (which resolves to none).
Valid values for max-width
The max-width property accepts the following types of values:
none— No limit on the element's width (the default).- Length values — Such as
500px,3.5em,20rem,80ch. - Percentage values — Such as
75%, relative to the containing block's width. - Keyword values —
max-content,min-content,fit-content, orfit-content(<length>). - Global values —
inherit,initial,revert,unset.
Examples
❌ Incorrect: using auto with max-width
<div style="max-width: auto;">
This container has an invalid max-width value.
</div>
This triggers the validation error because auto is not a valid max-width value.
✅ Fixed: using none to remove the constraint
If you want no maximum width limit (the most likely intent when writing auto), use none:
<div style="max-width: none;">
This container has no maximum width constraint.
</div>
✅ Fixed: using a specific length or percentage
If you want to cap the element's width at a specific size:
<div style="max-width: 600px;">
This container will not grow beyond 600 pixels.
</div>
<div style="max-width: 80%;">
This container will not exceed 80% of its parent's width.
</div>
✅ Fixed: using intrinsic sizing keywords
If you want the element's maximum width to be based on its content:
<div style="max-width: max-content;">
This container's max width is determined by its content.
</div>
A max-width declaration subtracts a length from the none keyword, and a keyword can't take part in arithmetic.
none means the element has no maximum width, which leaves nothing to subtract 20 pixels from. CSS identifiers can contain hyphens and digits, so the browser reads none-20px as one unknown keyword and drops the declaration. The element then takes its max-width from an earlier rule, or has no limit at all. Adding spaces doesn't help: none - 20px is a parse error, and calc(none - 20px) fails too, because calc() only works with numeric values such as lengths and percentages.
A value like this is usually the output of a preprocessor. In Sass, $max-width - 20px compiles to none-20px when $max-width is none. To Sass, none is a string, and its - operator joins a string and another value with a hyphen instead of subtracting.
Work out which width you meant. To keep the element 20 pixels narrower than its container, use calc(100% - 20px). If you didn't want a limit, write none on its own. In a Sass mixin or function, only subtract from the variable when it holds a length, and output none unchanged otherwise.
Invalid example
<div style="max-width: none-20px;">
<p>This panel was meant to stay 20 pixels narrower than its container.</p>
</div>
Valid example
<div style="max-width: calc(100% - 20px);">
<p>This panel stays 20 pixels narrower than its container.</p>
</div>
A max-width declaration has the unit px with no number in front of it, so the browser can't read it as a length.
A CSS length is a number followed by a unit, written together: 600px, 40rem, 75ch. The unit alone means nothing. Browsers drop the invalid declaration, so the element falls back to max-width: none and can grow wider than you intended.
The cause is usually a template that prints a number variable right before a hard-coded px. When the variable is empty, the output is max-width: px;. Make sure the variable always holds a number, or leave the declaration out when there's no value. If you want no limit at all, use none.
The number and the unit can't be separated by a space either. max-width: 600 px; triggers a different validator error, "Too many values or values are not recognized".
Invalid example
<div style="max-width: px;">
<p>This text block has no width limit.</p>
</div>
Valid example
<div style="max-width: 600px;">
<p>This text block stops growing at 600 pixels.</p>
</div>
A max-width declaration holds a value the property doesn't accept, often the word undefined printed by a script or template in place of a missing value.
JavaScript turns a missing value into the text undefined when it builds a string, so "max-width: " + options.maxWidth produces max-width: undefined. Appending a unit gives undefinedpx, arithmetic on a missing number gives NaNpx, and a null variable prints null. The validator quotes whatever ended up in the CSS, and it reports made-up keywords such as full with the same message.
A browser that can't parse the value drops the declaration. The element keeps the max-width from an earlier rule, or has no limit at all, so an image or text block meant to stay narrow can stretch to the full width of its container.
Fix the code that generates the value. Give the variable a default, for example options.maxWidth ?? "100%", or leave the declaration out when there's no value. The property accepts none (its initial value, meaning no limit), lengths such as 600px or 40rem, percentages of the containing block's width, the keywords min-content, max-content and fit-content, the fit-content() function, calc() expressions, and global keywords such as inherit. A number with no unit, such as 600, gets a different validator message asking for a unit.
Invalid example
<img src="harbor.jpg" alt="Fishing boats moored in the harbor" width="1200" height="800" style="max-width: undefined;">
Valid example
<img src="harbor.jpg" alt="Fishing boats moored in the harbor" width="1200" height="800" style="max-width: 100%;">
A math function in the min-height value, such as calc(), min(), max() or clamp(), combines values whose types can't be mixed, like a length and a unitless number.
min-height sets the smallest height an element can have, even when its content would make it shorter. The property takes a length such as 300px or 50vh, a percentage, or a keyword like auto, so any math function inside it has to produce a length or a percentage too.
When calc() adds or subtracts, both sides must have the same type. calc(100vh - 80px) subtracts one length from another, but calc(100vh - 80) subtracts a plain number from a length, and the result has no type the browser can use. The arguments of min(), max() and clamp() follow the same rule, so max(300px, 50) can't compare a length with a number.
This mistake often turns up in a full-screen section that subtracts a fixed header from the viewport height, with the unit left off the header's height. Multiplication is different: one side can be a plain number that scales the other, so calc(100vh - 2 * 40px) is valid.
Browsers ignore a declaration with a mistyped expression. The element keeps the min-height it got from earlier rules, usually auto, and the section can end up shorter than you intended.
The validator doesn't look inside var(), so a custom property that holds a bare number passes validation. The browser still rejects the result once it substitutes the value.
Invalid example
<div style="min-height: calc(100vh - 80);">Hero</div>
<div style="min-height: max(300px, 50);">Card</div>
Valid example
<div style="min-height: calc(100vh - 80px);">Hero</div>
<div style="min-height: max(300px, 50vh);">Card</div>
The min-height property sets the minimum height of an element. Unlike shorthand properties such as margin or padding, min-height accepts only a single value. Providing multiple space-separated values (e.g., min-height: 100px 200px) is invalid and will trigger this error.
This error commonly occurs for several reasons:
- Multiple values provided:
min-heightis not a shorthand and does not accept more than one value. - Invalid units or typos: Using an unrecognized unit (e.g.,
100pixelsinstead of100px) or a misspelled keyword. - Using unsupported CSS functions or syntax: Some newer CSS features like
min-height: fit-content(200px)may not be recognized by the validator or may lack browser support. - Confusing
min-heightwith other properties: Accidentally using syntax meant for properties likegrid-template-rowsorminmax()expressions. - Missing units on non-zero values: Writing
min-height: 100instead ofmin-height: 100px. Zero is the only numeric value that doesn't require a unit.
According to the CSS specification, valid values for min-height include:
| Value Type | Examples |
|---|---|
| Length | 0, 100px, 10em, 5rem, 50vh |
| Percentage | 50%, 100% |
| Keywords | auto, min-content, max-content, none |
| Functions | fit-content, calc(100vh - 50px) |
Fixing this issue ensures your CSS is standards-compliant and behaves predictably across browsers. Invalid min-height values will be ignored by browsers, which means your layout may not render as intended.
Examples
Incorrect: multiple values
<div style="min-height: 100px 200px;">Content</div>
min-height only accepts a single value. This is not a shorthand property.
Incorrect: missing unit
<div style="min-height: 100;">Content</div>
Non-zero numeric values must include a unit.
Incorrect: invalid keyword or typo
<div style="min-height: inheret;">Content</div>
The keyword inherit is misspelled.
Correct: single length value
<div style="min-height: 100px;">Content</div>
Correct: percentage value
<div style="min-height: 50%;">Content</div>
Correct: using calc() for computed values
<div style="min-height: calc(100vh - 80px);">Content</div>
Correct: using a keyword
<div style="min-height: min-content;">Content</div>
Correct: using auto
<div style="min-height: auto;">Content</div>
If you need to set both a minimum and maximum height on an element, use min-height and max-height as separate properties:
<div style="min-height: 100px; max-height: 400px;">Content</div>
The min-width value uses a math function such as calc(), min(), max() or clamp() to combine values whose types don't match, most often a length and a number with no unit.
min-width keeps an element from getting narrower than a given size, even when its container shrinks or its width asks for less. It accepts a length like 320px or 20rem, a percentage, or a keyword such as auto or min-content, so any math function in it has to work out to a length or a percentage.
Addition and subtraction inside calc() only work between values of the same type. calc(100vw - 300px) takes one length away from another, while calc(100vw - 300) takes a bare number away from a length, which CSS can't compute. The comparison functions apply the same rule to their arguments: max(320px, 50) asks for the larger of a length and a number, and clamp(200, 50%, 400px) sets a lower bound with no unit.
A common source is a layout that subtracts the width of a sidebar or fixed column from the viewport, with the unit left off that width. Multiplying or dividing by a plain number is fine, because the number only scales the other value: calc(100vw - 2 * 150px) is valid.
Browsers drop a declaration whose expression has the wrong type. The element then uses the min-width from earlier rules, or the initial auto, and the column can shrink below the size you planned when the screen is narrow.
The validator only reports this error when one of the values is a length. It lets calc(100% - 300) and max(50%, 10) through, but browsers reject those as well, so check percentage expressions for a missing unit yourself. It also skips values that come from var().
Invalid example
<style>
.content {
min-width: calc(100vw - 300);
}
.card {
min-width: max(320px, 50);
}
</style>
Valid example
<style>
.content {
min-width: calc(100vw - 300px);
}
.card {
min-width: max(320px, 50%);
}
</style>
The CSS min-width property has a quoted string as its value, such as "" or "200px", and strings are not valid for this property.
min-width accepts a length (200px, 12rem), a percentage (50%), 0, a calc() expression, the keywords auto, min-content, max-content and fit-content, and CSS-wide keywords like inherit. Anything wrapped in quotes is a CSS string, so min-width: "200px" is rejected even though min-width: 200px is fine. The validator repeats the string in the message: “""” means the declaration was min-width: "", an empty string.
An empty string usually comes from a template or page builder that wraps the value in quotes and prints nothing when the setting is blank. Quoted lengths often come from code copied out of JavaScript or JSON, where values are written as strings (minWidth: "200px").
To fix it, remove the quotes. If there is no value to set, remove the whole declaration; the default min-width is auto. Other bad values produce different messages: a number without a unit (min-width: 200) reports that only 0 can be unitless, and an unknown keyword (min-width: none) reports that values are not recognized.
Invalid example
<style>
.sidebar {
min-width: "";
}
.card {
min-width: "200px";
}
</style>
Valid example
<style>
.card {
min-width: 200px;
}
</style>
The empty declaration on .sidebar is gone, and the .card value has no quotes.
The mix-blend-mode property accepts a fixed set of blend mode keywords, and the validator reports anything outside that set, including typos and the newer plus-lighter keyword.
The keywords the validator accepts are normal, multiply, screen, overlay, darken, lighten, color-dodge, color-burn, hard-light, soft-light, difference, exclusion, hue, saturation, color and luminosity. Browsers drop a declaration they don't understand, so a misspelled value such as multipley leaves the element at the default normal and the blend effect never shows up.
plus-lighter is a different case. The Compositing and Blending Level 2 draft adds it to mix-blend-mode, and Chrome, Firefox and Safari support it. The validator only knows the Level 1 keywords, so it flags plus-lighter even inside an @supports block. plus-darker gets the same error, but it is not part of the mix-blend-mode grammar in the spec and only Safari supports it, so replace it.
If you need plus-lighter, for example to cross-fade two stacked images without a dip in brightness, keep it and mute this message for that value. Otherwise use screen, which also brightens the result but uses a softer formula, so compare the two visually before you switch.
Invalid example
.overlay {
mix-blend-mode: multipley;
}
.crossfade img {
mix-blend-mode: plus-lighter;
}
Valid example
.overlay {
mix-blend-mode: multiply;
}
.crossfade img {
mix-blend-mode: screen;
}
These mso- prefixed properties are most commonly introduced when content is copied and pasted from Microsoft Word or other Office applications into an HTML editor. Microsoft Office generates heavily styled HTML with dozens of proprietary CSS properties designed to preserve the document's formatting when rendered back in Office products. While browsers silently ignore these unknown properties, they clutter your markup, inflate file size, and violate web standards.
This is a problem for several reasons. First, these properties have no effect in any web browser — they are purely artifacts of Microsoft's internal rendering engine. Second, they significantly bloat your HTML, sometimes doubling or tripling the size of the markup. Third, they make your code harder to read and maintain. Fourth, they can cause issues with automated tools, linters, and content management systems that expect valid CSS. Finally, in the context of HTML email development, while mso- properties are sometimes intentionally used to target Microsoft Outlook's rendering engine, they should not appear in web pages intended for browsers.
How to Fix
- Identify the source. Check if the content was pasted from Microsoft Word or another Office application. This is the most common origin.
- Remove all
mso-properties. Delete every CSS declaration that starts withmso-. They serve no purpose in a browser context. - Replace with standard CSS if needed. Some
mso-properties have standard CSS equivalents. For example,mso-margin-top-altcan be replaced withmargin-top, andmso-bidi-font-weightcan be replaced withfont-weight. - Use a paste-as-plain-text workflow. When copying from Word, paste as plain text first (Ctrl+Shift+V in many editors), then apply formatting using your own CSS.
Examples
❌ Incorrect: HTML with Microsoft Office properties
<p style="mso-spacerun: yes; mso-fareast-font-family: 'Times New Roman'; margin-bottom: .0001pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-bidi-font-weight: bold; line-height: normal;">
This text was pasted from Microsoft Word.
</p>
<style>
.content {
mso-fareast-font-family: "Calibri";
mso-bidi-font-family: "Times New Roman";
font-family: Arial, sans-serif;
mso-line-height-rule: exactly;
line-height: 1.5;
}
</style>
✅ Correct: Cleaned-up HTML with only standard CSS
<p style="margin-bottom: 0; margin-top: auto; font-weight: bold; line-height: normal;">
This text was pasted from Microsoft Word.
</p>
<style>
.content {
font-family: Arial, sans-serif;
line-height: 1.5;
}
</style>
Common mso- properties and their standard replacements
mso- Property | Standard CSS Equivalent |
|---|---|
mso-margin-top-alt | margin-top |
mso-margin-bottom-alt | margin-bottom |
mso-bidi-font-weight | font-weight |
mso-bidi-font-style | font-style |
mso-bidi-font-size | font-size |
mso-fareast-font-family | font-family (use a standard font stack) |
mso-line-height-rule | No equivalent needed — remove it |
mso-spacerun | No equivalent needed — remove it |
mso-tab-count | No equivalent needed — remove it |
Many mso- properties (like mso-spacerun and mso-tab-count) control behaviors specific to Microsoft's rendering engine and have no CSS equivalent at all. These can simply be deleted without any replacement. If your content originally came from Word, it's often best to strip all formatting and restyle the content from scratch using your own clean CSS.
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