Acerca de este problema de CSS
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.
Encuentra problemas como este automáticamente
Rocket Validator escanea miles de páginas en segundos, detectando problemas de HTML en todo tu sitio web.
Más información: