-
Hajipur, Bihar, 844101
Spinners are small animated icons that indicate a process is ongoing, such as loading content, submitting forms, or fetching data. They are useful for improving the user experience, as they reassure users that an operation is in progress rather than leaving them guessing. Bootstrap 4 provides built-in spinner components that are easy to implement, flexible, and visually consistent. This tutorial covers everything you need to know about BS4 spinners.
A spinner is an animated visual element that loops continuously to represent an ongoing process. Unlike progress bars, which display the percentage completed, spinners do not show exact progress but give users immediate feedback that something is happening in the background. Bootstrap 4 offers two types of spinners: border spinners and growing spinners.
Border spinners are circular indicators with a rotating border. They are created using the .spinner-border class. You can change the color using contextual classes like .text-primary or .text-success.
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
role="status" makes the spinner accessible.
.sr-only provides screen readers with a descriptive text without displaying it visually.
Border spinners are often used in buttons, modals, or standalone loading indicators.
Growing spinners expand and contract in a pulsating manner. They are created using the .spinner-grow class. Like border spinners, contextual classes can change their color.
<div class="spinner-grow text-success" role="status">
<span class="sr-only">Loading...</span>
</div>
Growing spinners offer a softer visual effect and are useful for lightweight loading indicators.
Bootstrap 4 allows you to adjust spinner sizes to fit different contexts. By default, spinners are medium-sized. To make them smaller, add .spinner-border-sm or .spinner-grow-sm for small spinners.
<div class="spinner-border spinner-border-sm text-danger" role="status">
<span class="sr-only">Loading...</span>
</div>
<div class="spinner-grow spinner-grow-sm text-warning" role="status">
<span class="sr-only">Loading...</span>
</div>
Smaller spinners are often used inside buttons or alongside text.
Spinners are commonly used inside buttons to indicate actions like form submission or data processing. They can be combined with button text for clarity.
<button class="btn btn-primary" type="button" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Loading...
</button>
Here, the button is disabled to prevent repeated clicks, and the spinner communicates that an action is ongoing.
Bootstrap 4 supports multiple contextual colors for spinners, including .text-primary, .text-secondary, .text-success, .text-danger, .text-warning, .text-info, .text-light, and .text-dark.
<div class="spinner-border text-primary" role="status"></div>
<div class="spinner-border text-success" role="status"></div>
<div class="spinner-grow text-warning" role="status"></div>
Using colors can help indicate the type of process or match branding colors.
Accessibility is important when using spinners. Always include:
role="status" on the spinner element
A visually hidden text description using .sr-only
Avoid relying solely on color to communicate status
These practices ensure that assistive technologies can interpret the spinner correctly.
Spinners can be used in multiple contexts:
Standalone Loading Indicators: Centered on the page while fetching data.
Inside Buttons: Shows that a button action is in progress.
Inline with Text: Indicates a small process next to a sentence or label.
Loading data <div class="spinner-border spinner-border-sm text-primary" role="status"></div>
This placement makes the spinner unobtrusive yet informative.
You can display multiple spinners together for aesthetic or functional purposes. For example, a loading screen with three growing spinners in a row.
<div class="d-flex justify-content-around">
<div class="spinner-grow text-primary" role="status"></div>
<div class="spinner-grow text-success" role="status"></div>
<div class="spinner-grow text-danger" role="status"></div>
</div>
This creates a visually engaging loading section for dashboards or modals.
Spinners can be customized with CSS:
Adjust width and height for different sizes
Add margins or padding for spacing
Change animation speed using animation-duration in CSS
<style>
.custom-spinner {
width: 3rem;
height: 3rem;
animation-duration: 1.5s;
}
</style>
<div class="spinner-border text-info custom-spinner" role="status"></div>
Customization helps spinners fit seamlessly into your website design.
Use spinners only when an operation takes noticeable time.
Combine spinners with text when possible for clarity.
Avoid overusing multiple spinners on the same page.
Ensure spinners are accessible to all users.
Match spinner size and style to the context (button, inline, or page-level).
Form Submission: Show spinner inside a submit button.
Data Fetching: Display spinner while loading tables or charts.
Content Loading: Centered spinner on a modal or card while waiting for content.
Inline Indicators: Small spinner next to a label to indicate a small process.
Multiple Processes: Different colored spinners representing parallel tasks.
Bootstrap 4 spinners are flexible, lightweight, and visually effective indicators for ongoing processes. They come in border and growing types, with multiple sizes and colors. Spinners can be used inside buttons, inline with text, or as standalone indicators. By using spinners effectively, you can enhance user experience, provide clear feedback, and create polished, professional interfaces.
Create a basic border spinner with the Primary color.
Create a growing spinner with the Success color.
Create a small border spinner using .spinner-border-sm with the Danger color.
Create a small growing spinner using .spinner-grow-sm with the Warning color.
Create a border spinner inside a disabled Primary button with the text “Loading...”.
Create three growing spinners of different colors (Primary, Success, Danger) displayed in a row.
Create an inline spinner next to a sentence, e.g., “Fetching data,” using a small border spinner.
Create a spinner with a custom size of 3rem and a slower animation speed using CSS.
Create multiple spinners on a page representing parallel processes, each with a different color and type.
Create a spinner with proper accessibility attributes (role="status" and .sr-only) inside a button labeled “Processing.”