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.
Remember
// 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;
}
Treat it as a lookup: if the property is listed, numbers stay unitless.
Check that jQuery.cssNumber exists (skip on jQuery 4+).
For built-ins like opacity, pass a number to .css() — no px.
For a custom property, set $.cssNumber.propName = true.
Pair custom keys with a cssHook when the property is synthetic.
Piece
Required?
Role
$.cssNumber
Yes (pre-4.0)
Map of unitless property names
CamelCase key
Yes
DOM-style name (zIndex, not z-index)
Value
—
Always true for listed keys
Pseudocode
Pseudocode
when .css(prop, number) is called (jQuery < 4):
if prop is in $.cssNumber:
write number as-is // opacity → 0.5
else:
write number + "px" // width → "200px"
to teach a custom prop:
if $.cssNumber exists:
$.cssNumber.myProp = true
Reference
Cheat Sheet
Keep these facts handy for numeric .css() setters.
Topic
Detail
API
jQuery.cssNumber / $.cssNumber
Since
1.4.3
Removed
jQuery 4.0
Common keys
opacity, zIndex, lineHeight, fontWeight
Also
flexGrow, order, columnCount, grid keys
Extend
if ($.cssNumber) $.cssNumber.prop = true
Safe habit
Pass "200px" / "0.5" as strings when unsure
Try it
Live Preview
Compare a unitless property with a dimension property. Results show the inline style attribute after each call.
Sample
Browser demo of how $.cssNumber affects numeric .css() setters.
Guard.if ($.cssNumber) keeps the code safe on jQuery 4+.
Mark.rotateDeg = true stops jQuery from appending px.
Hook. The setter builds a rotate(Ndeg) transform.
Result..css("rotateDeg", 90) receives 90, not "90px".
Edge Cases & Pitfalls
Check these before relying on numeric .css() setters.
removed
Missing on jQuery 4.0+
$.cssNumber is undefined. Always pass unit strings, and guard custom registrations.
case
Keys are camelCase
Register zIndex, not z-index. Hyphenated names work in .css() calls, but the object uses DOM names.
hook
Custom props still need a hook
cssNumber only skips px. Without a cssHook, a made-up name does nothing useful.
strings
Strings skip the px logic
If you pass "50%" or "2em", jQuery does not append px — the auto-append path is for bare numbers.
Compatibility
Browser Support
jQuery.cssNumber exists in jQuery 1.4.3–3.x in the browser. It was removed in jQuery 4.0. Not for Node.js without a DOM.
✓ jQuery 1.4.3–3.x · Removed in 4.0
jQuery.cssNumber
Available wherever jQuery 1.4.3–3.x runs in a browser. On jQuery 4+, pass explicit unit strings to .css() instead.
LegacyPre-4.0 jQuery
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.cssNumber1.4.3–3.x
Bottom line: Use cssNumber on jQuery 3.x and earlier. For new code, prefer .css("width", "200px") so behavior stays clear across versions.
Analysis
Performance Notes
Approach
Cost
Best for
Bare number + cssNumber
Negligible
jQuery 3.x unitless props
String with units
Same
All versions, clearest intent
Custom cssNumber + hook
Small
Plugin / synthetic properties
The lookup is a cheap object check. Clarity matters more than micro-cost — explicit unit strings travel better across jQuery major versions.
Remember
Key Takeaways
Role: list of unitless CSS properties for .css() numbers.
Listed: no px; not listed: often get px (pre-4.0).
Removed: gone in jQuery 4.0 — pass unit strings instead.
Extend:if ($.cssNumber) $.cssNumber.prop = true.
One line:cssNumber tells pre-4.0 jQuery which numeric .css() values must stay unitless.
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.