buttons.md 4.86 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
3
4
---
layout: page
title: Buttons
---
Mark Otto's avatar
Mark Otto committed
5
6
7
8

Use any of the available button classes to quickly create a styled button.

{% example html %}
Mark Otto's avatar
Mark Otto committed
9
10
11
<!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
<button type="button" class="btn btn-primary">Primary</button>

12
13
14
<!-- Secondary, outline button -->
<button type="button" class="btn btn-secondary">Secondary</button>

Mark Otto's avatar
Mark Otto committed
15
16
17
18
19
20
21
22
23
24
25
<!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success">Success</button>

<!-- Indicates caution should be taken with this action -->
<button type="button" class="btn btn-warning">Warning</button>

<!-- Indicates a dangerous or potentially negative action -->
<button type="button" class="btn btn-danger">Danger</button>

<!-- Deemphasize a button by making it look like a link while maintaining button behavior -->
<button type="button" class="btn btn-link">Link</button>
Mark Otto's avatar
Mark Otto committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{% endexample %}

## Sizes

Fancy larger or smaller buttons? Add `.btn-lg`, `.btn-sm`, or `.btn-xs` for additional sizes.

{% example html %}
<button type="button" class="btn btn-primary btn-lg">Large button</button>
<button type="button" class="btn btn-secondary btn-lg">Large button</button>
{% endexample %}

{% example html %}
<button type="button" class="btn btn-primary btn-sm">Small button</button>
<button type="button" class="btn btn-secondary btn-sm">Small button</button>
{% endexample %}

{% example html %}
<button type="button" class="btn btn-primary btn-xs">Extra small button</button>
<button type="button" class="btn btn-secondary btn-xs">Extra small button</button>
{% endexample %}

Create block level buttons—those that span the full width of a parent—by adding `.btn-block`.

{% example html %}
Mark Otto's avatar
Mark Otto committed
50
<button type="button" class="btn btn-primary btn-lg btn-block">Block level button</button>
Mark Otto's avatar
Mark Otto committed
51
<button type="button" class="btn btn-secondary btn-lg btn-block">Block level button</button>
Mark Otto's avatar
Mark Otto committed
52
53
54
55
56
57
58
{% endexample %}

## Active state

Buttons will appear pressed (with a darker background, darker border, and inset shadow) when active. **There's no need to add a class to `<button>`s as they use a pseudo-class**. However, you can still force the same active appearance with `.active` should you need to replicate the state programmatically.

{% example html %}
Mark Otto's avatar
Mark Otto committed
59
<a href="#" class="btn btn-primary btn-lg active" role="button">Primary link</a>
Mark Otto's avatar
Mark Otto committed
60
<a href="#" class="btn btn-secondary btn-lg active" role="button">Link</a>
Mark Otto's avatar
Mark Otto committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{% endexample %}

## Disabled state

Make buttons look unclickable by adding the `disabled` boolean attribute to any `<button>` element.

{% example html %}
<button type="button" class="btn btn-lg btn-primary" disabled>Primary button</button>
<button type="button" class="btn btn-secondary btn-lg" disabled>Button</button>
{% endexample %}

As `<a>` elements don't support the `disabled` attribute, you must add the `.disabled` class to fake it.

{% example html %}
Mark Otto's avatar
Mark Otto committed
75
<a href="#" class="btn btn-primary btn-lg disabled" role="button">Primary link</a>
Mark Otto's avatar
Mark Otto committed
76
<a href="#" class="btn btn-secondary btn-lg disabled" role="button">Link</a>
Mark Otto's avatar
Mark Otto committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{% endexample %}

<div class="bs-callout bs-callout-warning">
  <h4>Cross-browser compatibility</h4>
  <p>If you add the <code>disabled</code> attribute to a <code>&lt;button&gt;</code>, Internet Explorer 9 and below will render text gray with a nasty text-shadow that we cannot fix.</p>
</div>

<div class="bs-callout bs-callout-warning">
  <h4>Link functionality caveat</h4>
  <p>This class uses <code>pointer-events: none</code> to try to disable the link functionality of <code>&lt;a&gt;</code>s, but that CSS property is not yet standardized and isn't fully supported in Opera 18 and below, or in Internet Explorer 11. So to be safe, use custom JavaScript to disable such links.</p>
</div>

<div class="bs-callout bs-callout-warning">
  <h4>Context-specific usage</h4>
  <p>While button classes can be used on <code>&lt;a&gt;</code> and <code>&lt;button&gt;</code> elements, only <code>&lt;button&gt;</code> elements are supported within our nav and navbar components.</p>
</div>

## Button tags

Use the button classes on an `<a>`, `<button>`, or `<input>` element.

{% example html %}
Mark Otto's avatar
Mark Otto committed
99
100
101
102
<a class="btn btn-secondary" href="#" role="button">Link</a>
<button class="btn btn-secondary" type="submit">Button</button>
<input class="btn btn-secondary" type="button" value="Input">
<input class="btn btn-secondary" type="submit" value="Submit">
Mark Otto's avatar
Mark Otto committed
103
104
105
106
107
108
{% endexample %}

<div class="bs-callout bs-callout-warning">
  <h4>Cross-browser rendering</h4>
  <p>As a best practice, <strong>we highly recommend using the <code>&lt;button&gt;</code> element whenever possible</strong> to ensure matching cross-browser rendering.</p>
  <p>Among other things, there's <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=697451">a bug in Firefox &lt;30</a> that prevents us from setting the <code>line-height</code> of <code>&lt;input&gt;</code>-based buttons, causing them to not exactly match the height of other buttons on Firefox.</p>
Mark Otto's avatar
Mark Otto committed
109
</div>