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.
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:
<i class="icon-search"></i>
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.
Heads up!
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:
Essentially, anywhere you can put an <i>
tag, you can put an icon.
Use them in buttons, button groups for a toolbar, navigation, or prepended form inputs.
The best part about forms in Bootstrap is that all your inputs and controls look great no matter how you build them in your markup. No superfluous HTML is required, but we provide the patterns for those who require it.
More complicated layouts come with succinct and scalable classes for easy styling and event binding, so you're covered at every step.
Bootstrap comes with support for four types of form layouts:
Different types of form layouts require some changes to markup, but the controls themselves remain and behave the same.
Bootstrap's forms include styles for all the base form controls like input, textarea, and select you'd expect. But it also comes with a number of custom components like appended and prepended inputs and support for lists of checkboxes.
States like error, warning, and success are included for each type of form control. Also included are styles for disabled controls.
Bootstrap provides simple markup and styles for four styles of common web forms.
Name | Class | Description |
---|---|---|
Vertical (default) | .form-vertical (not required) |
Stacked, left-aligned labels over controls |
Inline | .form-inline |
Left-aligned label and inline-block controls for compact style |
Search | .form-search |
Extra-rounded text input for a typical search aesthetic |
Horizontal | .form-horizontal |
Float left, right-aligned labels on same line as controls |
With v2.0, we have lighter and smarter defaults for form styles. No extra markup, just form controls.
<form class="well"> <label>Label name</label> <input type="text" class="span3" placeholder="Type something"> <span class="help-inline">Associated help text!</span> <label class="checkbox"> <input type="checkbox"> Check me out </label> <button type="submit" class="btn">Submit</button> </form>
Reflecting default WebKit styles, just add .form-search
for extra rounded search fields.
<form class="well form-search"> <input type="text" class="input-medium search-query"> <button type="submit" class="btn">Search</button> </form>
Inputs are block level to start. For .form-inline
and .form-horizontal
, we use inline-block.
<form class="well form-inline"> <input type="text" class="input-small" placeholder="Email"> <input type="password" class="input-small" placeholder="Password"> <label class="checkbox"> <input type="checkbox"> Remember me </label> <button type="submit" class="btn">Sign in</button> </form>
Given the above example form layout, here's the markup associated with the first input and control group. The .control-group
, .control-label
, and .controls
classes are all required for styling.
<form class="form-horizontal"> <fieldset> <legend>Legend text</legend> <div class="control-group"> <label class="control-label" for="input01">Text input</label> <div class="controls"> <input type="text" class="input-xlarge" id="input01"> <p class="help-block">Supporting help text</p> </div> </div> </fieldset> </form>
Shown on the left are all the default form controls we support. Here's the bulleted list:
Up to v1.4, Bootstrap's default form styles used the horizontal layout. With Bootstrap 2, we removed that constraint to have smarter, more scalable defaults for any form.
Bootstrap features styles for browser-supported focused and disabled
states. We remove the default Webkit outline
and apply a box-shadow
in its place for :focus
.
It also includes validation styles for errors, warnings, and success. To use, add the error class to the surrounding .control-group
.
<fieldset class="control-group error"> </fieldset>
Input groups—with appended or prepended text—provide an easy way to give more context for your inputs. Great examples include the @ sign for Twitter usernames or $ for finances.
Up to v1.4, Bootstrap required extra markup around checkboxes and radios to stack them. Now, it's a simple matter of repeating the <label class="checkbox">
that wraps the <input type="checkbox">
.
Inline checkboxes and radios are also supported. Just add .inline
to any .checkbox
or .radio
and you're done.
To use prepend or append inputs in an inline form, be sure to place the .add-on
and input
on the same line, without spaces.
To add help text for your form inputs, include inline help text with <span class="help-inline">
or a help text block with <p class="help-block">
after the input element.
Wrap inline snippets of code with <code>
.
For example, <code>section</code> should be wrapped as inline.
Use <pre>
for multiple lines of code. Be sure to escape any angle brackets in the code for proper rendering.
<p>Sample text here...</p>
<pre> <p>Sample text here...</p> </pre>
Note: Be sure to keep code within <pre>
tags as close to the left as possible; it will render all tabs.
You may optionally add the .pre-scrollable
class which will set a max-height of 350px and provide a y-axis scrollbar.
Take the same <pre>
element and add two optional classes for enhanced rendering.
<p>Sample text here...</p>
<pre class="prettyprint linenums"> <p>Sample text here...</p> </pre>
Download google-code-prettify and view the readme for how to use.