jQuery.cssHooks (since 1.4.3) lets you plug custom get and set functions for a CSS property name. That extends both .css() and .animate().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.cssHooks.someProp = {
get: function (elem, computed, extra) { /* read */ },
set: function (elem, value) { /* write */ }
};
// Then normal API works:
$("#el").css("someProp", "10px");
$("#el").css("someProp");
Call
What it does
cssHooks — Custom CSS Get and Set
Learn jQuery.cssHooks: override how .css() gets and sets properties, normalize vendor prefixes, use cssNumber and fx.step, examples, 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
Confirm $.cssHooks exists (jQuery 1.4.3+).
Step 2
Optional: feature-test the real style property name (standard vs vendor).
Find the supported name (standard or vendor-prefixed) before wiring a hook.
jQuery
function styleSupport(prop) {
var cap = prop.charAt(0).toUpperCase() + prop.slice(1);
var prefixes = ["Moz", "Webkit", "ms"];
var div = document.createElement("div");
var supported = prop in div.style ? prop : null;
if (!supported) {
for (var i = 0; i < prefixes.length; i++) {
var vendor = prefixes[i] + cap;
if (vendor in div.style) { supported = vendor; break; }
}
}
return supported;
}
console.log(styleSupport("borderRadius")); // e.g. "borderRadius"
cssNumber. Marks the property unitless so jQuery won’t add px.
set. Builds a rotate(Ndeg) transform string.
get. Parses the degrees back out of style.transform.
Frequently Asked Questions
jQuery.cssHooks is an object where you register get and set handlers for CSS property names. When you call .css('prop') or .animate({ prop: value }), jQuery can route through your hook instead of the default style logic.
Use cssHooks for special cases: vendor-prefix normalization, synthetic properties (like a rotateDeg helper), or animation of non-standard values. Everyday color and width changes only need .css().
jQuery writes its own cssHooks during document ready and can overwrite hooks registered too early. The official docs recommend wrapping your registration in a ready callback.
cssHooks define how to read and write a property. cssNumber tells jQuery not to auto-append px to numeric setter values — useful for opacity, z-index, or custom degree values.
A get/set hook lets animation use that property. For complex values, also add $.fx.step.propName so each frame pushes the tweened number through your setter.
Rarely for common modern properties. Hooks remain useful for plugins, legacy support, custom properties, and understanding how .css() and .animate() share one extension point.