HTML Guides for length
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 position in the background shorthand is a plain number like 10, and CSS only accepts a number without a unit when it is 0.
In background: url(banner.png) no-repeat 10 20, the two numbers set background-position, which takes lengths such as 10px or 1.5em, percentages, or keywords like left and center. CSS has no default unit, so 10 alone is not a length. Browsers ignore the whole declaration, and the element loses its background color and image along with the position.
The bare number often comes from a template or CMS setting that prints an offset without px, or from a value copied out of a design tool. Add the unit you meant, or switch to a percentage or keyword. 0 is the one number that is valid on its own, because zero is the same length in every unit.
The validator words two close cases differently. A unitless size after the slash, as in center / 100 auto, is reported as a "unit" error instead of a "length" one. A unitless number that comes second, after a valid first position such as 10px 20, is reported as not being a background value. Adding the unit fixes both.
Invalid example
<div style="background: url(banner.png) no-repeat 10 20;">
<p>Summer sale</p>
</div>
Valid example
<div style="background: url(banner.png) no-repeat 10px 20px;">
<p>Summer sale</p>
</div>
The background-position property has a number without a unit, such as 20, and CSS only accepts a unitless number as a length when it is 0.
background-position places a background image inside its element. Each offset is a length such as 20px or 1.5em, a percentage, or a keyword like left or center. CSS has no default unit, so 20 alone is not a length. One bare number triggers the error even next to a valid value: right 20 and 50% 20 both fail.
Browsers in standards mode drop the declaration. The image then sits at the default position, the top left corner, or wherever an earlier rule put it.
The bare number often comes from a theme or page builder setting that prints an offset without px, or from a template that outputs a calculated number alone. Add the unit you meant. 0 is the one number that is valid without a unit, because zero is the same length in every unit.
Invalid example
<div style="background-image: url(hills.jpg); background-position: right 20;">
<p>Welcome to the valley</p>
</div>
Valid example
<div style="background-image: url(hills.jpg); background-position: right 20px;">
<p>Welcome to the valley</p>
</div>
A max-width declaration has the unit px with no number in front of it, so the browser can't read it as a length.
A CSS length is a number followed by a unit, written together: 600px, 40rem, 75ch. The unit alone means nothing. Browsers drop the invalid declaration, so the element falls back to max-width: none and can grow wider than you intended.
The cause is usually a template that prints a number variable right before a hard-coded px. When the variable is empty, the output is max-width: px;. Make sure the variable always holds a number, or leave the declaration out when there's no value. If you want no limit at all, use none.
The number and the unit can't be separated by a space either. max-width: 600 px; triggers a different validator error, "Too many values or values are not recognized".
Invalid example
<div style="max-width: px;">
<p>This text block has no width limit.</p>
</div>
Valid example
<div style="max-width: 600px;">
<p>This text block stops growing at 600 pixels.</p>
</div>
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