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.
A non-standard value high is being used for the prefers-contrast media feature in a <style> block or style attribute, but the valid values are no-preference, more, less, and custom.
The prefers-contrast media feature detects whether the user has requested more or less contrast through their operating system or browser settings. Early drafts of the specification used high and low as values, and some older references still mention them. The current specification replaced these with more and less.
The W3C validator flags high because it checks CSS within HTML documents against current standards. Even though some browsers may still accept high as an alias, it is non-standard and should be replaced with more.
The mapping from old to new values:
high→morelow→less
HTML example with the issue
<style>
@media(prefers-contrast: high){
body{
background: white;
color: black;
}
}
</style>
Fixed example
<style>
@media(prefers-contrast: more){
body{
background: white;
color: black;
}
}
</style>
The @import rule allows you to pull in styles from another CSS file. According to the CSS specification, @import rules must precede all other at-rules (except @charset) and all style rules. When a browser encounters an @import after another valid CSS statement, it silently ignores the import. This means the styles you intended to load simply won't be applied, which can lead to broken layouts or missing designs that are difficult to debug.
The W3C validator catches this ordering problem and flags it because the misplaced @import will have no effect. Even though browsers won't throw a visible error, the imported stylesheet is completely discarded, making this a real functional issue rather than just a cosmetic validation warning.
The correct order inside a <style> element or CSS file is:
@charset(if needed, and only in external CSS files)@importrules- All other CSS rules (
@font-face,@media, style rules, etc.)
Examples
Incorrect: @import after a style rule
<style>
body{
margin:0;
}
@importurl("typography.css");
h1{
color: navy;
}
</style>
The @import is placed after the body rule, so the browser will ignore it entirely. The styles from typography.css will never be loaded.
Incorrect: @import after another at-rule
<style>
@font-face{
font-family:"MyFont";
src:url("myfont.woff2")format("woff2");
}
@importurl("reset.css");
</style>
Even though @font-face is an at-rule, it is not @charset or @import, so placing @import after it is invalid.
Correct: @import rules first
<style>
@importurl("reset.css");
@importurl("typography.css");
@font-face{
font-family:"MyFont";
src:url("myfont.woff2")format("woff2");
}
body{
margin:0;
}
h1{
color: navy;
}
</style>
All @import rules appear before any other statements, so they are valid and the imported stylesheets will be loaded correctly.
Correct: Multiple @import rules with @charset
In an external CSS file, you may also have a @charset declaration. It must come first, followed by @import rules:
@charset"UTF-8";
@importurl("base.css");
@importurl("components.css");
body{
font-family: sans-serif;
}
Alternatives to @import
While fixing the ordering resolves the validation error, it's worth noting that @import in CSS can cause performance issues because imported files are loaded sequentially rather than in parallel. Consider these alternatives:
- Multiple
<link>elements in your HTML<head>— these allow browsers to download stylesheets in parallel. - CSS bundling tools — build tools like Webpack, Vite, or PostCSS can combine multiple CSS files into one at build time, eliminating the need for
@importat runtime.
If you do use @import, just make sure every instance appears at the very top of your stylesheet, before any other CSS rules.
A CSS selector in your style element or style attribute contains an ID that doesn't follow valid CSS syntax rules.
In CSS, ID selectors must begin with a # followed by a valid CSS identifier. A valid CSS identifier cannot start with a digit, two hyphens, or a hyphen followed by a digit, unless the identifier is properly escaped. This error commonly occurs when your HTML element has an id that begins with a number (like id="1section") and your CSS references it directly as #1section.
While HTML5 allows id values to start with numbers, CSS does not accept those values as-is in selectors. You have two options: rename the id to start with a letter or underscore, or escape the leading digit in your CSS selector using a backslash (e.g., #\31 section). Renaming the id is almost always the simpler and more maintainable approach.
Invalid ID selector
<style>
#1section {
color: red;
}
</style>
<divid="1section">Hello</div>
Fixed: Use a valid identifier
<style>
#section-1{
color: red;
}
</style>
<divid="section-1">Hello</div>
If you cannot change the id in the HTML, escape the digit in CSS:
<style>
#\31 section {
color: red;
}
</style>
<divid="1section">Hello</div>
The \31 is the Unicode code point for the character "1", and the space after it separates the escape sequence from the rest of the identifier. This is valid CSS but harder to read, so renaming the id is the preferred fix.
The W3C validator parses inline CSS values character by character. When it encounters a numeric value for the left property, it expects the characters that follow to be part of a valid number (digits, a decimal point, or e for scientific notation) or a recognized CSS unit. If it instead finds an unexpected letter like n, it raises this error. This can happen in several ways:
- Missing units: Writing
left: 10;instead ofleft: 10px;. The CSS specification requires a unit for all non-zero length values. While some browsers may interpret unitless numbers in quirks mode, this is invalid CSS and produces unpredictable results across browsers. - Typos in units: Writing something like
left: 10n;orleft: 10xp;where the intended unit waspxbut a typo introduced invalid characters. - Template or scripting artifacts: Dynamically generated values like
left: {{offset}}px;that weren't properly resolved, leaving non-numeric characters in the output. - Using
calc()incorrectly: Writingleft: 10 + 5px;instead ofleft: calc(10px + 5px);.
The left property accepts the following value types:
- Lengths: A number followed by a unit such as
px,em,rem,vw,vh,ch, etc. (e.g.,left: 10px;) - Percentages: A number followed by
%(e.g.,left: 50%;) - Keywords:
auto,inherit,initial,unset, orrevert - Functions:
calc(),min(),max(),clamp(), etc. - Zero: The value
0is the only number that does not require a unit.
Invalid CSS not only triggers validation errors but can cause layout issues. Browsers may ignore the entire declaration, falling back to the default value, which can break your intended positioning. Ensuring valid CSS improves cross-browser consistency and maintainability.
Examples
Missing unit (triggers the error)
<divstyle="position: absolute;left:10;">
Positioned element
</div>
The validator reads 10 and then encounters the ; (or in other cases a stray letter like n), which is not a valid part of a CSS length value.
Typo in unit (triggers the error)
<divstyle="position: absolute;left:10xn;">
Positioned element
</div>
Fixed with a valid length unit
<divstyle="position: absolute;left:10px;">
Positioned element
</div>
Fixed with a percentage
<divstyle="position: absolute;left:50%;">
Positioned element
</div>
Fixed with the auto keyword
<divstyle="position: absolute;left: auto;">
Positioned element
</div>
Fixed with calc()
<divstyle="position: absolute;left:calc(50%-20px);">
Positioned element
</div>
Zero without a unit (valid)
<divstyle="position: absolute;left:0;">
Positioned element
</div>
Always double-check that every non-zero numeric value for left (and other length-based properties like top, right, bottom, width, margin, etc.) includes a valid CSS unit. If you're generating styles dynamically, verify that template variables resolve to proper values before rendering.
The left property specifies the horizontal offset of a positioned element — one that has its position set to relative, absolute, fixed, or sticky. The W3C validator checks CSS within style attributes and <style> elements, and it will flag any value it cannot recognize as a valid left value.
Common causes of this error include:
- Misspelled or non-existent units: Writing
10 px(with a space),10pixels, or20ppxinstead of10px. - Unsupported keywords: Using values like
none,center, ormiddle, which are not valid for theleftproperty. - Missing units on non-zero numbers: Writing
left: 10instead ofleft: 10px. Zero is the only number that doesn't require a unit. - Typos in keyword values: Writing
auтоorautooinstead ofauto. - CSS custom properties in inline styles: Using
var(--offset)in astyleattribute may trigger validation warnings depending on the validator's CSS level.
The valid values for the left property are:
<length>: A numeric value with a unit, such as10px,2em,3rem,1vw.<percentage>: A percentage relative to the containing block's width, such as50%.auto: Lets the browser determine the position (this is the default).- Global keywords:
inherit,initial,unset, andrevert.
Using an invalid value means the browser will ignore the declaration entirely, which can break your layout. Fixing these values ensures consistent rendering across browsers and compliance with CSS standards.
Examples
Invalid: Using an unsupported keyword
The keyword none is not a valid value for the left property.
<divstyle="position: absolute;left: none;">Positioned element</div>
Invalid: Missing unit on a non-zero number
A bare number (other than 0) is not valid without a CSS unit.
<divstyle="position: relative;left:20;">Shifted element</div>
Invalid: Misspelled unit
The unit xp does not exist in CSS.
<divstyle="position: absolute;left:15xp;">Positioned element</div>
Valid: Using a length value
<divstyle="position: absolute;left:20px;">20 pixels from the left</div>
Valid: Using a percentage
<divstyle="position: absolute;left:50%;">Offset by 50% of containing block</div>
Valid: Using the auto keyword
<divstyle="position: absolute;left: auto;">Browser-determined position</div>
Valid: Using zero without a unit
Zero does not require a unit in CSS.
<divstyle="position: absolute;left:0;">Flush with the left edge</div>
Valid: Using inherit
<divstyle="position: relative;left: inherit;">Inherits left value from parent</div>
To fix this error, identify the invalid value the validator is reporting and replace it with one of the accepted value types listed above. If you intended to reset the position, use auto or 0. If you meant to remove a previously set left value, use initial or unset rather than an unsupported keyword like none.
NaN in JavaScript stands for "Not a Number" and appears when a numeric operation fails — for example, parsing a non-numeric string with parseFloat(), dividing 0 by 0, or referencing an undefined variable in arithmetic. When this NaN value gets concatenated with a unit string like "rem", the result is "NaNrem", which is meaningless to CSS. The browser cannot interpret it, and the W3C validator flags it as an invalid letter-spacing value.
This issue almost always originates from dynamically generated styles — either through JavaScript that sets inline styles, a server-side template that computes CSS values, or a CSS-in-JS library. The rendered HTML ends up containing something like style="letter-spacing: NaNrem", which the validator rightly rejects.
Beyond validation, this is a practical problem: the browser will ignore the invalid declaration entirely, so whatever letter-spacing you intended won't be applied. Your layout may look different than expected, and the invalid value in the markup signals a bug in your code that could affect other computed styles too.
How to Fix It
Trace the source of the value. Search your codebase for where
letter-spacingis set. If it's an inline style, look at the JavaScript or server-side code that generates it.Validate the number before using it. In JavaScript, use
Number.isNaN()orisFinite()to check that a computed value is valid before applying it.Provide a sensible fallback. If the calculation might fail, default to a known-good value like
0ornormal.Fix the root cause. Determine why the calculation produces
NaN— common causes include missing data attributes,undefinedvariables, or parsing non-numeric strings.
Examples
❌ Invalid: NaN concatenated with a unit
This is what the rendered HTML looks like when the bug occurs:
<pstyle="letter-spacing:NaNrem">Spaced text</p>
The JavaScript that likely produced it:
// Bug: getAttribute returns null if data-spacing is missing
letspacing=parseFloat(element.getAttribute('data-spacing'));
element.style.letterSpacing=spacing+'rem';// "NaNrem" if attribute is missing
✅ Fixed: Validate the value before applying it
letraw=parseFloat(element.getAttribute('data-spacing'));
letspacing=Number.isFinite(raw)?raw:0.1;// fallback to 0.1
element.style.letterSpacing=spacing+'rem';
This produces valid inline CSS:
<pstyle="letter-spacing: 0.1rem">Spaced text</p>
✅ Fixed: Using a static CSS value
If the letter-spacing doesn't need to be dynamic, the simplest fix is to use a plain CSS rule instead of computing it in JavaScript:
<style>
.spaced-text{
letter-spacing:0.1rem;
}
</style>
<pclass="spaced-text">Spaced text</p>
✅ Fixed: Server-side template with a guard
If a server-side template generates the style, add a check before rendering:
<!-- Pseudocode for a template engine -->
<!-- Only output the style attribute if the value is a valid number -->
<pstyle="letter-spacing: 0.05rem">Spaced text</p>
Ensure your template logic verifies the value is numeric before injecting it into the markup. If the value is missing or invalid, either omit the style attribute entirely or use a safe default.
Valid letter-spacing values for reference
The letter-spacing property accepts:
- The keyword
normal(default, lets the browser decide) - Any valid CSS length:
0.1rem,1px,0.05em,2px, etc. 0(no extra spacing)
The numeric part must always be a real number — NaN, Infinity, and empty strings are never valid.
A lexical error is a low-level parsing failure. Unlike a syntax error where the structure is wrong but the characters are individually valid, a lexical error means the parser cannot even form valid tokens from the input. The CSS specification defines a precise set of characters and sequences that are meaningful — property names, values, punctuation like ;, :, {, }, and so on. When the parser encounters something outside these expectations, such as @ where a ; should be, a curly ("smart") quote instead of a straight quote, or a stray Unicode character, it raises a lexical error.
This matters for several reasons. First, browsers handle invalid CSS unpredictably — some may skip the entire rule block, others may ignore only the broken declaration, and the behavior can vary across browser versions. This leads to inconsistent rendering for your users. Second, a single lexical error can cascade, causing the parser to misinterpret subsequent valid CSS as well, potentially breaking styles well beyond the offending line. Third, clean, valid CSS is easier to maintain, debug, and collaborate on.
Common causes of this error include:
- Invalid characters used in place of punctuation — e.g.,
@,!, or#where a semicolon or colon should be. - Smart (curly) quotes — pasting CSS from word processors or CMS editors that convert
"straight quotes"to"curly quotes"or'curly apostrophes'. - Missing semicolons — while not always a lexical error, a missing
;can cause the next line's property name to be read as part of the previous value, producing unexpected character sequences. - Non-ASCII invisible characters — byte order marks (BOM), zero-width spaces, or non-breaking spaces that are invisible in most editors but invalid in CSS tokens.
- Copy-paste artifacts — copying code from PDFs, websites, or chat applications that insert hidden formatting characters.
To fix the issue, go to the exact line and column the error references. Look at the character it reports as "Encountered" and determine what the correct character should be. If you can't see anything wrong, try deleting the characters around the reported position and retyping them manually — this eliminates invisible character problems.
Examples
Invalid character instead of semicolon
The @ symbol after blue is not valid CSS punctuation in this context:
<style>
h1{
color: blue@
font-size: 24px;
}
</style>
Replace @ with a proper semicolon:
<style>
h1{
color: blue;
font-size:24px;
}
</style>
Smart quotes in font-family
Curly quotes copied from a word processor cause a lexical error:
<style>
body{
font-family: \u201CHelvetica Neue\u201D,sans-serif;
}
</style>
Use straight double quotes instead:
<style>
body{
font-family:"Helvetica Neue", sans-serif;
}
</style>
Stray character in an inline style
An accidental backtick in a style attribute triggers the error:
<pstyle="color: red`;margin:0;">Hello</p>
Remove the invalid character:
<pstyle="color: red;margin:0;">Hello</p>
Invisible non-breaking space
Sometimes the error points to what looks like empty space. A non-breaking space (\u00A0) pasted from another source can hide between tokens:
<style>
.box{
display:\u00A0flex;
}
</style>
Delete the space and retype it as a normal ASCII space:
<style>
.box{
display: flex;
}
</style>
If you suspect invisible characters, use your text editor's "show whitespace" or "show invisible characters" feature, or paste the CSS into a hex editor to inspect the raw bytes. Configuring your editor to save files in UTF-8 without BOM also helps prevent encoding-related lexical errors.
The line-height CSS property controls the spacing between lines of text within an element. When the validator reports that a value "is not a line-height value," it means the value you provided doesn't match any of the accepted formats defined in the CSS specification.
Common mistakes that trigger this error include:
- Misspelled keywords — writing
normlorNormalinstead ofnormal(CSS keywords are case-insensitive in browsers, but some validators may flag inconsistencies; the real issue is outright misspellings). - Invalid or missing units — using a unit the spec doesn't support (e.g.,
line-height: 1.5x;) or accidentally adding a unit to what should be a unitless value (e.g., confusing1.5with1.5 emwith a space). - Malformed numbers — typos like
1..5or24ppx. - Using unsupported keywords — values like
auto,thin, orlargeare not valid forline-height. - Negative values —
line-heightdoes not accept negative numbers.
This matters for standards compliance and predictable rendering. While browsers may silently ignore an invalid line-height value and fall back to a default, this means your intended styling won't be applied — potentially causing overlapping text, poor readability, or inconsistent layouts across browsers. Fixing validation errors ensures your styles work as intended everywhere.
Valid line-height values
| Format | Example | Description |
|---|---|---|
| Keyword | normal | Browser default (typically around 1.2) |
| Unitless number | 1.5 | Multiplied by the element's font size — recommended |
| Length | 24px, 1.5em, 2rem | An absolute or relative length |
| Percentage | 150% | Relative to the element's font size |
The unitless number format is generally preferred because it scales properly with inherited font sizes, avoiding unexpected results in nested elements.
Examples
❌ Incorrect: invalid values that trigger the error
<!-- Misspelled keyword -->
<pstyle="line-height: norml;">Text with an invalid line-height.</p>
<!-- Invalid unit -->
<pstyle="line-height:1.5x;">Text with an unrecognized unit.</p>
<!-- Malformed number -->
<pstyle="line-height:1..5;">Text with a typo in the number.</p>
<!-- Unsupported keyword -->
<pstyle="line-height: auto;">Auto is not valid for line-height.</p>
<!-- Negative value -->
<pstyle="line-height:-1.5;">Negative values are not allowed.</p>
✅ Correct: valid line-height values
<!-- Keyword -->
<pstyle="line-height: normal;">Browser default line height.</p>
<!-- Unitless number (recommended) -->
<pstyle="line-height:1.5;">1.5 times the font size.</p>
<!-- Length with px -->
<pstyle="line-height:24px;">Fixed 24px line height.</p>
<!-- Length with em -->
<pstyle="line-height:1.5em;">1.5em line height.</p>
<!-- Percentage -->
<pstyle="line-height:150%;">150% of the font size.</p>
Full document example
<!DOCTYPE html>
<htmllang="en">
<head>
<title>Valid line-height Example</title>
</head>
<body>
<h1style="line-height:1.2;">A Heading with Tight Spacing</h1>
<pstyle="line-height:1.6;">This paragraph uses a unitless line-height of 1.6,
which is a common choice for body text readability. It scales correctly even
if child elements have different font sizes.</p>
</body>
</html>
Tip: unitless vs. percentage/length
A unitless line-height and a percentage line-height may look equivalent, but they behave differently with inherited styles. A unitless value is recalculated for each child element based on its own font size, while a percentage or length is computed once on the parent and that fixed value is inherited. For most cases, unitless numbers are the safest choice.
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
<divstyle="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
<divstyle="margin-bottom:10px;">Content</div>
Correct: zero margin (no unit needed)
<divstyle="margin-bottom:0;">Content</div>
Correct: using a keyword value
<divstyle="margin-bottom: auto;">Content</div>
Incorrect in a stylesheet
<htmllang="en">
<head>
<title>Example</title>
<style>
.card{
margin-bottom: px;
}
</style>
</head>
<body>
<divclass="card">Content</div>
</body>
</html>
Fixed stylesheet
<htmllang="en">
<head>
<title>Example</title>
<style>
.card{
margin-bottom:16px;
}
</style>
</head>
<body>
<divclass="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.
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
<divstyle="margin-left: px;">Content</div>
The browser cannot interpret px alone and will ignore the declaration entirely.
Correct: number with a unit
<divstyle="margin-left:10px;">Content</div>
Correct: zero margin (no unit needed)
<divstyle="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;" -->
<divstyle="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:
<divstyle="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
<divstyle="margin: px;">Content</div>
The value px has no number, so this is invalid CSS.
Correct: Number Paired With Unit
<divstyle="margin:10px;">Content</div>
Correct: Zero Margin (No Unit Needed)
<divstyle="margin:0;">Content</div>
Correct: Using a Keyword
<divstyle="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;" -->
<divstyle="margin:{{ spacing }}px;">Content</div>
To prevent this, ensure the variable contains the full value including the number, or add a fallback:
<divstyle="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
<divstyle="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
<divstyle="margin-right:10px;">Content</div>
Fixed: using zero (no unit required)
<divstyle="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
<divstyle="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:
<divstyle="margin-right:2em;">Em-based margin</div>
<divstyle="margin-right:5%;">Percentage-based margin</div>
<divstyle="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:10px20px30px40px50px;
}
❌ Missing unit on a non-zero number
.box{
margin:1020px;
}
❌ 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:10px20px;
}
/* Top, left/right, bottom */
.box{
margin:10px auto 20px;
}
/* Top, right, bottom, left */
.box{
margin:10px20px30px40px;
}
✅ 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
<divstyle="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
<divstyle="margin-top:10px;">Content</div>
Correct: using zero without a unit
<divstyle="margin-top:0;">Content</div>
Correct: using a keyword value
<divstyle="margin-top: auto;">Content</div>
Incorrect in a stylesheet
<style>
.box{
margin-top: px;
}
</style>
<divclass="box">Content</div>
Correct in a stylesheet
<style>
.box{
margin-top:16px;
}
</style>
<divclass="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: -->
<divstyle="margin-top: px;">Content</div>
Ensure the variable has a valid numeric value so the rendered CSS is complete:
<divstyle="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:
<pstyle="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:001em0;
}
</style>
In an inline style:
<pstyle="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:2px1em0 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 -->
<divstyle="margin:'1em'"></div>
<!-- ✅ Correct: only the HTML attribute is quoted -->
<divstyle="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 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()
<divstyle="mask-image: mask.png;">
Content here
</div>
Correct: image path wrapped in url()
<divstyle="mask-image:url('mask.png');">
Content here
</div>
Incorrect: typo in gradient function name
<divstyle="mask-image:linear-gradiant(to right, transparent, black);">
Content here
</div>
Correct: properly spelled gradient function
<divstyle="mask-image:linear-gradient(to right, transparent, black);">
Content here
</div>
Incorrect: missing to keyword in gradient direction
<divstyle="mask-image:linear-gradient(right, transparent, black);">
Content here
</div>
Correct: direction uses the to keyword
<divstyle="mask-image:linear-gradient(to right, transparent, black);">
Content here
</div>
Incorrect: unsupported keyword
<divstyle="mask-image: overlay;">
Content here
</div>
Correct: using none to explicitly disable masking
<divstyle="mask-image: none;">
Content here
</div>
Correct: multiple mask layers
<divstyle="mask-image:url('star.svg'),linear-gradient(to bottom, black, transparent);">
Content here
</div>
Correct: radial gradient as a mask
<divstyle="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>
<divclass="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>
<divclass="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>
<divclass="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>
<divclass="masked">Content</div>
Correct: using the longhand for mask mode
<style>
.masked{
mask-image:url(mask.png);
mask-mode: luminance;
}
</style>
<divclass="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
<divstyle="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
<divstyle="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
<divstyle="mask:url(star.svg);">
Masked Content
</div>
Correct: using none to explicitly disable masking
<divstyle="mask: none;">
No Mask Applied
</div>
Correct: using a gradient as a mask
<divstyle="mask:linear-gradient(to right, transparent, black);">
Fading Content
</div>
Correct: combining multiple shorthand values
<divstyle="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
<divstyle="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.
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
<divstyle="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:
<divstyle="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:
<divstyle="max-width:600px;">
This container will not grow beyond 600 pixels.
</div>
<divstyle="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:
<divstyle="max-width: max-content;">
This container's max width is determined by its content.
</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
<divstyle="min-height:100px200px;">Content</div>
min-height only accepts a single value. This is not a shorthand property.
Incorrect: missing unit
<divstyle="min-height:100;">Content</div>
Non-zero numeric values must include a unit.
Incorrect: invalid keyword or typo
<divstyle="min-height: inheret;">Content</div>
The keyword inherit is misspelled.
Correct: single length value
<divstyle="min-height:100px;">Content</div>
Correct: percentage value
<divstyle="min-height:50%;">Content</div>
Correct: using calc() for computed values
<divstyle="min-height:calc(100vh-80px);">Content</div>
Correct: using a keyword
<divstyle="min-height: min-content;">Content</div>
Correct: using auto
<divstyle="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:
<divstyle="min-height:100px;max-height:400px;">Content</div>
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
<pstyle="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
<pstyle="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.
The padding-block shorthand property sets padding on the block-start and block-end sides of an element. In horizontal writing modes (like English), this corresponds to the top and bottom padding; in vertical writing modes, it maps to left and right. It's the logical equivalent of combining padding-block-start and padding-block-end.
The reason auto is invalid here is that padding, by definition in the CSS specification, must resolve to a definite size. Margins can be auto because the browser uses that value in layout algorithms to distribute remaining space (e.g., centering a block element with margin-inline: auto). Padding, however, adds space inside an element's border and has no such auto-distribution behavior defined in the spec. Attempting to use auto will cause the declaration to be ignored by browsers, meaning no padding is applied, which can lead to unexpected layout results.
This validation error often arises when developers confuse padding-block with margin-block, or when they copy centering patterns that work with margins and try to apply them to padding. If your intent was to center content, consider using margin-block: auto instead, or use Flexbox/Grid alignment properties.
How to Fix
Replace auto with a valid value:
- Length values:
0,10px,1em,1.5rem, etc. - Percentage values:
5%,2% 1%, etc. (relative to the inline size of the containing block). - Two values:
padding-block: 20px 10px;setspadding-block-startto20pxandpadding-block-endto10px. - CSS-wide keywords:
inherit,initial,revert,revert-layer, orunset.
If you used auto to try to eliminate padding, use 0 instead. If you used it to try to center something, switch to margins or a layout method like Flexbox.
Examples
Incorrect: using auto as a padding-block value
<style>
.box{
padding-block: auto;
}
</style>
<divclass="box">This box has invalid padding.</div>
The browser will ignore the padding-block: auto declaration entirely, and the W3C validator will flag it as an error.
Correct: using length values
<style>
.box{
padding-block:20px10px;
}
</style>
<divclass="box">20px padding on block-start, 10px on block-end.</div>
Correct: using a single value for equal padding
<style>
.box{
padding-block:1em;
}
</style>
<divclass="box">1em padding on both block-start and block-end.</div>
Correct: removing padding with zero
<style>
.box{
padding-block:0;
}
</style>
<divclass="box">No block padding.</div>
If you intended to center: use margin-block instead
<style>
.container{
display: flex;
flex-direction: column;
height:300px;
}
.centered{
margin-block: auto;
}
</style>
<divclass="container">
<divclass="centered">This element is vertically centered using margin-block: auto.</div>
</div>
The margin-block: auto approach works inside flex or grid containers to distribute space evenly, achieving vertical centering. This is likely what you want if you originally reached for padding-block: auto.
The padding-bottom property defines the amount of space between an element's content and its bottom border. Like all CSS length properties, it expects a length value — a number paired with a unit such as px, em, rem, %, vh, etc. The lone string px is just a unit identifier with no magnitude, so CSS parsers cannot interpret it as a meaningful measurement. This typically happens when a numeric value is accidentally deleted during editing, when a CSS preprocessor or template engine outputs an empty variable before the unit, or when code is manually written with a typo.
When the browser encounters an invalid value like padding-bottom: px, it discards the entire declaration and falls back to the default or inherited value. This can lead to unexpected layout shifts, where the spacing looks correct in one browser but breaks in another depending on how defaults are applied. Fixing these errors ensures consistent rendering across browsers and keeps your stylesheets standards-compliant.
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 padding — writingpadding-bottom: 0is valid and preferred over0px. - Check template variables — if you're using a preprocessor like Sass or a templating engine, make sure the variable that generates the number is not empty or undefined.
- Remove the declaration entirely if padding-bottom is not needed, rather than leaving a broken value in place.
Examples
Incorrect: unit without a number
<divstyle="padding-bottom: px;">Content</div>
The value px alone is not valid because there is no number specifying the amount of padding.
Correct: numeric value with a unit
<divstyle="padding-bottom:10px;">Content</div>
Correct: zero padding (no unit needed)
<divstyle="padding-bottom:0;">Content</div>
Incorrect in an external stylesheet
.card{
padding-bottom: px;
}
Correct in an external stylesheet
.card{
padding-bottom:16px;
}
Common preprocessor pitfall
In Sass or similar tools, this issue often arises from an empty or undefined variable:
$spacing:null;
.card{
padding-bottom:#{$spacing}px;// Outputs "padding-bottom: px;" if $spacing is empty
}
The fix is to ensure the variable holds a valid number, or provide a fallback:
$spacing:16;
.card{
padding-bottom:#{$spacing}px;// Outputs "padding-bottom: 16px;"
}
Even better, include the unit in the variable itself to avoid concatenation issues:
$spacing:16px;
.card{
padding-bottom: $spacing;
}
An invalid value was assigned to the padding-bottom CSS property inside a style attribute, and the W3C validator rejected it.
The padding-bottom property accepts a length (e.g., 10px, 2em), a percentage (e.g., 5%), or the keyword inherit. Values like auto, bare numbers without units, or unrecognized keywords are not valid. A common mistake is writing padding-bottom: 10 instead of padding-bottom: 10px, or using a value meant for a different property.
The validator specifically checks inline styles in style attributes against CSS grammar rules. Even if a browser silently ignores the bad value, the markup is still invalid.
Invalid example
<divstyle="padding-bottom: auto;">
Content here
</div>
The value auto is not valid for padding-bottom.
Valid example
<divstyle="padding-bottom:10px;">
Content here
</div>
Use a supported value: a length with a unit (px, em, rem, %, etc.) or 0 (which does not require a unit).
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.
Pro Trial
Full Pro access. Cancel anytime.
Start Pro Trial →Join teams across 40+ countries