The CSSWG has a question that it's not well-qualified to answer, because its members don't do enough web development to really understand the problem space well. So we'd like your feedback!
Here's the thing. For a long time, if you wanted access to the property values on an element, your only recourse was
getComputedStyle(). This has always been kinda crappy, though - in particular, because the definition of "computed value" changed between CSS2 (when the function was first defined and implemented) and CSS2.1, the function now technically returns used values for a subset of 2.1 properties, and computed values for everything else. (This means that, for example, if you set
width to a percentage, it'll show up as
px in the
getComputedStyle() results, but if you use a percentage in, say,
flex-basis, it'll show up a percentage.)
(Quick primer on the basic differences between "computed" and "used" values. A CSS value goes through several stages as it transforms from its declared value (what's actually written in the style sheet) to its actual value (the final, absolute value actually used by the browser). The first stage is specified value, which handles the global keywords
initial, and fills in the initial value of the property if you didn't specify anything in your stylesheet for that element. The second stage is computed value, which takes the specified value and resolves it into final form as much as it can, using only property data on the element and its parent. No layout information is used here, and we try to avoid depending on network loads or the property data of other elements. The third stage is used value, which finishes resolving the value into final form, using layout data, network data, and whatever else is necessary. Finally, there's an actual value, which is just the used value, but adjusted as necessary to accommodate the display device and other last-second limitations. For example, fractional pixel lengths might get rounded to integers so they map to an exact number of physical pixels.)
Recently, we added some new and better ways to access this kind of information on elements: the .specifiedStyle, .computedStyle, .usedStyle, and .defaultStyle attributes on Element. These work exactly like
.style, except that rather than only exposing the property set by the
style='' attribute, they expose all the properties, just like the
getComputedStyle() method did.
Here's where we need your help.
.usedStyle seem pretty easy to justify. But
.specifiedStyle is a little harder. What exactly would be helpful for you, the author?
As it's specified right now,
.specifiedStyle will return a value for every property on the element. If you didn't give the element a value for that property in your stylesheets, it'll return the initial value for the property. If you set the property to
inherit, it'll substitute those with the values they represent.
On the other hand, would it be more useful to instead provide something slightly lower-level? Where
inherit are returned literally if specified, and you get back
null or the empty string for properties that were not set on the element? I feel like being able to tell when a property hasn't been set on an element is potentially useful, as it lets you tell the difference between "set a value" and "inherited a value". I also suspect that any time you want something slightly more advanced/friendly, you'd be okay with going all the way to "computed value" or "used value".