Built as a sprite
Instead of making every icon an extra request, we've compiled them into a sprite—a bunch of images in one file that uses CSS to position the images with
background-position. This is the same method we use on Twitter.com and it has worked well for us.
All icons classes are prefixed with
.icon- for proper namespacing and scoping, much like our other components. This will help avoid conflicts with other tools.
Glyphicons has granted us use of the Halflings set in our open-source toolkit so long as we provide a link and credit here in the docs. Please consider doing the same in your projects.
How to use
Bootstrap uses an
<i> tag for all icons, but they have no case class—only a shared prefix. To use, place the following code just about anywhere:
There are also styles available for inverted (white) icons, made ready with one extra class:
<i class="icon-search icon-white"></i>
There are 120 classes to choose from for your icons. Just add an
<i> tag with the right classes and you're set. You can find the full list in sprites.less or right here in this document.
When using beside strings of text, as in buttons or nav links, be sure to leave a space after the
<i> tag for proper spacing.
Icons are great, but where would one use them? Here are a few ideas:
- As visuals for your sidebar navigation
- For a purely icon-driven navigation
- For buttons to help convey the meaning of an action
- With links to share context on a user's destination
Essentially, anywhere you can put an
<i> tag, you can put an icon.