jQuery.cssNumber (since 1.4.3, removed in 4.0) is an object of camelCase CSS property names that are unitless. Before 4.0, .css() used it to decide whether a bare number should get a px suffix.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// In cssNumber → no px
$("p").css("opacity", 0.5) // "0.5"
$("p").css("zIndex", 10) // "10"
// Not in cssNumber → px added (jQuery < 4)
$("p").css("width", 200) // "200px"
// Add a custom key (guard for 4.0+):
if (jQuery.cssNumber) {
jQuery.cssNumber.myProp = true;
}
Call
What it does
cssNumber — Unitless CSS Properties
Learn jQuery.cssNumber: which CSS properties skip auto px in .css(), opacity and zIndex examples, custom keys with cssHooks, jQuery 4.0 removal, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Check that jQuery.cssNumber exists (skip on jQuery 4+).
Step 2
For built-ins like opacity, pass a number to .css() — no px.
Step 3
For a custom property, set $.cssNumber.propName = true.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Opacity Stays Unitless
opacity is in cssNumber — a number is not turned into px.
Key. Use camelCase zIndex (or hyphenated z-index in .css()).
Number.100 is written without px.
Read. Getter returns the stacking value as a string.
Frequently Asked Questions
jQuery.cssNumber is an object listing CSS property names that are unitless. Before jQuery 4.0, .css() used it to decide whether to append px to a bare number — listed properties stay unitless; others often get px.
width is not in cssNumber, so jQuery treats the number as pixels. opacity is in cssNumber, so the value stays a unitless 0–1 number.
Yes. jQuery 4.0 removed cssNumber. Pass string values with explicit units to .css() instead. On jQuery 3.x and earlier, cssNumber still controls numeric setters.
Guard and set a camelCase key: if (jQuery.cssNumber) { jQuery.cssNumber.myProp = true; }. Often paired with a cssHook that expects a bare number.
cssHooks define get/set behavior. cssNumber only controls the px auto-append step. Custom hooks that take numbers usually register a matching cssNumber entry.
Common ones include opacity, zIndex, lineHeight, fontWeight, zoom, flexGrow, flexShrink, order, columnCount, and several grid/SVG opacity properties. Keys are camelCase; values are true.