4

I am using some interactive/dynamic SVG on my site and as a feature we have an option to download the .svg file as-is.

One problem we discovered is that when external stylesheets are used, the styles get lost if the user, say, tries to open the file in Inkscape. So I have been styling fill and stroke colors, etc., inline on the elements.

I am wondering about the SVG standard and how stylesheets fit into it. Are .css files designed to be transported with the .svg file? I understand you can declare external stylesheets like so:

<?xml-stylesheet type="text/css" href="mystylesheet.css" ?>

Will most vector graphics software recognize and load this if they are in the same folder? It seems Illustrator doesn't have initial support for SVG but has add-ons that include JavaScript and CSS3 engines.

I can't help but feel like everyone has missed the SVG boat. Has anyone had success doing something like, packaging the .svg with a .css for download and trying this out in various vector graphics programs? What do programs like Inkscape typically do when they save SVG, as there are obviously several ways to assign styles?

2
  • What exactly is your question? (The title is not a question, and you have four inside the body text.)
    – Phrogz
    Commented Jun 11, 2012 at 14:53
  • @Phrogz All 4 I guess... I think they are pretty related. It's sort of a broad question - how are/should SVG and external stylesheets be used generally? I am just experiencing a lot of confusion about which way to do this, so that it will have the broadest support.
    – Tony R
    Commented Jun 13, 2012 at 2:48

1 Answer 1

3

I found a few documents from W3C about SVG viewer conformance that clear some of this up:

SVG Viewer Conformance

Styling with CSS

Styling Alternatives

Common Facilities Used by SVG and CSS

I saw this line,

Conforming SVG Interpreters and Conforming SVG Viewers that support CSS styling of generic (i.e., text-based) XML content are required to also support CSS styling of SVG content.

which makes me believe that only SVG viewers that support CSS (as opposed to presentation attributes) are required to support external stylesheets - so basically just browsers.

I would still like to have a list of SVG software packages and whether each supports external stylesheets as well as how they assign styles, but maybe I will have to do this research for myself.

1
  • Note that it should be trivial to include the external CSS inside the SVG, so that should probably be the safest bet.
    – johndodo
    Commented Dec 11, 2013 at 6:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.