twitter-bootstrap Buttons

Syntax

  • Classes: .btn-default | .btn-primary | .btn-success | .btn-info | .btn-warning | .btn-danger |.btn-link;
  • Sizes: .btn-lg | .btn-md | .btn-sm | .btn-xs;
  • State: active | dissabled.

Button Classes

Bootstrap provides multiple classes for styling buttons and making them stand out.

Bootstrap buttons can be created by adding the .btn class to an element.

Bootstrap ClassRole (color)
.btn-defaultStandard button (white)
.btn-primaryProvides extra visual weight and identifies the primary action (blue)
.btn-successUsed to indicate a successful action (green)
.btn-infoContextual button for providing information (light blue)
.btn-warningIndicates caution should be applied by the user (yellow)
.btn-dangerIndicates a dangerous or negative action (red)
.btn-linkMake you button look like an anchor tag.

Button Sizes

You can also create different sizes of buttons with the .btn-size classes

Bootstrap ClassResult
.btn-lgCreates a larger sized button
.btn-smCreates a smaller sized button
.btn-xsCreates an extra-small button
.btn-blockButtons become block-level elements and span the full width of their parent

Make button active

The active class will make a button appear pressed.

<button type="button" class="btn btn-primary active">Active Primary</button>

Disable a button

Adding the disabled class to a button will render the button un-clickable and show a forbidden cursor when hovering over it.

<button type="button" class="btn btn-primary disabled">Disabled Primary</button>

Render buttons horizontally together

Multiple buttons can be rendered horizontally with the .btn-group class. Simply wrap your buttons inside a container element and give that element the btn-group class.

<div class="btn-group">
  <button type="button" class="btn btn-primary">Apples</button>
  <button type="button" class="btn btn-primary">Oranges</button>
  <button type="button" class="btn btn-primary">Pineapples</button>
</div>

Render buttons vertically

Apply the .btn-group-vertical class to the container element

<div class="btn-group-vertical">
  <button type="button" class="btn btn-primary">Apples</button>
  <button type="button" class="btn btn-primary">Oranges</button>
  <button type="button" class="btn btn-primary">Pineapples</button>
</div>

Make button group take up full width

Buttons wrapped inside a .btn-group element only take up as much width as needed. To make the group span the entire width of the screen, use .btn-group-justified instead.

<div class="btn-group btn-group-justified">
  <a href="#" class="btn btn-primary">Apples</a>
  <a href="#" class="btn btn-primary">Oranges</a>
  <a href="#" class="btn btn-primary">Pineapples</a>
</div>