#2411·jquery-ui

CSS variable stripped from calls to jQuery .css()

Author: KrinkleCreated Jul 22, 2026Updated Sep 25, 2026
LabelsComp: Effects

I found an odd behavior in the jQuery Core .css() function when passing values that contain CSS variables, with a color value as fallback. This bug only happens when jQuery UI is also loaded on the page, and seems to be caused by the jQuery Color plugin (as vendored by jQuery UI) and its cssHooks for converting colors to rgb() notation.

Test case

javascript
$('<div>').css('color', 'var(--color-base, #202122)').css('color');

Expected If you run this e.g. on https://jquery.com where jQuery UI is not loaded, it returns var(--color-base, #202122).

Actual If you run it on https://jqueryui.com/resources/demos/draggable/default.html where jQuery UI is present, it returns rgb(32, 33, 34).

This is not limited to the return value, the style attribute itself is altered so this happens during the setting, not the getting.

The impact is that when you later attach the element to the document, where the CSS variable exists in a stylesheet, its value will not be used, and instead the fallback is always used.

This was found downstream at Wikipedia (https://phabricator.wikimedia.org/T391461), where we found theme variables (especially dark mode) causing some challenging color combinations. The issue only happened on the subset of forms where jQuery UI is loaded by something elsewhere on the page.