Styling SVG icon in React.js
3 min readAug 21, 2021
Swinging between both design team and frontend developing team, I am recently dealing with icons, including those drawn by our designers ๐จHence, this post will guide you to use svg icons in an developer-friendly, easy-to-style method ๐ฉโ๐ป
Our Goal
Enable frontend to apply the same styling logic, especially changing color, among all icons.
The Challenge
When it comes to changing the color of a svg icon, frontend may actually needs to change the stroke
property or the fill
property, which varies between different icons.
Letโs open 3 svg files with text editor to see what I mean:
- filter icon (color set on
fill
property in<path>
)
- folder icon (color set on
stroke
property in<path>
)