HTML Guides
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
The opacity property takes a number such as 0.5 or a percentage such as 50%, so a quoted value like "" is invalid.
opacity sets how transparent an element and its content are, from 0 (fully transparent) to 1 (fully opaque, the initial value). Quotes turn whatever is between them into a CSS string, and opacity doesn't accept strings. "" is an empty string, and "0.5" fails for the same reason even though the number inside it is fine. Browsers drop the declaration, so the element keeps the opacity set by other rules, or stays fully opaque.
The empty pair of quotes often comes from a template or script that wraps the value in quotes and has nothing to print, as in style='opacity: "{{ opacity }}"' when the setting is empty. Write the number without quotes, or leave the declaration out when there's no value. Any other value the property can't parse, such as the word undefined printed by a script, gets the same message.
Numbers outside the 0 to 1 range, such as 1.5, are valid: browsers clamp them to the nearest limit. Global keywords such as inherit work too.
Invalid example
<div class="banner" style='opacity: "";'>
<p>Spring offers</p>
</div>
Valid example
<div class="banner" style="opacity: 0.8;">
<p>Spring offers</p>
</div>
The orphans property only accepts a positive whole number, so a keyword such as auto or none is invalid.
orphans sets the minimum number of lines of a block that must stay at the bottom of a page or column when the browser splits it. The default is 2. The property has no keywords besides the global ones (inherit, initial, unset), so browsers drop a declaration like orphans: auto and keep the value that would apply without it.
The property mostly matters in print styles and multi-column layouts. Its counterpart widows sets the minimum number of lines at the top of the next page or column, and takes the same kind of value.
Replace the keyword with a number such as 2 or 3, or remove the declaration to keep the default. The value must be an integer of at least 1: 0 and decimals such as 1.5 get their own validator errors.
Invalid example
<style>
p {
orphans: auto;
}
</style>
Valid example
<style>
p {
orphans: 3;
}
</style>
The overflow-y property accepts only the keywords visible, hidden, clip, scroll and auto, so the old overlay keyword, like any other value, is rejected.
overlay started as a WebKit value that drew the scrollbar on top of the content instead of reserving room for it beside the content. It never became part of the standard. The CSS Overflow specification keeps it only as a legacy alias of auto: browsers must still accept it, but they treat it exactly like auto, and it isn't a value authors are meant to write. The validator reports other values it doesn't recognize in the same way, such as none, which belongs to other properties, or a typo like scrol.
Replace overlay with auto. The scrollbar then appears only when the content is taller than the box, which is what browsers already do with overlay, so the page looks the same. No standard value makes the scrollbar float over the content. Whether scrollbars sit on top of the content or take up space beside it is up to the browser and the operating system.
Keeping overflow-y: overlay after an overflow-y: auto fallback in the same rule doesn't help either. The validator still reports the overlay declaration, and in browsers that follow the specification it changes nothing.
Invalid example
<style>
.message-list {
max-height: 20rem;
overflow-y: overlay;
}
</style>
<div class="message-list">
<p>Your order has shipped.</p>
<p>Your invoice is ready.</p>
</div>
Valid example
<style>
.message-list {
max-height: 20rem;
overflow-y: auto;
}
</style>
<div class="message-list">
<p>Your order has shipped.</p>
<p>Your invoice is ready.</p>
</div>
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>
<div class="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: 20px 10px;
}
</style>
<div class="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>
<div class="box">1em padding on both block-start and block-end.</div>
Correct: removing padding with zero
<style>
.box {
padding-block: 0;
}
</style>
<div class="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>
<div class="container">
<div class="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
<div style="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
<div style="padding-bottom: 10px;">Content</div>
Correct: zero padding (no unit needed)
<div style="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
<div style="padding-bottom: auto;">
Content here
</div>
The value auto is not valid for padding-bottom.
Valid example
<div style="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).
A padding-bottom declaration has a negative value, and padding can't be less than zero.
Bottom padding is the space between the bottom of an element's content and its bottom border, so CSS only accepts zero or a positive length or percentage for it. A browser drops a padding-bottom declaration with a negative value, and the element keeps whatever bottom padding it gets from other rules. Adding !important doesn't change that: the declaration is still invalid, and the validator still reports it.
A negative bottom padding is usually an attempt to pull the next element up, or to make it overlap the bottom of this one. A negative margin-bottom does that, and CSS allows it. To fix the error, set padding-bottom to 0 or a positive length, and move the negative value to margin-bottom if you still need the overlap. The padding shorthand and the other side properties follow the same rule, and each one has its own message.
Invalid example
<div class="banner" style="padding-bottom: -20px;">
Banner content
</div>
<p>The next paragraph starts here.</p>
Valid example
<div class="banner" style="padding-bottom: 0; margin-bottom: -20px;">
Banner content
</div>
<p>The next paragraph starts here.</p>
The padding-left property accepts a valid CSS length value, a percentage, or the keyword 0. A CSS length is always composed of two parts: a number and a unit (e.g., 10px, 2em, 1.5rem). Writing just px with no number is syntactically invalid — it's a bare unit with no magnitude, so the browser cannot determine what spacing to apply. This commonly occurs due to a typo, a missing variable in a template or preprocessor, or accidentally deleting the numeric portion during editing.
When the validator encounters this in a style attribute, it flags the value as invalid CSS. While most browsers will simply ignore the malformed declaration and fall back to the default padding, relying on this error-recovery behavior leads to unpredictable layouts. Fixing the issue ensures your styles are applied consistently across all browsers and that your markup passes validation.
How to fix it
- Add a numeric value before the unit: change
pxto something like10px,1em, or5%. - If you want zero padding, use
0— no unit is needed (though0pxis also valid). - Check template variables and preprocessors. If you're using a system like PHP, JavaScript templating, or a CSS preprocessor (Sass, Less), make sure the variable that should supply the number isn't empty or undefined. For example,
padding-left: <?= $indent ?>px;will producepadding-left: px;if$indentis empty.
Examples
Incorrect: bare unit with no number
<div style="padding-left: px;">Content</div>
The value px has no numeric component, so it is not a valid length.
Correct: numeric value before the unit
<div style="padding-left: 10px;">Content</div>
Correct: zero padding (no unit required)
<div style="padding-left: 0;">Content</div>
Incorrect: empty variable producing a bare unit
This is a common source of the bug in templated or dynamically generated HTML:
<!-- If the variable is empty, this renders as "padding-left: px;" -->
<div style="padding-left: px;">Content</div>
Correct: ensuring a fallback value
When generating styles dynamically, always provide a sensible default so the output is valid even if the variable is missing:
<div style="padding-left: 16px;">Content</div>
Using an external stylesheet
The same rule applies in external or embedded CSS. The incorrect version:
.sidebar {
padding-left: px;
}
The corrected version with a proper numeric value:
.sidebar {
padding-left: 20px;
}
Other valid padding-left values
Any valid CSS length or percentage works:
<div style="padding-left: 2em;">Em-based padding</div>
<div style="padding-left: 1.5rem;">Rem-based padding</div>
<div style="padding-left: 5%;">Percentage-based padding</div>
A padding-left declaration has a negative value, and padding can't be less than zero.
Left padding is the space between an element's left border and its content, so CSS only accepts zero or a positive length or percentage for it. A browser drops a padding-left declaration with a negative value, and the element keeps whatever left padding it gets from other rules. On a list, that means the default indentation stays where it was.
To fix the error, change the value to 0 or a positive length. Setting padding-left: 0 removes the indentation a list gets by default. If the content has to move past the left edge of its container, use a negative margin-left, which CSS allows. The padding shorthand and the other side properties follow the same rule, and each one has its own message.
Invalid example
<ul class="links" style="padding-left: -20px;">
<li>First link</li>
<li>Second link</li>
</ul>
Valid example
<ul class="links" style="padding-left: 0;">
<li>First link</li>
<li>Second link</li>
</ul>
The padding shorthand property sets the padding area on all four sides of an element. It accepts one to four values, each of which must be a <length> (e.g., 10px, 1em), a <percentage>, or 0. Unlike some other CSS properties such as border, outline, or max-width, the padding property has no none keyword in its value syntax.
This is a common mistake because several CSS properties do accept none — for example, border: none, text-decoration: none, and display: none. It's natural to assume padding: none would work the same way, but the CSS specification simply doesn't define it for padding. When a browser encounters an invalid value, it ignores the declaration entirely, which means your intended styling won't be applied and the element may retain its default or inherited padding. This can lead to unexpected layout issues that are difficult to debug.
The same rule applies to the margin property — margin: none is also invalid. Use margin: 0 instead.
How to Fix It
Replace none with 0. You don't need to include a unit when the value is zero, so padding: 0 is perfectly valid and is the idiomatic way to express "no padding." You can also use 0 for individual padding properties like padding-top, padding-right, padding-bottom, and padding-left.
If you only want to remove padding on specific sides, target those sides individually rather than using the shorthand.
Examples
❌ Incorrect: Using none with padding
.card {
padding: none;
}
The validator will report: CSS: "padding": "none" is not a "padding" value. The browser will ignore this declaration.
✅ Correct: Using 0 to remove padding
.card {
padding: 0;
}
✅ Correct: Removing padding on specific sides
.card {
padding-top: 0;
padding-bottom: 0;
}
❌ Incorrect: Using none in inline styles
<div style="padding: none;">Content</div>
✅ Correct: Using 0 in inline styles
<div style="padding: 0;">Content</div>
✅ Correct: Using valid padding values
/* Single value — applies to all four sides */
.card {
padding: 16px;
}
/* Two values — vertical | horizontal */
.card {
padding: 10px 20px;
}
/* Four values — top | right | bottom | left */
.card {
padding: 10px 20px 15px 5px;
}
/* Zero on top/bottom, 1em on left/right */
.card {
padding: 0 1em;
}
The padding property accepts one or more length values, percentages, or the keyword 0. A valid length value always consists of a number immediately followed by a unit identifier, such as 10px, 1.5em, or 2rem. Writing just px without a preceding number is meaningless to the CSS parser — it's like saying "pixels" without specifying how many. The browser will discard the invalid declaration entirely, which means the element will fall back to its default or inherited padding, potentially breaking your layout in unexpected ways.
This error commonly occurs due to:
- Typos or accidental deletion — the numeric part of the value was inadvertently removed during editing.
- Templating or build tool issues — a dynamic value (e.g., from a variable or CMS field) resolved to an empty string, leaving only the
pxsuffix behind. - Copy-paste mistakes — copying a snippet and forgetting to update the placeholder value.
Because the W3C validator flags this in inline style attributes, it means invalid CSS is embedded directly in your HTML. Fixing it improves standards compliance and ensures consistent rendering across browsers.
How to Fix
- Add a numeric value before the unit: change
pxto something like10px,1em, or5%. - Use
0without a unit if you want zero padding — writingpadding: 0;is valid and preferred overpadding: 0px;. - Check dynamic values — if the number comes from a variable or template expression, make sure it outputs a valid number and isn't empty.
Examples
Incorrect: Unit Without a Number
<div style="padding: px;">Content</div>
The validator reports that px is not a valid padding value because no number precedes the unit.
Correct: Numeric Value With Unit
<div style="padding: 10px;">Content</div>
Correct: Zero Padding (No Unit Needed)
<div style="padding: 0;">Content</div>
When the value is 0, no unit is required since zero pixels, zero ems, and zero percent are all identical.
Correct: Multiple Padding Values
<div style="padding: 8px 16px;">Content</div>
This sets 8px of vertical padding and 16px of horizontal padding — both are valid length values.
Incorrect in External CSS
The same problem can appear in a stylesheet linked from your HTML:
.card {
padding: px;
}
Fixed in External CSS
.card {
padding: 12px;
}
Watch for Template-Generated Values
If you use a templating system, double-check that the numeric portion actually renders. For example, a template like this could produce the error if spacing is empty:
<!-- If spacing is empty, this becomes "padding: px;" -->
<div style="padding: {{ spacing }}px;">Content</div>
Make sure the variable always resolves to a valid number, or provide a fallback value.
The padding-right property defines the space between an element's content and its right border. According to the CSS Box Model specification, padding represents internal space within an element, and conceptually, negative internal space doesn't make sense — you can't have less than zero space between content and its border. This rule applies equally to all padding properties: padding-top, padding-right, padding-bottom, padding-left, and the padding shorthand.
Browsers will typically ignore or discard a negative padding value, meaning your intended layout adjustment won't take effect. Beyond simply being invalid CSS, this can lead to inconsistent rendering across browsers and unexpected layout behavior. Relying on invalid values makes your stylesheets fragile and harder to maintain.
If your goal is to pull an element closer to its neighbor or create an overlapping effect, margin-right is the appropriate property to use. Unlike padding, margins are explicitly allowed to have negative values. Negative margins reduce the space between elements or even cause them to overlap, which is often the actual intent behind a negative padding attempt.
How to Fix
- Set the value to
0or a positive number. If you simply want no padding, use0. If you need some spacing, use a positive value. - Use
margin-rightfor negative spacing. If you need to reduce external space or create overlap, switch to a negative margin instead. - Re-evaluate your layout approach. In some cases, using
transform: translateX(), Flexboxgap, or Grid layout may achieve the desired result more cleanly than negative values on any property.
Examples
Incorrect: negative padding value
<style>
.sidebar {
padding-right: -10px;
}
</style>
<div class="sidebar">
<p>Sidebar content</p>
</div>
This triggers the validator error because -10px is not a valid value for padding-right.
Fixed: using zero or a positive value
<style>
.sidebar {
padding-right: 0;
}
</style>
<div class="sidebar">
<p>Sidebar content</p>
</div>
Fixed: using a negative margin instead
If the intent was to reduce external spacing on the right side, use margin-right:
<style>
.sidebar {
padding-right: 0;
margin-right: -10px;
}
</style>
<div class="sidebar">
<p>Sidebar content</p>
</div>
Fixed: using transform for visual offset
If the goal is to visually shift the element without affecting document flow, transform is another option:
<style>
.sidebar {
padding-right: 0;
transform: translateX(10px);
}
</style>
<div class="sidebar">
<p>Sidebar content</p>
</div>
Quick reference: padding vs. margin
| Property | Negative values allowed? | Purpose |
|---|---|---|
padding-right | No | Space between content and border |
margin-right | Yes | Space between the element's border and surrounding elements |
Choose the property that matches your layout intent, and remember that all four padding directions — padding-top, padding-right, padding-bottom, and padding-left — follow the same non-negative rule.
The padding-right property defines the amount of space between an element's content and its right border. Like all CSS length properties, it expects either a valid length value (a number paired with a unit like px, em, rem, %, vw, etc.), the keyword 0 (which needs no unit), or the keyword inherit/initial/unset. A bare unit such as px with no number is meaningless — it doesn't tell the browser how much padding to apply.
This error typically occurs due to a typo, a templating issue where a variable failed to render, or accidental deletion of the numeric portion of the value. For example, a template like padding-right: {{ value }}px; might produce padding-right: px; if value is empty or undefined.
When the browser encounters an invalid value like px, it discards the entire declaration and falls back to the default or inherited value for padding-right. This can lead to unexpected layout differences across browsers and makes your intentions unclear to other developers. Fixing these validation errors also helps maintain clean, predictable stylesheets.
How to Fix
- Add the missing number before the unit: change
pxto a specific value like10px. - Use
0without a unit if you want no padding:padding-right: 0;is valid and preferred overpadding-right: 0px;. - Check template variables and dynamic style generation to ensure numeric values are always output correctly.
Examples
Incorrect: bare unit with no number
<div style="padding-right: px;">Content</div>
The value px is not valid because it lacks a numeric component.
Correct: numeric value with unit
<div style="padding-right: 10px;">Content</div>
Correct: zero padding (no unit needed)
<div style="padding-right: 0;">Content</div>
Correct: using other valid units
<div style="padding-right: 2em;">Content</div>
<div style="padding-right: 5%;">Content</div>
Incorrect in an external stylesheet
.sidebar {
padding-right: px;
}
Fixed in an external stylesheet
.sidebar {
padding-right: 16px;
}
Guarding against empty values in templates
If you generate CSS dynamically, make sure the numeric value is always present. For instance, provide a fallback:
.sidebar {
padding-right: 16px; /* safe default */
}
Rather than relying on a template that might produce an empty value, consider setting defaults in your CSS and only overriding with inline styles when you're certain the value is valid.
A math function in the padding value, such as calc(), min(), max() or clamp(), combines values whose types don't match, most often a length and a number with no unit.
padding is a shorthand that takes one to four values, for the top, right, bottom and left sides. Each value is a length like 16px or 1rem, or a percentage, so a math function in any of those positions has to work out to a length or a percentage. The validator checks every position, and 1rem calc(1rem + 2) fails just like calc(1rem + 2) on its own. The message only names padding, so it won't tell you which side has the problem. Check each value in the declaration.
Addition and subtraction inside calc() only work between values of the same type. calc(1rem + 2px) adds two lengths, while calc(1rem + 2) adds a bare number to a length, which CSS can't compute. min(), max() and clamp() apply the same rule to their arguments, so max(16px, 2) and clamp(1rem, 5vw, 3) each mix a length with a number. Multiplying or dividing by a plain number is fine, because the number only scales the other value: calc(2 * 1rem) is valid.
A common source is side padding worked out from a fixed content width, such as calc((100vw - 1200) / 2), with the unit left off the width. Writing 1200px fixes it.
Browsers drop a declaration whose expression has the wrong type. Because padding sets all four sides at once, a mistake in one value throws away the other three as well. The element keeps the padding from earlier rules, or the initial 0.
The validator doesn't catch every case. It lets calc(5% + 2) and max(5%, 2) through, although browsers reject both. It also accepts calc(1rem + 0), but inside a math function a bare 0 counts as a number, so browsers drop that one too. Expressions that use var() pass whatever the variable holds.
Invalid example
<style>
.section {
padding: calc(1rem + 2) 1rem;
}
.card {
padding: 1rem 1.5rem max(16px, 2);
}
</style>
Valid example
<style>
.section {
padding: calc(1rem + 2px) 1rem;
}
.card {
padding: 1rem 1.5rem max(16px, 2vw);
}
</style>
The W3C validator reports this error when it encounters padding-top: px; — a unit with no numeric component. In CSS, length values are composed of two parts: a number and a unit identifier (e.g., px, em, rem, %, vh). The unit alone is meaningless without a number to quantify it. This typically happens due to a typo, a preprocessor variable that resolved to an empty value, or accidentally deleting the number during editing.
This matters for several reasons. Browsers will discard the invalid declaration entirely, meaning padding-top will fall back to its default or inherited value — which may not be what you intended. This can cause unpredictable layout differences across browsers. Additionally, invalid CSS can interfere with parsing of subsequent declarations in the same rule block, potentially causing other styles to be ignored as well.
To fix this issue:
- Add a numeric value before the unit: change
pxto something like10px,1.5em, or20%. - Use
0without a unit if you want zero padding:padding-top: 0;is valid and preferred overpadding-top: 0px;. - Check preprocessor variables (Sass, Less, etc.) to make sure they resolve to complete values, not just units.
- Remove the declaration entirely if padding-top doesn't need to be set.
Examples
Incorrect: unit without a number
<div style="padding-top: px;">Content</div>
The value px is not a valid padding-top value because it lacks a numeric component.
Correct: number with a unit
<div style="padding-top: 10px;">Content</div>
Correct: zero padding (no unit needed)
<div style="padding-top: 0;">Content</div>
Incorrect in an external stylesheet
.header {
padding-top: px;
}
Correct in an external stylesheet
.header {
padding-top: 16px;
}
Common preprocessor pitfall
If you use a CSS preprocessor like Sass, watch out for variables that might be empty or undefined:
/* If $spacing somehow resolves to empty, this produces "padding-top: px;" */
.card {
padding-top: $spacing + px;
}
/* Safer approach — define the variable with the full value */
.card {
padding-top: $spacing; /* where $spacing: 16px; */
}
Any valid CSS length value will work for padding-top, including px, em, rem, %, vw, vh, ch, and others — as long as a number precedes the unit. The only length value that doesn't require a unit is 0.
Unlike margin properties, which accept negative values to pull elements closer together or overlap them, all padding properties (padding-top, padding-right, padding-bottom, padding-left, and the padding shorthand) are defined in the CSS specification to only accept zero or positive lengths. This is because padding represents the space inside an element between its content and its border — a negative internal space is not a meaningful concept.
When you use a negative padding value, browsers will typically ignore the declaration entirely, meaning your layout may not look the way you intended. The W3C validator catches this to help you identify code that won't behave consistently across browsers and doesn't conform to the CSS specification.
If your goal is to reduce the space between elements, negative margin values are the correct tool. If you're trying to shift content upward within a container, consider using position: relative with a negative top offset, or adjust the layout with other techniques like transform: translateY().
Examples
❌ Invalid: negative padding value
<div style="padding-top: -20px;">
This element has invalid negative padding.
</div>
The validator will report: CSS: "padding-top": "-20" negative values are not allowed.
✅ Fixed: using zero or positive padding
<div style="padding-top: 0;">
This element has no top padding.
</div>
<div style="padding-top: 10px;">
This element has valid positive top padding.
</div>
✅ Alternative: using negative margin instead
If you need to reduce the space above an element, use a negative margin-top:
<div style="margin-top: -20px;">
This element is pulled upward with a negative margin.
</div>
❌ Invalid: negative values in the padding shorthand
The same rule applies to the padding shorthand property. Any negative component value is invalid:
<div style="padding: -10px 20px 15px 20px;">
Invalid shorthand padding.
</div>
✅ Fixed: all-positive shorthand values
<div style="padding: 0 20px 15px 20px;">
Valid shorthand padding with zero top padding.
</div>
✅ Alternative: using transform for visual offset
If you need to visually shift an element's content upward without affecting layout flow, transform is a clean option:
<div style="transform: translateY(-20px);">
This element appears shifted upward.
</div>
A calc() expression in padding-top, padding-right, padding-bottom or padding-left has a unit with no number in front of it, such as px where 24px was meant.
Inside calc(), the validator expects a number in front of every unit. When it finds a letter where the number should be, it names that letter in the message: calc(px + 1rem) reports "Character p", and calc(rem + 4px) reports "Character r". Outside calc(), a bare px gets a different message, which says px is not a valid padding-top value.
The usual cause is a template or build step that writes a number from a variable into the CSS. If the variable is empty, calc({{ spacing }}px + 1rem) comes out as calc(px + 1rem). Browsers discard the whole declaration, so the element keeps the padding it would have without that rule.
To fix it, put the number back in front of the unit, or make sure the variable always has a value. When the value comes from a custom property, give var() a fallback, as in calc(var(--banner-space, 0px) + 1rem). If the value can be zero, write 0px and not 0: inside calc() a unitless 0 is a number, and a number can't be added to a length.
Invalid example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Banner</title>
<style>
.banner {
padding-top: calc(px + 1rem);
padding-bottom: calc(px + 1rem);
}
</style>
</head>
<body>
<div class="banner">Welcome</div>
</body>
</html>
Valid example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Banner</title>
<style>
.banner {
padding-top: calc(24px + 1rem);
padding-bottom: calc(24px + 1rem);
}
</style>
</head>
<body>
<div class="banner">Welcome</div>
</body>
</html>
The values of the padding property are separated by spaces, not commas: write padding: 10px 20px, not padding: 10px, 20px.
padding is a shorthand that takes one to four lengths or percentages. One value applies to all four sides. Two values set the top and bottom, then the left and right. Three set the top, then left and right, then the bottom. Four go clockwise from the top: top, right, bottom, left.
In CSS a comma separates the items of a list, such as the fonts in font-family or the layers in box-shadow. padding doesn't take a list, so the validator reports the comma as an incorrect operator. Browsers drop the whole declaration, and the element keeps whatever padding an earlier rule gave it, or none. The habit often comes from JavaScript, or from CSS functions like rgb(255, 0, 0) where commas separate the arguments.
Invalid example
<div style="padding: 10px, 20px;">
<p>Card content</p>
</div>
Valid example
<div style="padding: 10px 20px;">
<p>Card content</p>
</div>
A CSS padding property contains a value the validator does not recognize as valid for that property.
The padding shorthand and its longhand variants (padding-top, padding-right, padding-bottom, padding-left) accept only <length>, <percentage>, or the keyword auto (in some contexts). Common causes of this error include:
- Using an invalid unit or misspelling a unit, such as
10xpinstead of10px. - Omitting the unit on a non-zero value, such as
padding: 10instead ofpadding: 10px. - Passing a color, keyword, or other unrelated value, such as
padding: redorpadding: bold. - Including extra or misplaced values from a copy-paste error, such as
padding: 10px 20px 30px 40px 50px(five values instead of the maximum four). - Using CSS custom properties or newer syntax in an inline
styleattribute that the validator's CSS parser does not yet support.
The padding shorthand accepts one to four values, corresponding to the top, right, bottom, and left sides. Each value must be a non-negative length (like 0, 8px, 1em, 2rem) or a percentage.
HTML examples
Invalid padding value
<div style="padding: 10xp;">Content</div>
Fixed padding value
<div style="padding: 10px;">Content</div>
A padding declaration has a negative value, and padding can't be less than zero.
Padding is the space between an element's content and its border, so CSS only accepts zero or a positive length or percentage for it. A browser drops any padding declaration with a negative value, and the element keeps whatever padding it gets from other rules.
The shorthand takes one to four values, and any of them can be the negative one. In padding: 16px -8px, the left and right padding are -8px, so the validator reports that value. When a declaration has more than one negative value, the message only quotes the first, so check every value in it. The padding-top, padding-right, padding-bottom and padding-left properties follow the same rule, and each one has its own message.
To fix the error, change each negative value to 0 or a positive length. If the negative value was meant to pull the element closer to its neighbors, or past the edges of its container, use a negative margin instead, which CSS allows.
Invalid example
<div class="card" style="padding: 16px -8px;">
Card content
</div>
Valid example
<div class="card" style="padding: 16px 0; margin: 0 -8px;">
Card content
</div>
A CSS parse error means the validator's CSS parser encountered something unexpected and could not make sense of the code from that point forward. Unlike many HTML errors that pinpoint a specific rule violation, a parse error is more general — the parser simply gave up trying to interpret the CSS. This can sometimes cause a cascade of additional errors, since the parser may lose track of context after the initial failure.
This matters because browsers handle broken CSS unpredictably. While most browsers are forgiving and will skip invalid rules, the way they recover varies. Styles may render differently across browsers, or entire rule blocks may be silently ignored. Valid CSS ensures consistent rendering, easier debugging, and better maintainability.
Common causes of CSS parse errors include:
- Missing semicolons between declarations
- Unclosed curly braces
{or extra closing braces} - Unclosed comments (
/*without a matching*/) - Invalid or empty property values (e.g.,
color: ;) - Unexpected characters such as stray text, unsupported tokens, or HTML markup inside
<style>blocks - Typos in property names or values (e.g.,
colr: red) - Using CSS syntax that isn't valid in an attribute context, such as placing selectors inside a
styleattribute
To fix the error, go to the line indicated by the validator and carefully inspect the CSS around that point. Look for the common issues listed above. Sometimes the actual mistake is on a line before the reported one — for example, a missing semicolon on line 5 might only cause a parse error on line 6.
Examples
Missing semicolon
A missing semicolon causes the parser to misinterpret where one declaration ends and the next begins.
❌ Incorrect:
<p style="color: red font-size: 16px">Hello</p>
✅ Fixed:
<p style="color: red; font-size: 16px">Hello</p>
Unclosed curly brace
A missing closing brace causes the parser to treat subsequent rules as part of the unclosed block.
❌ Incorrect:
<style>
.container {
margin: 0 auto;
padding: 20px;
.title {
font-size: 24px;
}
</style>
✅ Fixed:
<style>
.container {
margin: 0 auto;
padding: 20px;
}
.title {
font-size: 24px;
}
</style>
Unclosed comment
A comment that is never closed causes everything after it to be consumed by the parser as part of the comment.
❌ Incorrect:
<style>
/* Set the main color
body {
color: #333;
}
</style>
✅ Fixed:
<style>
/* Set the main color */
body {
color: #333;
}
</style>
Empty or invalid property value
Declaring a property with no value or a clearly invalid value triggers a parse error.
❌ Incorrect:
<div style="background-color: ;">Content</div>
✅ Fixed:
<div style="background-color: #f0f0f0;">Content</div>
Selectors inside an inline style attribute
The style attribute only accepts declarations (property-value pairs), not selectors or full rule blocks.
❌ Incorrect:
<div style="p { color: blue; }">Content</div>
✅ Fixed:
<div style="color: blue;">Content</div>
Stray characters or typos
Unexpected characters anywhere in CSS will cause parsing to fail.
❌ Incorrect:
<style>
.box {
width: 100px;;
height: 50px
border: 1px solid #ccc;
}
</style>
While a double semicolon (;;) is technically harmless in most parsers, a missing semicolon after height: 50px merges it with the next line, producing an invalid value.
✅ Fixed:
<style>
.box {
width: 100px;
height: 50px;
border: 1px solid #ccc;
}
</style>
If the validator points to a line but the cause isn't obvious, try isolating sections of your CSS and validating them separately using the W3C CSS Validation Service. This can help narrow down the exact location of the problem.
The CSS perspective property does not accept 0 as a valid value. It must be either none or a positive length greater than zero.
The perspective property defines the distance between the viewer and the z=0 plane, which determines the intensity of 3D effects on child elements. A value of 0 is mathematically undefined (it would place the viewer directly on the plane), so the specification rejects it. If the goal is to remove perspective entirely, use none. If the goal is a very strong perspective effect, use a small positive value like 1px.
The property applies to the element's children, not the element itself. A smaller value creates a more dramatic 3D effect, while a larger value creates a subtler one.
Invalid example
<div style="perspective: 0;">
<div style="transform: rotateY(45deg);">Content</div>
</div>
Valid examples
To disable perspective:
<div style="perspective: none;">
<div style="transform: rotateY(45deg);">Content</div>
</div>
To apply a strong (but valid) perspective:
<div style="perspective: 1px;">
<div style="transform: rotateY(45deg);">Content</div>
</div>
The pointer-events CSS property controls whether an element can be the target of pointer events such as clicks, taps, and hover states. Unlike many other CSS properties that accept normal as a keyword (e.g., white-space, letter-spacing), the pointer-events property does not include normal in its list of valid values. This is a common mistake since normal and auto are often used interchangeably across different CSS properties, but each property defines its own set of accepted keywords.
Using an invalid value like normal means the browser will ignore the entire declaration. In most cases this won't cause visible breakage because the default behavior already allows pointer interaction, but it can lead to unexpected results if you're relying on the property to override an inherited pointer-events: none from a parent element. The invalid declaration would simply be discarded, and the inherited none value would remain in effect, making the element unclickable.
For standard HTML elements, the two primary values you'll use are:
auto— The element behaves as it normally would regarding pointer events. This is the default.none— The element is never the target of pointer events. Clicks and hovers pass through to whatever is behind it.
Several additional values exist (visiblePainted, visibleFill, visibleStroke, visible, painted, fill, stroke, all) but these only apply to SVG elements. Global CSS keywords like inherit, initial, unset, and revert are also valid.
To fix the issue, replace normal with auto wherever it appears as a pointer-events value. If you're using pointer-events: normal to restore default interactivity after a parent set pointer-events: none, then auto is exactly what you need.
Examples
Incorrect — using normal
<div style="pointer-events: normal;">
<a href="/about">About us</a>
</div>
The validator will flag normal as an invalid value for pointer-events.
Correct — using auto
<div style="pointer-events: auto;">
<a href="/about">About us</a>
</div>
Practical use case: restoring pointer events on a child
A common pattern is disabling pointer events on a parent and re-enabling them on a specific child. Using normal here would silently fail, leaving the button unclickable:
<!-- Incorrect -->
<style>
.overlay {
pointer-events: none;
}
.overlay .close-btn {
pointer-events: normal; /* Invalid — button remains unclickable */
}
</style>
<div class="overlay">
<button class="close-btn">Close</button>
</div>
<!-- Correct -->
<style>
.overlay {
pointer-events: none;
}
.overlay .close-btn {
pointer-events: auto; /* Valid — button is clickable again */
}
</style>
<div class="overlay">
<button class="close-btn">Close</button>
</div>
In the incorrect version, the browser discards the invalid pointer-events: normal declaration entirely, so the .close-btn inherits none from the parent and cannot be clicked. Changing it to auto correctly restores interactivity on the button.
The position property accepts only the keywords static, relative, absolute, fixed and sticky, written without quotes, so a quoted value such as "absolute" is rejected.
Quotation marks turn a CSS value into a string. "absolute" is a string that contains the word absolute, not the absolute keyword, and position has no string values. Quoted keywords usually come from a template or script that writes the CSS and wraps every value in quotes, the way JavaScript and JSON write strings. The validator reports any other value it doesn't recognize in the same way, such as the typo absolut or center borrowed from another property.
Browsers drop a declaration whose value they can't parse. The element keeps the position it would otherwise have, usually static, and top, right, bottom and left have no effect on it. A badge meant to sit in the corner of a card stays in the normal flow instead. If only the parent's position: "relative" is quoted, its absolutely positioned children are placed against the nearest positioned ancestor further up the page, or the page itself, rather than the parent.
Remove the quotes so the value is the bare keyword. The global keywords inherit, initial, unset and revert also work, and they don't take quotes either. When a template or script generates the CSS, fix the code that writes it, since a hand edit to the output won't survive the next build.
Invalid example
<style>
.card {
position: "relative";
}
.card-badge {
position: "absolute";
top: 0;
right: 0;
}
</style>
<div class="card">
<img src="shoe.jpg" alt="Trail running shoe">
<span class="card-badge">New</span>
</div>
Valid example
<style>
.card {
position: relative;
}
.card-badge {
position: absolute;
top: 0;
right: 0;
}
</style>
<div class="card">
<img src="shoe.jpg" alt="Trail running shoe">
<span class="card-badge">New</span>
</div>
In CSS, a length value is composed of two parts: a number and a unit. Writing just px provides the unit but omits the number, which makes the declaration invalid. The CSS parser cannot interpret px alone as a meaningful measurement, so the property is ignored entirely. This means your intended layout won't be applied, potentially causing elements to render at unexpected sizes across different browsers.
This error commonly arises from typos, copy-paste mistakes, or templating issues where a variable that should output a number resolves to an empty string, leaving behind only the unit suffix. It can also happen when a numeric value is accidentally deleted during editing.
Beyond layout breakdowns, invalid CSS can cause inconsistent rendering across browsers. Some browsers may silently discard the invalid declaration, while others might apply unexpected fallback behavior. Keeping your CSS valid ensures predictable, cross-browser results and makes your stylesheets easier to maintain and debug.
How to Fix It
- Add the missing numeric value — Pair every unit with a number, e.g.,
300px,1.5em,50%. - Use
0without a unit for zero values — The value0is valid on its own and doesn't require a unit. - Use a valid keyword — Properties like
widthaccept keywords such asauto,min-content,max-content, andfit-content. - Check dynamic values — If a preprocessor or template engine generates the value, verify it outputs a complete length (e.g.,
${value}pxwherevalueis not empty).
Examples
Incorrect: unit without a number
<style>
.box {
width: px;
}
</style>
<div class="box">Content</div>
The declaration width: px is invalid because px alone is not a recognized CSS value. The browser will discard this rule.
Incorrect: number without a unit
<style>
.box {
width: 300;
}
</style>
<div class="box">Content</div>
A unitless number (other than 0) is also invalid for the width property. Browsers will ignore this declaration as well.
Correct: number paired with a unit
<style>
.box {
width: 300px;
}
</style>
<div class="box">Content</div>
Correct: using different valid length units
<style>
.box-a {
width: 50%;
}
.box-b {
width: 20em;
}
.box-c {
width: 15rem;
}
.box-d {
width: 80vw;
}
</style>
Correct: zero value and keywords
<style>
.collapsed {
width: 0;
}
.flexible {
width: auto;
}
.intrinsic {
width: fit-content;
}
</style>
The value 0 is the only number that doesn't require a unit in CSS. Keywords like auto, min-content, max-content, and fit-content are also valid for width and don't use numeric lengths at all.
Common CSS Length Units
| Unit | Description |
|---|---|
px | Pixels (absolute unit) |
em | Relative to the element's font size |
rem | Relative to the root element's font size |
% | Percentage of the containing block's dimension |
vw | 1% of the viewport width |
vh | 1% of the viewport height |
ch | Width of the "0" character in the element's font |
Always double-check that your CSS length values include both a number and a unit. If you're generating styles dynamically, add safeguards to ensure the numeric portion is never empty before the unit is appended.
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