How to change color in svg file?
In SVG, color is set through special attributes:
fill— fill colorstroke— outline color
Changing Color in SVG File Itself
Color can be specified directly inside SVG:
html
<svg>
<circle fill="red" stroke="blue" />
</svg>Changing Color via CSS
If SVG is inline (inside HTML), you can style it with CSS:
css
svg circle {
fill: green;
stroke: black;
}Using currentColor
currentColor inherits text color from parent:
html
<div style="color: blue;">
<svg>
<path fill="currentColor" />
</svg>
</div>Changing Color in External SVG
If SVG is loaded via <img>, color cannot be changed with CSS.
Solution:
- Load SVG inline
- Use
<object>or<use>with<symbol> - Use CSS variables in SVG
Tip:
Use currentColor for icon systems — icons will automatically inherit text color.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.