Missing Unit on CSS Value
In CSS, numeric values (except 0) must have a unit. Writing 'margin: 10' instead of 'margin: 10px' is invalid. The only exceptions are unitless values like line-height, opacity, flex-grow, z-index, and font-weight, which accept plain numbers by design.
Why It Matters
A missing unit causes the entire declaration to be ignored. The property reverts to its default or inherited value, which can cause layout shifts, spacing issues, or invisible elements.
Code Examples
div {
margin: 20; /* needs a unit */
padding: 10 15; /* both need units */
font-size: 16; /* needs a unit */
border: 1 solid red; /* width needs unit */
}div {
margin: 20px;
padding: 10px 15px;
font-size: 16px;
border: 1px solid red;
}How to Fix
- 1Always add a unit to non-zero numeric values: px, em, rem, %, vh, vw.
- 2Exception: 0 never needs a unit. 'margin: 0' is correct (not 'margin: 0px').
- 3Properties that accept unitless numbers: line-height, opacity, z-index, flex-grow, flex-shrink, font-weight, order.
- 4When in doubt, use px for fixed sizes, rem for scalable sizes, % for relative sizes.
Check Your CSS Now
Our CSS validator detects this error automatically and shows the exact line number.
Open CSS ValidatorHostinger — Fast & Affordable Web Hosting
Deploy clean, validated CSS on reliable hosting.
Related CSS Errors
Invalid CSS Property Value
Learn why CSS property values are invalid and how to fix them. Common mistakes with colors, units, and keywords.
Invalid CSS Color Value
Common CSS color mistakes: wrong hex codes, misspelled names, invalid rgb/hsl values. How to fix them.
Missing Semicolon in CSS
Why missing semicolons break CSS rules and how to find them. The most common CSS syntax error.