One of the best things about SVG icons is that you can change them. This guide shows you the common ways to change the colour and size of an icon. Some take ten seconds in a text editor. Others use a design app.
First, look inside the file
Open any SVG in a text editor. You will see something like this:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="48" height="48">
<g fill="none" stroke="#1e293b" stroke-width="1.5">
<path d="M12 6.5v5.5l3.500 2"/>
</g>
</svg>
Three things matter:
viewBoxis the grid the icon is drawn on. Smash Icons use a 24 by 24 grid.widthandheightset the size the icon is shown at.strokeis the colour of the lines.fillis the colour of the filled parts.
Change the size
In the file
Change width and height. Leave viewBox alone. It is what lets the drawing grow and shrink.
With CSS
.icon { width: 32px; height: 32px; }
Keep the shape
Use the same number for width and height. Line icons look sharpest at 24, 48, 72 or 96 pixels. At sizes in between, such as 20 or 30 pixels, thin lines can look a little soft.
The line gets thicker too
When you make a line icon twice as big, the line gets twice as thick. If you want a big icon with a fine line, lower stroke-width in the file. On a 24 grid, 1.5 is a medium line, 1 is light and 2 is bold.
Change the colour
In the file
Find the colour codes. They look like #1e293b. Swap them for the colour you want. A line or solid icon often has just one. Flat icons have a few, one for each fill and edge.
With CSS, using currentColor
Swap the colour in the file for the word currentColor:
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">...</svg>
The icon now takes the text colour of the thing it sits in:
.nav a { color: #5d6380; }
.nav a:hover { color: #4f35e0; }
This only works when you paste the SVG code into your HTML. Your CSS cannot reach an SVG that is loaded with an <img> tag.
An icon loaded as an image
If you must use <img>, save a second copy of the file with the new colour. That is the simple way, and it always works. CSS filters can tint an image, but the result is hard to guess unless you want black or white.
In a design app
Figma
Drag the SVG onto the canvas. Double-click until you have picked the shape you want. Then change Stroke or Fill in the panel on the right. To change the size, pick the whole icon, press K for the Scale tool and drag. This makes the line grow with the shape.
Adobe Illustrator
Open the SVG. Pick a shape with the Direct Selection tool. Then choose a new colour in the Properties panel. To change one colour everywhere in one go, use Edit > Edit Colors > Recolor Artwork. When you change the size, tick Scale Strokes & Effects in the Transform panel if you want the line to grow too.
Inkscape
Open the file and click a shape. Pick a colour from the row at the bottom of the window. Click to set the fill. Shift-click to set the line. Object > Fill and Stroke gives you more control.
Styles that need a little more care
- Solid icons use a mask to cut clear gaps into the shape. The mask sits on one rectangle. Change the fill colour of that rectangle.
- Pixel icons are made of small squares. Change the
fillon each colour group. - Hand drawn icons have two pen lines on top of each other. Change both.
Check the contrast
When you have changed the colour, check that the icon still stands out from what is behind it. If the icon tells people something, aim for a contrast of at least 3:1.
Ready to try it? Pick any icon from the line set. It is the easiest style to change.