Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
commit | author | age
83c3f6 1 ---
SP 2 layout: docs
3 title: Spinners
4 description: Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript.
5 group: components
6 toc: true
7 ---
8
9 ## About
10
11 Bootstrap "spinners" can be used to show the loading state in your projects. They're built only with HTML and CSS, meaning you don't need any JavaScript to create them. You will, however, need some custom JavaScript to toggle their visibility. Their appearance, alignment, and sizing can be easily customized with our amazing utility classes.
12
13 For accessibility purposes, each loader here includes `role="status"` and a nested `<span class="sr-only">Loading...</span>`.
14
15 ## Border spinner
16
17 Use the border spinners for a lightweight loading indicator.
18
19 {% capture example %}
20 <div class="spinner-border" role="status">
21   <span class="sr-only">Loading...</span>
22 </div>
23 {% endcapture %}
24 {% include example.html content=example %}
25
26 ### Colors
27
28 The border spinner uses `currentColor` for its `border-color`, meaning you can customize the color with [text color utilities][color]. You can use any of our text color utilities on the standard spinner.
29
30 {% capture example %}
31 {% for color in site.data.theme-colors %}
32 <div class="spinner-border text-{{ color.name }}" role="status">
33   <span class="sr-only">Loading...</span>
34 </div>{% endfor %}
35 {% endcapture %}
36 {% include example.html content=example %}
37
38 {% capture callout %}
39 **Why not use `border-color` utilities?** Each border spinner specifies a `transparent` border for at least one side, so `.border-{color}` utilities would override that.
40 {% endcapture %}
41 {% include callout.html content=callout type="info" %}
42
43 ## Growing spinner
44
45 If you don't fancy a border spinner, switch to the grow spinner. While it doesn't technically spin, it does repeatedly grow!
46
47 {% capture example %}
48 <div class="spinner-grow" role="status">
49   <span class="sr-only">Loading...</span>
50 </div>
51 {% endcapture %}
52 {% include example.html content=example %}
53
54 Once again, this spinner is built with `currentColor`, so you can easily change its appearance with [text color utilities][color]. Here it is in blue, along with the supported variants.
55
56 {% capture example %}
57 {% for color in site.data.theme-colors %}
58 <div class="spinner-grow text-{{ color.name }}" role="status">
59   <span class="sr-only">Loading...</span>
60 </div>{% endfor %}
61 {% endcapture %}
62 {% include example.html content=example %}
63
64 ## Alignment
65
66 Spinners in Bootstrap are built with `rem`s, `currentColor`, and `display: inline-flex`. This means they can easily be resized, recolored, and quickly aligned.
67
68 ### Margin
69
70 Use [margin utilities][margin] like `.m-5` for easy spacing.
71
72 {% capture example %}
73 <div class="spinner-border m-5" role="status">
74   <span class="sr-only">Loading...</span>
75 </div>
76 {% endcapture %}
77 {% include example.html content=example %}
78
79 ### Placement
80
81 Use [flexbox utilities][flex], [float utilities][float], or [text alignment][text] utilities to place spinners exactly where you need them in any situation.
82
83 #### Flex
84
85 {% capture example %}
86 <div class="d-flex justify-content-center">
87   <div class="spinner-border" role="status">
88     <span class="sr-only">Loading...</span>
89   </div>
90 </div>
91 {% endcapture %}
92 {% include example.html content=example %}
93
94 {% capture example %}
95 <div class="d-flex align-items-center">
96   <strong>Loading...</strong>
97   <div class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
98 </div>
99 {% endcapture %}
100 {% include example.html content=example %}
101
102 #### Floats
103
104 {% capture example %}
105 <div class="clearfix">
106   <div class="spinner-border float-right" role="status">
107     <span class="sr-only">Loading...</span>
108   </div>
109 </div>
110 {% endcapture %}
111 {% include example.html content=example %}
112
113 #### Text align
114
115 {% capture example %}
116 <div class="text-center">
117   <div class="spinner-border" role="status">
118     <span class="sr-only">Loading...</span>
119   </div>
120 </div>
121 {% endcapture %}
122 {% include example.html content=example %}
123
124 ## Size
125
126 Add `.spinner-border-sm` and `.spinner-grow-sm` to make a smaller spinner that can quickly be used within other components.
127
128 {% capture example %}
129 <div class="spinner-border spinner-border-sm" role="status">
130   <span class="sr-only">Loading...</span>
131 </div>
132 <div class="spinner-grow spinner-grow-sm" role="status">
133   <span class="sr-only">Loading...</span>
134 </div>
135 {% endcapture %}
136 {% include example.html content=example %}
137
138 Or, use custom CSS or inline styles to change the dimensions as needed.
139
140 {% capture example %}
141 <div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
142   <span class="sr-only">Loading...</span>
143 </div>
144 <div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">
145   <span class="sr-only">Loading...</span>
146 </div>
147 {% endcapture %}
148 {% include example.html content=example %}
149
150 ## Buttons
151
152 Use spinners within buttons to indicate an action is currently processing or taking place. You may also swap the text out of the spinner element and utilize button text as needed.
153
154 {% capture example %}
155 <button class="btn btn-primary" type="button" disabled>
156   <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
157   <span class="sr-only">Loading...</span>
158 </button>
159 <button class="btn btn-primary" type="button" disabled>
160   <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
161   Loading...
162 </button>
163 {% endcapture %}
164 {% include example.html content=example %}
165
166 {% capture example %}
167 <button class="btn btn-primary" type="button" disabled>
168   <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
169   <span class="sr-only">Loading...</span>
170 </button>
171 <button class="btn btn-primary" type="button" disabled>
172   <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
173   Loading...
174 </button>
175 {% endcapture %}
176 {% include example.html content=example %}
177
178
179 [color]:   {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/
180 [display]: {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/display/
181 [flex]:    {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/flex/
182 [float]:   {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/float/
183 [margin]:  {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/spacing/
184 [sizing]:  {{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/sizing/
185 [text]:    {{ site.baseurl }}/docs/{{ site.docs_version }}/content/typography/