We can combine list-style-image with svg s, which we can embed in css! This method offers incredible control over “bullets” that can become anything.
To get the red circle, use only the following css:
ul { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><circle fill="red" cx="5" cy="5" r="2"/></svg>'); }
But this is only the beginning. This allows us to do any crazy thing we want with these bullets. circles or rectangles are simple, but anything you can draw with svg can be pasted there! See the apple apple example below:
ul { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><circle fill="red" cx="5" cy="5" r="5"/></svg>'); } ul ul { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><rect fill="red" x="0" y="0" height="10" width="10"/></svg>'); } ul ul ul { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><circle fill="red" cx="5" cy="5" r="3"/></svg>'); } ul ul ul ul { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><rect fill="red" x="2" y="2" height="4" width="4"/></svg>'); } ul.bulls-eye { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10" width="10" height="10"><circle fill="red" cx="5" cy="5" r="5"/><circle fill="white" cx="5" cy="5" r="4"/><circle fill="red" cx="5" cy="5" r="2"/></svg>'); } ul.multi-color { list-style-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" width="15" height="15"><circle fill="blue" cx="6" cy="6" r="6"/><circle fill="pink" cx="6" cy="6" r="4"/><circle fill="green" cx="6" cy="6" r="2"/></svg>'); }
<ul> <li> Big circles! <ul> <li>Big rectangles!</li> <li>b <ul> <li>Small circles!</li> <li>c <ul> <li>Small rectangles!</li> <li>b</li> </ul> </li> </ul> </li> </ul> </li> <li>b</li> </ul> <ul class="bulls-eye"> <li>Bulls</li> <li>eyes.</li> </ul> <ul class="multi-color"> <li>Multi</li> <li>color</li> </ul>
Width / Height Attributes
Some browsers require width and height attributes for <svg> , or they do not display anything. At the time of this writing, the latest versions of Firefox demonstrate this problem. I set both attributes in the examples.
Encodings
A recent comment reminded me of the encodings for data-uri. This has been a problem for me lately, and I can share the information I researched.
the uri data specification , which refers to the URI specification , says that svg should be encoded according to browser support: ie8
css tricks on svgs
mdn on svgs
Jon Surrell Sep 22 '15 at 16:37 2015-09-22 16:37
source share