📖 Scenario: You are building a simple web page that shows a loading spinner while content is loading. This spinner will help users know that something is happening in the background.
🎯 Goal: Build a web page with a Bootstrap spinner component centered on the page. The spinner should be visible and use the Bootstrap classes correctly.
📋 What You'll Learn
Use Bootstrap 5 spinner component
Center the spinner horizontally and vertically on the page
Use semantic HTML5 structure
Include necessary meta tags for responsive design
Ensure the spinner has an accessible label for screen readers
💡 Why This Matters
🌍 Real World
Loading spinners are common in websites and apps to show users that content is loading or a process is running.
💼 Career
Knowing how to use Bootstrap components and utilities helps you quickly build responsive and accessible UI elements in professional web projects.
Progress0 / 4 steps
1
Create the basic HTML structure
Write the basic HTML5 skeleton with lang="en", meta charset="UTF-8", and meta viewport tags inside the <head>. Also add a <main> element inside the <body>.
Bootsrap
Hint
Start with a simple HTML5 page structure including <html>, <head>, and <body>. Use lang="en" in the <html> tag for accessibility.
2
Add Bootstrap CSS link
Inside the <head>, add the Bootstrap 5 CSS CDN link: https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css using a <link> tag with rel="stylesheet".
Bootsrap
Hint
Use a <link> tag with rel="stylesheet" and the Bootstrap CSS URL as the href.
3
Add the Bootstrap spinner inside <main>
Inside the <main> element, add a <div> with classes spinner-border and text-primary. Add role="status" and inside it add a <span> with class visually-hidden containing the text Loading... for accessibility.
Bootsrap
Hint
Use the Bootstrap spinner classes exactly as shown. The role="status" and visually-hidden span help screen readers.
4
Center the spinner vertically and horizontally
Add Bootstrap utility classes d-flex, justify-content-center, and align-items-center to the <main> element. Also add min-vh-100 to make it fill the full viewport height.
Bootsrap
Hint
Use Bootstrap flexbox utility classes on the <main> tag to center the spinner both vertically and horizontally.
Practice
(1/5)
1. What is the main purpose of Bootstrap spinner components?
easy
A. To show a loading or processing state visually
B. To create navigation menus
C. To style buttons with colors
D. To add images to the page
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 A
Quick Check:
Spinner = Loading indicator [OK]
Hint: Spinners always mean loading or waiting [OK]
Common Mistakes:
Thinking spinners are for decoration only
Confusing spinners with buttons
Using spinners for static images
2. Which of the following is the correct Bootstrap class to create a border spinner?
easy
A. spinner-grow
B. spinner-spin
C. spinner-border
D. spinner-circle
Solution
Step 1: Recall Bootstrap spinner classes
Bootstrap provides two main spinner classes: spinner-border and spinner-grow.
Step 2: Identify the border spinner class
The class spinner-border creates a spinner with a border style.
Final Answer:
spinner-border -> Option C
Quick Check:
Border spinner class = spinner-border [OK]
Hint: Border spinner always uses spinner-border class [OK]
Common Mistakes:
Using spinner-grow for border spinner
Typing class names incorrectly
Confusing spinner classes with button classes
3. What will be the visible result of this code snippet?
C. Missing role="status" attribute for accessibility
D. Span should have class visually-hidden for screen readers
Solution
Step 1: Check accessibility best practices for spinners
Bootstrap recommends adding a span with visually-hidden class inside spinners to provide accessible text for screen readers.
Step 2: Analyze given code
The span inside the spinner lacks the visually-hidden class, so the text is visible visually, which is not ideal.
Final Answer:
Span should have class visually-hidden for screen readers -> Option D
Quick Check:
Accessible text inside spinner needs visually-hidden class [OK]
Hint: Use visually-hidden class on spinner text for accessibility [OK]
Common Mistakes:
Omitting visually-hidden class
Using aria-label instead of role
Confusing aria-label with aria-labelledby
5. You want to create a spinner that grows in size and uses the Bootstrap danger color with accessible text. Which code snippet correctly achieves this?
hard
A.
Loading...
B.
Loading...
C.
Loading...
D.
Loading...
Solution
Step 1: Choose spinner-grow for growing animation
The question asks for a spinner that grows in size, so spinner-grow is the correct class.
Step 2: Apply danger color and accessibility
The text-danger class applies the red color. The role="status" and span with visually-hidden provide accessible loading text.
Step 3: Verify all requirements
Loading... uses spinner-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 B
Quick Check:
Growing spinner + danger color + accessible text =