Warning! Unfortunately, the copy buttons on these cheat sheets only work with Flash installed.

Bootstrap Glyphiconsv.3.2.2

How to Use Bootstrap 3 Glyphicons

Glyphicons are great! They're one of my favourite additions to native Bootstrap 3. I've been working with these glyphs quite a lot, so I thought I'd make a cheat sheet for myself.

Cheat sheet?

Yeah! To use this cheat sheet, simply find the glyphicon you want to use and click the copy button. This will add the complete HTML code for that glyphicon (span tag and all) to your clipboard, ready to paste into your web development tool of choice.

What are Glyphicons?

Glyphicons are basically little symbols, icons, or pictograms (whatever you prefer to call them) that you can use in a webpage. They're implemented in Bootstrap as an icon font — a custom font that contains these glyphs instead of letters.

If you're creating a site based on Bootstrap 3.3.2, you already have access to all 260 glyphs in the Glyphicons 1.9 set.

Don't know how to set up Bootstrap? Go check out the offical getting started guide, or simply just include these two lines in your <head> tag:

(Bootstrap hosting very kindly provided by bootstrapcdn.com)

Counterpoint

Icon fonts aren't the only way to implement icons on the web. If you're looking for a explanation of using icon fonts vs. SVG files (another possible method), I'd suggest reading this excellent post by Ian Feather: Ten reasons we switched from an icon font to SVG.

Who made them?

The glyphicons you see in Bootstrap are part of a set called Glyphicons Halflings and were created by the very talented Jan Kovařík over at GLYPHICONS.

Am I allowed to use them?

Short answer: absolutely! Jan has kindly released them under the same MIT license as Bootstrap. If you'd like more detail, please check out Jan's licensing page.

How do they work?

So, how do I add an icon to my webpage? Well, Glyphicons can be used on the web in one of three ways.

You can use a simple <span> tag to place an glyphicon in your page, like this:

<span class="glyphicon glyphicon-home"></span> =

  • The first class—glyphicon—is a base class. It tells the <span> tag, "hey, heads up: this is going to be an icon."
  • The second class (in this example, glyphicon-home) points the specific icon you want to use. This one is an icon of a house!

To use a HTML Tag for an icon, simply copy and paste <i class="glyphicon glyphicon-home"></i> anywhere within the <body> of your page.

Warning: Don't mix glyphicons with other components

Icon classes shouldn't be combined with other elements in Bootstrap. They're designed to be standalone.

This works slightly differently, by:

  1. Specifying the Glyphicon web-font in a CSS rule with font-family
  2. Using the Unicode HTML Entity to display the icon

Firstly, the CSS rule. This should be placed inside a <style> tag, or better yet, in a seperate stylesheet:

          span.icon { 
  font-family: 'Glyphicons Halflings';
}

Next, the HTML Entity part:

          <span class="icon">&#xf015;</span>
        

The CSS rule specifies that any Unicode HTML Entity inside a <span class="icon"></span> tag will be rendered on the page as an icon.

The HTML entity inside the tag (in this case, &#xf015;) is a string of characters that tells the web-font to display a certain icon.

Note: This method may offer you more flexibility (for example, you could use a <div> or <li> tag instead).

This method works by including the rendering of the icon before the content using the :before CSS psuedo-element.

Firstly, the web-font is specified with font-family, and then the icon is specified by using the content property alongside a unicode hex entity (in this case, f015).

Because the hex entity is inside a style tag, it must be prepended with an escaped backslash, making it \f015.

This should be placed inside a <style> tag, or better yet, in a seperate stylesheet:

          span.icon:before { 
  font-family: 'Glyphicons Halflings';
  content: "\f015";
}

To add this icon to a page, add this HTML tag anywhere in the body of your page.

          <span class="icon"></span>
        

Note: This method is useful because it seperates the visual elements of your design—like icons—from the structural HTML, so you can add glyphicons to existing elements. Particularly useful for tasks like Wordpress or Moodle theme development, for example.

Examples

You can use glyphicons in a variety of ways; in buttons, button groups for a toolbar, navigation or prepended form inputs. Here are a few examples of glyphicons in action:

Buttons

<button type="button" class="btn btn-default btn-lg">
  <span class="glyphicon glyphicon-star"></span> Star
</button>

Toolbars

      
      <div class="btn-toolbar" role="toolbar"> 
  <div class="btn-group">
    <button type="button" class="btn btn-default">
      <span class="glyphicon glyphicon-align-left"></span>
    </button>
    <button type="button" class="btn btn-default">
      <span class="glyphicon glyphicon-align-center"></span>
    </button>
    <button type="button" class="btn btn-default">
      <span class="glyphicon glyphicon-align-right">
      </span>
    </button>
    <button type="button" class="btn btn-default">
      <span class="glyphicon glyphicon-align-justify">
      </span>
    </button>
  </div>
</div>

Navigation

             <ul class="nav nav-pills">
  <li>
    <a href="index.html">
      <span class="glyphicon glyphicon-home"></span> Home
    </a>
  </li>
  <li>
    <a href="shop.html">
      <span class="glyphicon glyphicon-shopping-cart"></span> Shop
    </a>
  </li>
  <li>
    <a href="about.html">
      <span class="glyphicon glyphicon-info-sign"></span> About
    </a>
  </li>
</ul>

Form Inputs

        	<div class="input-group input-group-lg">
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-envelope"></span>
  </span>
  <input class="form-control" type="text" placeholder="Email address">
</div>
<div class="input-group input-group-lg">
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-lock"></span>
  </span>
  <input class="form-control" type="password" placeholder="Password">
</div>

Additional Reading

Want more info on the Glyphicons in Bootstrap 3? Check out the official Bootstrap documentation.

About me

James Croft

My name is James Croft. I'm a web developer from Brisbane, Australia.

If you found this page useful, consider buying a Bootstrap Cheat Sheet poster for your wall!