Spinners show that something is loading or working in the background. They help users know to wait.
Spinner components in Bootsrap
<div class="spinner-border" role="status"> <span class="visually-hidden">Loading...</span> </div>
Use spinner-border for a rotating border spinner.
Always include role="status" and a span with visually-hidden text for accessibility.
<div class="spinner-border" role="status"> <span class="visually-hidden">Loading...</span> </div>
text-primary class.<div class="spinner-border text-primary" role="status"> <span class="visually-hidden">Loading...</span> </div>
spinner-border-sm class.<div class="spinner-border spinner-border-sm" role="status"> <span class="visually-hidden">Loading...</span> </div>
spinner-grow and text-success.<div class="spinner-grow text-success" role="status"> <span class="visually-hidden">Loading...</span> </div>
This page shows three spinners centered vertically and horizontally. Each spinner uses different styles and colors to demonstrate Bootstrap spinner components. The visually-hidden text helps screen readers understand the spinner means loading.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Spinner Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="d-flex flex-column align-items-center justify-content-center vh-100 gap-3"> <h1>Loading Data</h1> <div class="spinner-border text-primary" role="status" aria-label="Loading"> <span class="visually-hidden">Loading...</span> </div> <div class="spinner-grow text-success" role="status" aria-label="Loading"> <span class="visually-hidden">Loading...</span> </div> <div class="spinner-border spinner-border-sm text-danger" role="status" aria-label="Loading"> <span class="visually-hidden">Loading...</span> </div> </main> </body> </html>
Spinners do not show progress amount, only that something is happening.
Use aria-label or role="status" with hidden text for screen reader support.
Customize spinner size with spinner-border-sm or CSS if needed.
Spinners visually show loading or processing states.
Bootstrap offers spinner-border and spinner-grow styles.
Always add accessible text inside spinners for screen readers.
Practice
Solution
Step 1: Understand spinner usage
Spinners are used to indicate that something is loading or processing in the background.Step 2: Identify spinner purpose in Bootstrap
Bootstrap spinner components visually show this loading state to users.Final Answer:
To show a loading or processing state visually -> Option AQuick Check:
Spinner = Loading indicator [OK]
- Thinking spinners are for decoration only
- Confusing spinners with buttons
- Using spinners for static images
Solution
Step 1: Recall Bootstrap spinner classes
Bootstrap provides two main spinner classes:spinner-borderandspinner-grow.Step 2: Identify the border spinner class
The classspinner-bordercreates a spinner with a border style.Final Answer:
spinner-border -> Option CQuick Check:
Border spinner class = spinner-border [OK]
- Using spinner-grow for border spinner
- Typing class names incorrectly
- Confusing spinner classes with button classes
<div class="spinner-grow text-primary" role="status"> <span class="visually-hidden">Loading...</span> </div>
Solution
Step 1: Analyze spinner-grow and text-primary classes
Thespinner-growclass creates a growing spinner animation. Thetext-primaryclass applies Bootstrap's primary blue color.Step 2: Understand role and visually-hidden span
Therole="status"helps screen readers. Thespanwithvisually-hiddenhides the text visually but keeps it accessible.Final Answer:
A growing spinner with blue color and hidden accessible text -> Option AQuick Check:
spinner-grow + text-primary = blue growing spinner [OK]
- Thinking text-primary changes text color only
- Expecting visible text from visually-hidden span
- Confusing spinner-grow with spinner-border
<div class="spinner-border" aria-label="Loading"> <span>Loading...</span> </div>
Solution
Step 1: Check accessibility best practices for spinners
Bootstrap recommends adding aspanwithvisually-hiddenclass inside spinners to provide accessible text for screen readers.Step 2: Analyze given code
Thespaninside the spinner lacks thevisually-hiddenclass, so the text is visible visually, which is not ideal.Final Answer:
Span should have class visually-hidden for screen readers -> Option DQuick Check:
Accessible text inside spinner needs visually-hidden class [OK]
- Omitting visually-hidden class
- Using aria-label instead of role
- Confusing aria-label with aria-labelledby
Solution
Step 1: Choose spinner-grow for growing animation
The question asks for a spinner that grows in size, sospinner-growis the correct class.Step 2: Apply danger color and accessibility
Thetext-dangerclass applies the red color. Therole="status"andspanwithvisually-hiddenprovide accessible loading text.Step 3: Verify all requirements
Loading... usesspinner-grow,text-danger,role="status", and hidden accessible text correctly.Final Answer:
<div class="spinner-grow text-danger" role="status"><span class="visually-hidden">Loading...</span></div> -> Option BQuick Check:
Growing spinner + danger color + accessible text =Loading...[OK]
- Using spinner-border instead of spinner-grow
- Missing role="status"
- Not hiding accessible text visually
Ready to prove it?
Pass the test and this pattern moves unknown
