Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML SVG Basics SVG and CSS Responsive SVGs

Embedding SVGs, Web Optimization and Responsiveness

I was just wondering if it would actually be better practice to place your SVG in your html file via an image element and create multiple detailed and less detailed SVGs that you switch out with a media query based on the page's size. Would this be possible with Javascript?

I don't know if this would be a possibility - but I worry about performance optimization seeing 20+ lines of code just for one - typically not incredibly important - image file.

1 Answer

Alan Brown
Alan Brown
20,383 Points

You can now use the symbol tag in your svg. Embed that with an image tag and use css to style the svg and media queries to change the stroke widths etc responsively.