Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Stephen O'Connor
Stephen O'Connor
22,291 Points

Why does external css override inline svg styling?

I'm just working through the SVG course and Nick uses external css to override the inline styles of an SVG when the SVG code is in the HTML.

Why do the external css styles override the inline SVG styles? This usually wouldn't happen with normal inline css.


2 Answers

Codin - Codesmite
Codin - Codesmite
8,600 Points

Because it is not an inline style it is an attribute and external styles will override inline attributes.

For example:

This is an attribute and not an inline style:


This is an inline style:



<svg width="500" height="500">
  <text x="100" y="100" fill="red" style="fill:green">This will be green</text>

The SVG text will be filled green because the inline style will override the fill="red" attribute. http://codepen.io/anon/pen/Ggwxmb

Laurie Williams
Laurie Williams
10,174 Points

I think it's because SVG is an attribute and CSS styles override attributes.