Experimental SVG components
Type: boolean
Default: false
astro@5.0.0
New
This feature allows you to import SVG files and use them as Astro components. By default, Astro will inline the SVG content into your HTML output.
To enable this feature, set experimental.svg
to true
in your Astro config:
To use this feature, reference the default import of any local .svg
file. Since this import is treated as an Astro component, it requires using the same conventions (e.g. capitalization) as when using dynamic tags.
SVG component attributes
Section titled SVG component attributesYou can pass props such as width
, height
, fill
, stroke
, and any other attribute accepted by the native <svg>
element. These attributes will automatically be applied to the underlying <svg>
element. If a property is present in the original .svg
file and is passed to the component, the value passed to the component will override the original value.
As a convenience, SVG components also accept a size
property. size
is a shorthand which sets both the width
and height
properties to the same value.
The following example uses Astro’s size
property to set an equal width and height of 48 instead of setting the HTML <svg>
attributes of width
and height
separately:
Add the mode
attribute on any SVG component to override your default configured svg.mode
technique for handling imported SVG files.
The following example generates a sprite sheet instead of inlining the logo’s SVG content into the HTML output:
experimental.svg.mode
Section titled experimental.svg.modeType: string
Default: 'inline'
astro@5.0.0
New
The default technique for handling imported SVG files. Astro will inline the SVG content into your HTML output if not specified.
inline
: Astro will inline the SVG content into your HTML output. (default)sprite
: Astro will generate a sprite sheet with all imported SVG files.
For a complete overview, and to give feedback on this experimental API, see the SVG feature RFC.
Reference