How can I change the bullet points in an HTML list and use the glyphicons that come with Bootstrap 3?
So that:
<ul> <li>...</li> <li>...</li> </ul>
Displays as:
[icon] Facere possimus, omnis voluptas assumenda est, numquam eius modi omnis dolor repellendus. Non numquam eius modi numam dolor omnis tempora incidunt ut labore. [icon] Facere possimus, omnis voluptas assumenda est, numquam eius modi omnis dolor repellendus. Non numquam eius modi numam dolor omnis tempora incidunt ut labore.
I would prefer not to have to inject extra HTML such as this...
<ul> <li><i class="glyphicon glyphicon-chevron-right"></i> ...</li> <li><i class="glyphicon glyphicon-chevron-right"></i> ...</li> </ul>
What are Glyphicons? Glyphicons are icon fonts which you can use in your web projects. Glyphicons Halflings are not free and require licensing, however their creator has made them available for Bootstrap projects free of cost.
Bootstrap 3 Glyphicons are actually fonts, so you can scale them and color them as you please. Bootstrap previously used image sprites for icons. To add a glyphicon, add a <span> tag with Bootstrap's . glyphicon class and also the class for the specific glyphicon that you require.
This isn't too difficult with a little CSS, and is much better than using an image for the bullet since you can scale it and colour it and it will keep sharp at all resolutions.
Find the character code of the glyphicon by opening the Bootstrap docs and inspecting the character you want to use.
Use that character code in the following CSS
li { display: block; } li:before { /*Using a Bootstrap glyphicon as the bullet point*/ content: "\e080"; font-family: 'Glyphicons Halflings'; font-size: 9px; float: left; margin-top: 4px; margin-left: -17px; color: #CCCCCC; }
You may like to tweak the colour and margins to suit your font size and taste.
If anyone is coming here looking to do this with Font Awesome Icons (like I was) view here: https://fontawesome.com/how-to-use/on-the-web/styling/icons-in-a-list
<ul class="fa-ul"> <li><i class="fa-li fa fa-check-square"></i>List icons</li> <li><i class="fa-li fa fa-check-square"></i>can be used</li> <li><i class="fa-li fa fa-spinner fa-spin"></i>as bullets</li> <li><i class="fa-li fa fa-square"></i>in lists</li> </ul>
The fa-ul
and fa-li
classes easily replace default bullets in unordered lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With