The goal is to define a custom CSS property value in an external style sheet.
External CSS:
#myDiv {
--myCustomProperty: 'myCustomValue';
}
Markup:
<html>
<div id='myDiv'></div>
</html>
There is nothing in the CSS spec that says custom properties are invalid. However, the browser will render them as invalid, but they should, in theory, still be available by window.getComputedStyle or similar. Firebug shows the custom property and its value in the styles pane but its marked as overwritten.
Following snippet from: http://www.quirksmode.org/dom/getstyles.html
JavaScript:
function getStyle(el,styleProp) {
var x = document.getElementById(el);
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
var value = getStyle('myDiv', '--myCustomProperty');
alert(value);
Output should be the string "myCustomValue"