Updated for Divi 5: The Code module method and the CSS in this post work the same in Divi 5 and Divi 4 (I tested them on a Divi 5 site). Divi 5 also has a new SVG module and an Icon Manager for your own SVG icons, so I added a section on when to use them and when CSS still does the job better.
How to change the color of SVG icons in Divi
To change the color of an SVG icon with CSS, paste the SVG code into a Divi Code module (instead of uploading the file as an image), give the module a CSS class, and set the icon's fill and stroke with CSS. That also lets you change the color on hover.
Being able to use custom SVG icons instead of the default ones gives you much more freedom in your designs. But simply uploading your icon as an image is limiting, because you cannot change its appearance on hover.
In this short video walkthrough, I would like to show you how to start adding SVG icons using the Code module and how to change icon colors with custom CSS.
The video was recorded in Divi 4. The steps are the same in Divi 5, only the place where you add a CSS class has moved: Advanced tab ➜ Attributes ➜ Add Attribute ➜ CSS Class (Divi 4: Advanced tab ➜ CSS ID & Classes).

See it in action on the live demo page. This section layout is also available as a free download:
Free download
Cards with SVG Icons Layout
A Divi section with three colorful cards and two-tone SVG icons in Code modules that change color on hover, with all the CSS included. Works in Divi 5 and Divi 4.
Get the free downloadHow to look inside an SVG file (and optimize it)
An SVG file is just code, so you can open it in any text or code editor to see the shapes it is made of. A tool like SVGOMG shows the same code and makes it smaller and cleaner before you paste it into Divi.
To see the SVG code that is behind your SVG image or icon, all you need to do is simply open the file in a text or a code editor. But this handy online tool called SVGOMG will not only show you the code, but also optimize it for you. It comes as an app, too, so you can install it and use it offline as well.

One thing to check in the code: if the shapes have inline styles like style="stroke:#000", they will win over your CSS class. Colors written as attributes (stroke="#000") or in a <style> block inside the SVG are fine, your CSS overrides them.
How to style SVG icons inside the Divi Code module
Paste the optimized SVG code into a Code module, add a CSS class to the module, and target everything inside the SVG with .your-class svg *. Then you can set the fill and stroke colors, and change them on hover.
Now, once you copy the optimized SVG code you can simply paste it inside a Divi Code module and enjoy crisp looking icons, which you can target and style with CSS! For example, if you add a my-icon CSS class to the Code module (Advanced tab ➜ Attributes ➜ Add Attribute ➜ CSS Class (Divi 4: Advanced tab ➜ CSS ID & Classes)), you'll be able to target any element inside your SVG in that module, by using this bit of CSS:
.my-icon svg * {
fill: #121212;
stroke: #343434;
}
The star "*" symbol is a selector which selects every element inside the SVG element, inside your Code module. The code example above will change both the fill and the stroke color. If your icon is drawn with lines only (like the icons in my demo), set only the stroke, or use fill: none, otherwise the shapes get filled in.
Change the icon color on hover
By modifying the selector you can change the color of SVG paths and shapes on hover. My demo section uses this bit of CSS to change the SVG icon when hovering over the column (the dl-color CSS class is added to the Column settings):
.dl-color:hover .et_pb_code svg * {
stroke: #242325;
}
Because the hover is on the column, the icon changes color when you hover anywhere on the card, not only over the icon itself. In Divi 5, a column gets its class the same way as a module: Advanced tab ➜ Attributes ➜ Add Attribute ➜ CSS Class (Divi 4: Advanced tab ➜ CSS ID & Classes).
Color only one part of the icon
You can also select only a specific part of the SVG image by adding your own CSS class to individual elements in the SVG code. For example, add class="dl-accent" to one <path> and give it its own color:
.my-icon .dl-accent {
stroke: #f42279;
}
Let the icon follow the text color with currentColor
If you replace the color values in the SVG code with currentColor (for example stroke="currentColor"), the icon uses the CSS color of the module it sits in. Then one color rule, including a hover color, changes the whole icon:
.my-icon {
color: #343434;
}
.dl-color:hover .my-icon {
color: #242325;
}
Where to add the CSS in Divi 5
Add the CSS to the page (gear icon top-left ➜ Page Settings ➜ Advanced ➜ Custom CSS) if the icons live on one page, or to Divi ➜ Theme Options ➜ General ➜ Custom CSS if you use them across the site.
In my free layout, the CSS sits in a second Code module inside <style> tags, so it travels with the section when you import it. That still works in Divi 5, just keep in mind that the CSS only loads on pages where that Code module is used.
Does Divi 5 have a native way to style SVG icons?
Yes, partly. Divi 5 has an SVG module with fill and stroke color settings, and an Icon Manager where you can upload your own SVG icons. Both are great for one-color icons, but for multi-color icons or a hover effect on the whole card, the CSS above is still the way to go.
The Divi 5 SVG module
The SVG module puts the SVG code straight into the page, just like the Code module does. In the Content tab ➜ SVG Source you can paste the SVG code or pick an uploaded SVG file (you need to enable SVG uploads for that), and in the Design tab you get Fill (color and opacity) and Stroke (color, width and opacity) settings.
- The colors apply to every shape in the SVG, so a two-color icon becomes one color.
- The module removes
<style>tags from the SVG code (simple class rules like.cls-1{stroke:#000}are turned into attributes first, so the icon still looks right). - The hover color in the module's Design settings is applied per shape: in my test only the line under the mouse changed color, not the whole icon. For a hover on the whole card, use the column hover CSS from above with
.et_pb_svginstead of.et_pb_code:
.dl-color:hover .et_pb_svg svg * {
stroke: #242325;
}
Custom icons in the Icon Manager
In Divi 5 you can upload your own SVG icons in the Icon Manager (open any icon picker, for example in the Icon module, and click Icon Manager). Then you can pick them like the built-in icons. Divi shows these icons as a CSS mask, so each icon has one color, the module's icon color. That is perfect for simple line icons, but you can't color parts of the icon separately. For two-tone icons like the ones in my demo, stick with the Code module (or the SVG module) and CSS.
Final thoughts
Don't forget to check out the icon demo page to see beautifully styled SVG icons! If you're a subscriber, feel free to download the free layout above and test the icons I have created.
Hope you find this useful! Share your thoughts in my Divi Lovers Facebook group.





