Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I use a SVG in React?

I’m using a Typescript app I created with create-react-app, with no other dependencies other than react and react-dom.

Using the tag, how do I display an SVG?

I’ve checked that I have the right path because an adjacent PNG will render. Are SVGs different?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<img src={'../assets/triangle.svg'} alt=''/>

>Solution :

I always like to import the SVG in the top of the file, like this:

import FileSVG from "./file.svg";

and then use it as value for the src prop, like this:

<img src={FileSVG} />

Make sure to check if your path it is correct too!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading