progress.md 6.17 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 custom progress bars featuring support for stacked bars, animated backgrounds, and text labels.
5
group: components
Mark Otto's avatar
Mark Otto committed
6
toc: true
Mark Otto's avatar
Mark Otto committed
7
8
---

9
## How it works
Mark Otto's avatar
Mark Otto committed
10

Mark Otto's avatar
Mark Otto committed
11
Progress components are built with two HTML elements, some CSS to set the width, and a few attributes. 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.
12
13
14

- 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.
Mark Otto's avatar
Mark Otto committed
15
- The `.progress-bar` requires an inline style, utility class, or custom CSS to set their width.
16
17
18
- The `.progress-bar` also requires some `role` and `aria` attributes to make it accessible.

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

Mark Otto's avatar
Mark Otto committed
20
{% example html %}
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<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 %}
37

Mark Otto's avatar
Mark Otto committed
38
Bootstrap provides a handful of [utilities for setting width]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/sizing/). Depending on your needs, these may help with quickly configuring progress.
Mark Otto's avatar
Mark Otto committed
39
40
41
42
43
44
45

{% example html %}
<div class="progress">
  <div class="progress-bar w-75" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
46
## Labels
47

48
Add labels to your progress bars by placing text within the `.progress-bar`.
49

50
51
52
53
{% 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
54
55
{% endexample %}

Mark Otto's avatar
Mark Otto committed
56
## Height
Mark Otto's avatar
Mark Otto committed
57

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

{% example html %}
61
62
<div class="progress" style="height: 1px;">
  <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
63
</div>
64
65
<div class="progress" style="height: 20px;">
  <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
66
67
68
</div>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
69
## Backgrounds
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

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 %}

Mark Otto's avatar
Mark Otto committed
88
## Multiple bars
89
90
91
92
93
94
95
96
97

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
98
99
{% endexample %}

Mark Otto's avatar
Mark Otto committed
100
## Striped
Mark Otto's avatar
Mark Otto committed
101

102
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
103
104

{% example html %}
105
106
107
108
109
110
111
112
113
114
<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">
115
  <div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
116
117
118
119
</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
120
121
{% endexample %}

Mark Otto's avatar
Mark Otto committed
122
## Animated stripes
Mark Otto's avatar
Mark Otto committed
123

124
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
125

126
<div class="bd-example">
127
128
129
130
  <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
131
132
133
134
135
    Toggle animation
  </button>
</div>

{% highlight html %}
136
137
138
<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
139
{% endhighlight %}