About This HTML Issue
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)
<div style="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)
<div style="position: absolute; left: 10xn;">
Positioned element
</div>
Fixed with a valid length unit
<div style="position: absolute; left: 10px;">
Positioned element
</div>
Fixed with a percentage
<div style="position: absolute; left: 50%;">
Positioned element
</div>
Fixed with the auto keyword
<div style="position: absolute; left: auto;">
Positioned element
</div>
Fixed with calc()
<div style="position: absolute; left: calc(50% - 20px);">
Positioned element
</div>
Zero without a unit (valid)
<div style="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.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.