progress.md 6.05 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
---
Mark Otto's avatar
Mark Otto committed
2
layout: docs
Mark Otto's avatar
Mark Otto committed
3
title: Progress
Mark Otto's avatar
Mark Otto committed
4
description: Documentation and examples for using Bootstrap progress bars.
5
group: components
Mark Otto's avatar
Mark Otto committed
6
7
---

8
Use our custom progress component for displaying simple or complex progress bars. We don't use [the HTML5 `<progress>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress), ensuring you can stack progress bars, animate them, and place text labels over them.
Mark Otto's avatar
Mark Otto committed
9

Mark Otto's avatar
Mark Otto committed
10
11
12
13
14
## Contents

* Will be replaced with the ToC, excluding the "Contents" header
{:toc}

15
## How it works
Mark Otto's avatar
Mark Otto committed
16

17
18
19
20
21
22
23
24
Progress components are built with two HTML elements, some CSS to set the width, and a few attributes.

- We use the `.progress` as a wrapper to indicate the max value of the progress bar.
- We use the inner `.progress-bar` to indicate the progress so far.
- The `.progress-bar` requires an inline style or custom CSS to set their width.
- The `.progress-bar` also requires some `role` and `aria` attributes to make it accessible.

Put that all together, and you have the following examples.
25

Mark Otto's avatar
Mark Otto committed
26
{% example html %}
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<div class="progress">
  <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
{% endexample %}
43

44
## Customizing
45

46
Customize the appearance of your progress bars with custom CSS, background utilities, stripes, and more.
47

48
### Labels
49

50
Add labels to your progress bars by placing text within the `.progress-bar`.
51

52
53
54
55
{% example html %}
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div>
</div>
Mark Otto's avatar
Mark Otto committed
56
57
{% endexample %}

58
### Height
Mark Otto's avatar
Mark Otto committed
59

60
We only set a `height` value on the `.progress-bar`, so if you change that value the outer `.progress` will automatically resize accordingly.
Mark Otto's avatar
Mark Otto committed
61
62

{% example html %}
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 25%; height: 1px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 25%; height: 20px;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
{% endexample %}

### Backgrounds

Use background utility classes to change the appearance of individual progress bars.

{% example html %}
<div class="progress">
  <div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
{% endexample %}

### Multiple bars

Include multiple progress bars in a progress component if you need.

{% example html %}
<div class="progress">
  <div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
  <div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
  <div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
</div>
Mark Otto's avatar
Mark Otto committed
100
101
102
103
{% endexample %}

### Striped

104
Add `.progress-bar-striped` to any `.progress-bar` to apply a stripe via CSS gradient over the progress bar's background color.
Mark Otto's avatar
Mark Otto committed
105
106

{% example html %}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<div class="progress">
  <div class="progress-bar progress-bar-striped" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar progress-bar-striped bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar progress-bar-striped bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress">
  <div class="progress-bar progress-bar-striped bg-warning" role="progressbar"style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" ></div>
</div>
<div class="progress">
  <div class="progress-bar progress-bar-striped bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
Mark Otto's avatar
Mark Otto committed
122
123
{% endexample %}

Mark Otto's avatar
Mark Otto committed
124
125
### Animated stripes

126
The striped gradient can also be animated. Add `.progress-bar-animated` to `.progress-bar` to animate the stripes right to left via CSS3 animations.
Mark Otto's avatar
Mark Otto committed
127

128
**Animated progress bars don't work in Opera 12**—as they don't support CSS3 animations.
Mark Otto's avatar
Mark Otto committed
129

130
<div class="bd-example">
131
132
133
134
  <div class="progress">
    <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
  </div>
  <button type="button" class="btn btn-secondary bd-toggle-animated-progress" data-toggle="button" aria-pressed="false" autocomplete="off">
Mark Otto's avatar
Mark Otto committed
135
136
137
138
139
    Toggle animation
  </button>
</div>

{% highlight html %}
140
141
142
<div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
</div>
Mark Otto's avatar
Mark Otto committed
143
{% endhighlight %}