About

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.

For accessibility purposes, each loader here includes role="status" and a nested <span class="visually-hidden">Loading...</span>.

The animation effect of this component is dependent on the prefers-reduced-motion media query. See the reduced motion section of our accessibility documentation.

Border spinner

Use the border spinners for a lightweight loading indicator.

Spinners - 图1

  1. <div class="spinner-border" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>

Colors

The border spinner uses currentColor for its border-color, meaning you can customize the color with text color utilities. You can use any of our text color utilities on the standard spinner.

Spinners - 图2

  1. <div class="spinner-border text-primary" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>
  4. <div class="spinner-border text-secondary" role="status">
  5. <span class="visually-hidden">Loading...</span>
  6. </div>
  7. <div class="spinner-border text-success" role="status">
  8. <span class="visually-hidden">Loading...</span>
  9. </div>
  10. <div class="spinner-border text-danger" role="status">
  11. <span class="visually-hidden">Loading...</span>
  12. </div>
  13. <div class="spinner-border text-warning" role="status">
  14. <span class="visually-hidden">Loading...</span>
  15. </div>
  16. <div class="spinner-border text-info" role="status">
  17. <span class="visually-hidden">Loading...</span>
  18. </div>
  19. <div class="spinner-border text-light" role="status">
  20. <span class="visually-hidden">Loading...</span>
  21. </div>
  22. <div class="spinner-border text-dark" role="status">
  23. <span class="visually-hidden">Loading...</span>
  24. </div>

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.

Growing spinner

If you don’t fancy a border spinner, switch to the grow spinner. While it doesn’t technically spin, it does repeatedly grow!

Spinners - 图3

  1. <div class="spinner-grow" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>

Once again, this spinner is built with currentColor, so you can easily change its appearance with text color utilities. Here it is in blue, along with the supported variants.

Spinners - 图4

  1. <div class="spinner-grow text-primary" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>
  4. <div class="spinner-grow text-secondary" role="status">
  5. <span class="visually-hidden">Loading...</span>
  6. </div>
  7. <div class="spinner-grow text-success" role="status">
  8. <span class="visually-hidden">Loading...</span>
  9. </div>
  10. <div class="spinner-grow text-danger" role="status">
  11. <span class="visually-hidden">Loading...</span>
  12. </div>
  13. <div class="spinner-grow text-warning" role="status">
  14. <span class="visually-hidden">Loading...</span>
  15. </div>
  16. <div class="spinner-grow text-info" role="status">
  17. <span class="visually-hidden">Loading...</span>
  18. </div>
  19. <div class="spinner-grow text-light" role="status">
  20. <span class="visually-hidden">Loading...</span>
  21. </div>
  22. <div class="spinner-grow text-dark" role="status">
  23. <span class="visually-hidden">Loading...</span>
  24. </div>

Alignment

Spinners in Bootstrap are built with rems, currentColor, and display: inline-flex. This means they can easily be resized, recolored, and quickly aligned.

Margin

Use margin utilities like .m-5 for easy spacing.

Spinners - 图5

  1. <div class="spinner-border m-5" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>

Placement

Use flexbox utilities, float utilities, or text alignment utilities to place spinners exactly where you need them in any situation.

Flex

Spinners - 图6

  1. <div class="d-flex justify-content-center">
  2. <div class="spinner-border" role="status">
  3. <span class="visually-hidden">Loading...</span>
  4. </div>
  5. </div>

Spinners - 图7

  1. <div class="d-flex align-items-center">
  2. <strong>Loading...</strong>
  3. <div class="spinner-border ms-auto" role="status" aria-hidden="true"></div>
  4. </div>

Floats

Spinners - 图8

  1. <div class="clearfix">
  2. <div class="spinner-border float-end" role="status">
  3. <span class="visually-hidden">Loading...</span>
  4. </div>
  5. </div>

Text align

Spinners - 图9

  1. <div class="text-center">
  2. <div class="spinner-border" role="status">
  3. <span class="visually-hidden">Loading...</span>
  4. </div>
  5. </div>

Size

Add .spinner-border-sm and .spinner-grow-sm to make a smaller spinner that can quickly be used within other components.

Spinners - 图10

  1. <div class="spinner-border spinner-border-sm" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>
  4. <div class="spinner-grow spinner-grow-sm" role="status">
  5. <span class="visually-hidden">Loading...</span>
  6. </div>

Or, use custom CSS or inline styles to change the dimensions as needed.

Spinners - 图11

  1. <div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
  2. <span class="visually-hidden">Loading...</span>
  3. </div>
  4. <div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">
  5. <span class="visually-hidden">Loading...</span>
  6. </div>

Buttons

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.

Spinners - 图12

  1. <button class="btn btn-primary" type="button" disabled>
  2. <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
  3. <span class="visually-hidden">Loading...</span>
  4. </button>
  5. <button class="btn btn-primary" type="button" disabled>
  6. <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
  7. Loading...
  8. </button>

Spinners - 图13

  1. <button class="btn btn-primary" type="button" disabled>
  2. <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
  3. <span class="visually-hidden">Loading...</span>
  4. </button>
  5. <button class="btn btn-primary" type="button" disabled>
  6. <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
  7. Loading...
  8. </button>

Sass

Variables

  1. $spinner-width: 2rem;
  2. $spinner-height: $spinner-width;
  3. $spinner-vertical-align: -.125em;
  4. $spinner-border-width: .25em;
  5. $spinner-animation-speed: .75s;
  6. $spinner-width-sm: 1rem;
  7. $spinner-height-sm: $spinner-width-sm;
  8. $spinner-border-width-sm: .2em;

Keyframes

Used for creating the CSS animations for our spinners. Included in scss/_spinners.scss.

  1. @keyframes spinner-border {
  2. to { transform: rotate(360deg) #{"/* rtl:ignore */"}; }
  3. }
  1. @keyframes spinner-grow {
  2. 0% {
  3. transform: scale(0);
  4. }
  5. 50% {
  6. opacity: 1;
  7. transform: none;
  8. }
  9. }