</>
ValidateHTML

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

Bad CSS
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 */
}
Good CSS
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 Validator
Recommended

Hostinger Fast & Affordable Web Hosting

Deploy clean, validated CSS on reliable hosting.

Get 80% Off Hosting →

Related CSS Errors

View all CSS errors