Loading animation
Bootstrap 5 Loading animation component
Responsive loading animation built with Bootstrap 5. Enhance user experience with intuitive, responsive loading animations for seamless web design.
Icons
Basic example
Use the border spinners for a lightweight loading indicator.
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
MDB “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>
.
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.
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-secondary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-success" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-danger" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-warning" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-info" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-light" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-dark" role="status">
<span class="visually-hidden">Loading...</span>
</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.
Loading management
Basic example
Loading is automatically initialized on page load if you add the data-mdb-loading-init
attribute to your element.
By default, Loading attaches to the body element. If you want to attach Loading to a specific element, you need to
add data-mdb-parent-selector
with the class or ID of your parent. Alternatively, you can achieve this via
JavaScript using the parentSelector
option.
<div id="loading-test" style="height: 300px; width: 100%;">
<div data-mdb-loading-init data-mdb-parent-selector="#loading-test">
<div class="spinner-border loading-icon" role="status"></div>
<span class="loading-text">Loading...</span>
</div>
</div>
// Initialization for ES Users
import { Loading, initMDB } from "mdb-ui-kit";
initMDB({ Loading });
JavaScript init
You can initialize the Loading component in JavaScript using the constructor:
new Loading(element, options)
.
<div id="loading-test-1" style="height: 300px; width: 100%">
<div class="loading-mdb">
<div class="spinner-border loading-icon" role="status"></div>
<span class="loading-text">Loading...</span>
</div>
</div>
import { Loading, initMDB } from "mdb-ui-kit";
const loadingmdb = document.querySelector('.loading-mdb');
const newloading = new Loading(loadingmdb, {
parentSelector: '#loading-test-1'
});
const loadingmdb = document.querySelector('.loading-mdb');
const newloading = new mdb.Loading(loadingmdb, {
parentSelector: '#loading-test-1'
});
Colors
You can set a different colors to loader with color utilities for example .text-primary
.
<div id="loading-test-2" style="height: 300px; width: 100%">
<div class="loading-colors">
<div class="spinner-border loading-icon text-success" role="status"></div>
<span class="loading-text text-success">Loading...</span>
</div>
</div>
import { Loading, initMDB } from "mdb-ui-kit";
const loadingColors = document.querySelector('.loading-colors');
const newloading = new Loading(loadingColors, {
parentSelector: '#loading-test-2'
});
const loadingColors = document.querySelector('.loading-colors');
const newloading = new mdb.Loading(loadingColors, {
parentSelector: '#loading-test-2'
});