Precedence of CSS rules and presentation attributes in SVG

Hello world  ;-)

Probably this is also a topic for the CSS WG, but as I do only read (and may write) to the SVG mailing list, I can use only this one for the following ...

In SVG, we do have two options for styling elements: CSS mechanisms as well as presentation attributes. For the precedence of those, I may read:

In [http://www.w3.org/TR/SVG/styling.html#UsingPresentationAttributes], it is stated:
"For user agents that support CSS, the presentation attributes must be translated to corresponding CSS style rules according to rules described in Precedence of non-CSS presentational hints  ([CSS2], section 6.4.4), with the additional clarification that the presentation attributes are conceptually inserted into a new author style sheet which is the first in the author style sheet collection. The presentation attributes thus will participate in the CSS2 cascade as if they were replaced by corresponding CSS style rules placed at the start of the author style sheet with a specificity of zero. In general, this means that the presentation attributes have lower priority than other CSS style rules specified in author style sheets or ‘style’  attributes."

And in the referenced [http://www.w3.org/TR/2008/REC-CSS2-20080411/cascade.html#q12], we read:
"The UA may choose to honor presentational hints from other sources than style sheets, for example the FONT element or the "align" attribute in HTML. If so, the non-CSS presentational hints must be translated to the corresponding CSS rules with specificity equal to zero. The rules are assumed to be at the start of the author style sheet and may be overridden by subsequent style sheet rules."

In a newer version [http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#preshint], this is complemented by the following statement as well as an example:
"For other languages, all document language-based styling must be translated to the corresponding CSS and either enter the cascade at the user agent level or, as with HTML presentational hints, be treated as author level rules with a specificity of zero placed at the start of the author style sheet."

To make a long story short: In SVG, if you give some general design information in an external CSS style sheet, this has precedence over a special presentation attribute in the specific element tag.

I understand why it was so in the beginning since CSS was to replace presentational attributes and tags of HTML 3.2. But for SVG, there is no need to replace the presentational attributes - they were introduced although CSS was already present and could and can be used with SVG up to now and probably in the future as well. Otherwise, the presentational attributes of SVG would need to be marked as deprecated, at least.

And what's the use case of a presentation attribute in SVG? I would like to use CSS rules (from an external stylesheet) for global design issues (e.g. stroke width and color) for most elements, as long as the elements do not need to be specific. But in case I need a special design for a single element or just few elements, I might use the presentation attribute. And even more important, for that special single element, I might easily change the presentation with the help of JavaScript (e.g. due to some user interaction), whereas it is not at all trivial (and should not be done IMHO) to change a corresponding CSS rule with JavaScript ... well, of course, as a work around, I might use a special class for that special element (as long as it is "special"), or I might change its style attribute (!), but if there is more than one class or styling information given in the attribute, I would at least need to use regexp handling for this (to filter out the old information and replace it by the new one), and this is complex and not very efficiently implemented in most browsers ...

What was the rationale behind that decision other than preceding old HTML presentation attributes and elements with CSS rules? And if there is none, would there be any chance to change that rule for SVG presentation attributes? Ah, I already hear those arguing "why should we have an exception for SVG in the CSS standard?", but I might reply that another exception for the same issue is already present in the spec of CSS2.1 regarding HTML itself (user agent level vs. author level, see quote above).

Any opinions?

Juergen Roethig

Received on Saturday, 18 January 2014 18:45:10 UTC