Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

Is there a way to edit SVG files in Illustrator where you can specify a CSS class for each path?

I already know in Illustrator that if you give the layer name an actual name, Illustrator will use that name as the path's ID, which is fine if you don't plan on reusing the icon more than once on the same page.

My current workaround is to just use the IDs method, but then later convert the IDs to classes in my code editor, but it's pretty annoying to have to do every time I generate my SVG sprite.

If that's currently not possible in Illustrator, are there any other apps that will allow you to specify that? Or maybe a Grunt or Gulp package?

It looks like you might be able to do it with Inkscape with a hack, so I might look at that if there's no other good solutions out there.

share|improve this question
I can't get illustrator to export with ID's, or classes's. I prefer to code my SVG's though, as odd as that sounds, and not very effective i know, Could you include what version of illustrator you are using? –  Daniel Jun 18 '14 at 18:42
I'm using Adobe Illustrator CC version 17.1.0 –  NerdCowboy Jun 18 '14 at 18:52
Ah, i'm using an older version, mine probably doesn't even do this. –  Daniel Jun 18 '14 at 18:56
i am also searching for the perfect SVG image workflow. i want to create a set of SVGs listening to the same CSS — for this it is necessary to have classes. the source files need to stay editable in a visual editor. i tried out "sketch" briefly, just as with illustrator, the generated svg code looks very proprietary. –  Frank Lämmer Oct 7 '14 at 8:27

1 Answer 1

up vote 1 down vote accepted

Looks like the link Ian Dunn posted might be your ticket. Here's an excerpt from that page:

In the SVG export options, I select Style Elements, and I select the Include Unused Graphic Styles option. It will declare sandStyle and blueSky as CSS styles in the SVG document.

Here is the SVG output generated by Illustrator CC:
<style type="text/css"> .sandStyle{fill:#BFAF8F;stroke:#A6806A;stroke-width:3;stroke-miterlimit:10;} .blueSky{fill:#338AC4;stroke:#3469B7;stroke-width:3;stroke-miterlimit:10;} </style> <g id="mySquare"> <rect x="90.5" y="15.5" class="sandStyle" width="64" height="63"/> </g> <g id="myCircle"> <circle class="sandStyle" cx="42" cy="46" r="34.2"/> </g>

Illustrator can export graphic styles as CSS in a style element and applies them via classes in the SVG code. This is how you can generate classes in your exported SVG. Depending on what you want those classes to do, you could just define them in another CSS file and remove the style definitions from the exported SVG.

The linked page states this, but for the sake of completeness, Illustrator will only generate the style element and classes if you set CSS Properties: Style Element in the Advanced area (you might need to click More Options) of the SVG Options Dialog: Save > Format: SVG > SVG Options > More Options > CSS Properties: Style Element

I'd also note that generated code is never going to be quite perfect for all situations. Hand-written code tends to be lighter and easier for humans to read (if that's what you're going for). I'd recommend reading over Wikimedia user Quibik's document on cleaning up SVG files by hand and taking a look at grunt-svgmin.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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