postcss-custom-properties icon indicating copy to clipboard operation
postcss-custom-properties copied to clipboard

Retrieving custom property values with `getPropertyValue` doesn't work in IE11

Open toufali opened this issue 5 years ago • 7 comments

Trying to access custom properties set in :root does not seem to work on IE11: getComputedStyle(document.documentElement).getPropertyValue('--my-var') returns empty string despite confirming --my-var is properly set.

Works as expected on Edge and all modern browsers.

toufali avatar Mar 05 '19 23:03 toufali

@HandsomeMedia IE11 doesn't support CSS variables. Ref: https://caniuse.com/#search=css%20variable

BrentWMiller avatar Mar 13 '19 20:03 BrentWMiller

@BrentWMiller yes, but isn't that the main point of PostCSS custom properties - to polyfill for browsers that don't support it?

toufali avatar Mar 20 '19 00:03 toufali

@HandsomeMedia, PostCSS Custom Properties does not polyfill anything but rather transforms your CSS to add in a fallback declaration for the usage of CSS custom properties during build time. PostCSS itself is a CSS transformation/postprocessing tool that's used during build time and has no effect on the client's browser.

qkevinto avatar May 24 '19 02:05 qkevinto

Okay, let me rephrase then: Shouldn't PostCSS transform the :root CSS to add a fallback declaration in IE11, so that we can access it via getComputedStyle(document.documentElement).getPropertyValue('--my-var')?

toufali avatar May 24 '19 16:05 toufali

I have the same issue.

I'm thinking of giving https://www.npmjs.com/package/css-vars-ponyfill a go but not sure if this will work as expected in combination with custom properties.

More ideas are welcome. Thank you.

coolemur avatar Dec 12 '19 15:12 coolemur

Just tested ponyfill. Didn't work on IE11 (doesn't set/get css variables from js).

coolemur avatar Dec 13 '19 08:12 coolemur

@coolemur the css-vars-ponyfill module provides javascript access to all custom properties in a callback: https://github.com/jhildenbiddle/css-vars-ponyfill/issues/85#issuecomment-521771857

spiess-demos avatar Dec 13 '19 14:12 spiess-demos