JQuery Mobile: Change Color of SVG Icons

Since version 1.4, JQuery Mobile provides an SVG-based icon set for high-quality scalable icons.
Out-of-the-box, the icons are provided in two different color schemes: default (white) and alt-icon (black).

To give your user interface an individual style, you might want to change the color to something more specific such as green, black or a specific rgb color.
Using CSS to change the font color of your button or link containing the icon will not work, as the jQuery Mobile svg icons are realized as background images.

The solution to change the icons color, is to modify the svg image realizing the icon itself.
To do so, open jquery mobiles stylesheet (e.g. “jquery.mobile.inline-svg-1.4.1.min.css”) and find the definition of the icon you would like to change (e.g. .ui-icon-delete:after)
The styles are always defined as “.ui-icon-:after”. The icon style definitions contain background images with the SVG images encoded in a data url.

To change the color, you do not need to understand the full encoded svg data url. You just need to know that shapes in an SVG are defined by polygones. In the example below, search for the string “polygon%20fill%3D%22%23FFF”:


polygon%20fill%3D%22%23FFF“ stands for a polygon filled with the color white (FFF).

So to define your custom icon with a different color, copy the style definition into your own css stylesheet file and replace “FFF” with your prefered hex color definition.
Note: You should not modify the original jquery mobile file. Otherwise your modifications could be overridden with the next update.

1 Comment

  1. Alexander

    Thank your for this explanation. It helped me a lot 🙂