Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import SVG file in Astro and use it without the <img /> tag

Tags:

svg

astrojs

Is there a way to use and SVG file in an Astro file directly without using the <img /> tag. I want something like this:

import Logo from "./logo.svg"

and then use it like this:

<Logo />

I tried that doing it like that but it didn't work.

like image 925
Storm Avatar asked Dec 20 '25 18:12

Storm


1 Answers

You can change the import to add ?raw after the file extension. Then, use <Fragment set:html={Logo} /> to inline the css. See: this post and the Astro docs

like image 71
Marijn Kneppers Avatar answered Dec 23 '25 11:12

Marijn Kneppers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!