SVG icons are popular in web development because they are lightweight, scalable, and easy to style. In React, there are several simple ways to display .svg files:
Import the SVG file directly and use it like a normal component:
import { ReactComponent as MyIcon } from './icons/my-icon.svg';
const MyComponent = () => <MyIcon width={24} height={24} />;
Note:Â Supported in Create React App (CRA) and Vite (with vite-plugin-svgr).
Treat the SVG like a regular image:
const MyComponent = () => (
<img src="/icons/my-icon.svg" alt="My Icon" width={24} height={24} />
);
-> Very simple for static icons
-> Harder to change colors dynamically
Paste the SVG markup into your component:
const MyIcon = () => (
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M12 2L2 22h20L12 2z" fill="currentColor"></path>
</svg>
);
Load icons based on props:
const MyComponent = ({ iconName }: { iconName: string }) => {
const Icon = require(`./icons/${iconName}.svg`).default;
return <img src="{" icon="" }="" alt="{iconName}">;
};
Or with Vite:
const icons = import.meta.glob('./icons/*.svg', { eager: true, import: 'default' });
const MyComponent = ({ iconName }: { iconName: string }) => {
const Icon = icons[`./icons/${iconName}.svg`];
return <img src="{" icon="" }="" alt="{iconName}">;
};
Choose the method that fits your needs and keep your UI lightweight and flexible!
Work with our skilled React developers to accelerate your project and boost its performance.
3rd Floor, Aval Complex, University Road, above Balaji Super Market, Panchayat Nagar Chowk, Indira Circle, Rajkot, Gujarat 360005.
Abbotsford, BC
15th B Street 103, al Otaiba Dubai DU 00000, United Arab Emirates
3rd Floor, Aval Complex, University Road, above Balaji Super Market, Panchayat Nagar Chowk, Indira Circle, Rajkot, Gujarat 360005.
Abbotsford, BC
15th B Street 103, al Otaiba Dubai DU 00000, United Arab Emirates
Copyright © 2026 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.