Bootstrap 4 spinners show the loading state of the components.
Steps to create bootstrap 4 spinners.
.spinner-border
to the spinner loader container base class.
General Syntax
<div class="spinner-border">
<span class="sr-only">Loading...</span>
</div>
Source Code
<div class="container text-center mt-4">
<h3 class="text-center">Bootstrap Spinner</h3>
<div class="spinner-border">
<span class="sr-only">Loading...</span>
</div>
</div>
Source Code: Output
Note:Bootstrap spinner is used to show loading state of the web componet inside the web project.
Bootstrap spinners are used to show the loading state of the web component.
Follow the following steps to create bootstrap 4 colored spinners.
.spinner-border
to spinner loader container.
.text-*
to the spinner container.
.text-primary
,.text-secondary
,.text-success
,.text-danger
,.text-warning
,.text-info
,.text-light
,,text-dark
.
General Syntax
<div class="spinner-border text-*" role="status">
<span class="sr-only">Loading...</span>
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center my-5">Colored Spinners</h2>
<div class="row">
<div class="col">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="col">
<div class="spinner-border text-secondary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</div>
Source Code: Output
Remember: Bootstrap provides different text utilities classes that is used to provide different color to the spinners.
Growing spinners glows repeatedly after a certain time duration.It does not spin.To make growing spinner,add
.spinner-grow
tp spinner container.
Source Code
<div class="container text-center mt-4">
<h2 class="text-center my-5">Growing Spinners</h2>
<div class="row">
<div class="col">
<div class="spinner-grow text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="col">
<div class="spinner-grow text-secondary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Note:
To create growing spinner,assign .spinner-grow
to the spinner container.
Steps to create colored growing spinners:
.spinner-grow
to spinner loader container.
.text-*
to the spinner container.
.text-primary
,.text-secondary
,.text-success
,.text-danger
,.text-warning
,.text-info
,.text-light
,,text-dark
.
General Syntax
<div class="spinner-grow text-*">
<span class="sr-only">Loading...</span>
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center my-5">Growing Spinners</h2>
<div class="row">
<div class="col">
<div class="spinner-grow text-secondary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="col">
<div class="spinner-grow text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="col">
<div class="spinner-grow text-danger" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Note: Use bootstrap text utility classes to make colorful growing spinners.
To create smaller spinner size ,use either .spinner-border-sm
or .spinner-grow-sm class
.
General Syntax
<div class="spinner-border spinner-border-sm">
<span class="sr-only">Loading...</span>
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center">Spinner Size</h2>
<div class="row">
<div class="col">
<div class="spinner-border text-primary spinner-border-sm" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="col">
<div class="spinner-border text-secondary spinner-border-sm" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Note: In the above example, use .spinner-grow-sm
or .spinner-border-sm
to make smaller spinner size.
General Syntax
<button class="btn btn-*">
<span class="spinner-border spinner-border-sm"></span>
</button>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center my-5">Spinner Buttons</h2>
<div class="row">
<div class="col mb-2">
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
</div>
<div class="col mb-2">
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
</div>
<div class="col mb-2">
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
</div>
<div class="col mb-2">
<button class="btn btn-primary" disabled>
<span class="spinner-grow spinner-grow-sm"></span>
Loading..
</button>
</div>
</div>
</div>
Source Code: Output
flexbox utilities, float utilities, or text alignment are very helpful utilities class that placed spinner to any where in the web page.
General Syntax
<div class="d-flex justify-content-center">
<div class="spinner-border"></div>
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center">Growing Spinner Alignment</h2>
<div class="row">
<div class="col-sm-12 col-12">
<!-- Center Alignment -->
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div><!--/col-sm-12 col-12"-->
</div><!--/row-->
</div><!--/container-->
Source Code: Output
Note:In the above example flexbox utility class is used to align the spinners.
General Syntax
<div class="spinner-border float-right">
<span class="sr-only">Loading...</span>
</div>
Source Code
<div class="container text-center mt-4">
<h2 class="text-center">Spinner Alignment Using Float</h2>
<div class="clearfix">
<div class="spinner-border float-right" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
Source Code: Output
Note:
In the above example, .float-right
is used to align the spinner to the right of the web page.
General Syntax
<div class="text-center">
<div class="spinner-border">
<span class="sr-only">Loading...</span>
</div>
</div>
Source Code
<div class="container text-center mt-4">
<div class="text-center">
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
Source Code: Output
Note:
In the above example, .text-center
is used to align the spinner to the right of the web page.