📖 Scenario: You are creating a simple webpage that shows different button styles using Bootstrap. This will help users see how buttons can look with different colors and sizes.
🎯 Goal: Build a webpage with a header and four buttons. Each button uses a different Bootstrap style variant: primary, secondary, success, and danger.
📋 What You'll Learn
Use Bootstrap 5 CSS from CDN
Create a header with the text 'Bootstrap Button Variants'
Add four buttons with classes: btn-primary, btn-secondary, btn-success, btn-danger
Buttons should have the text: 'Primary', 'Secondary', 'Success', 'Danger'
Use semantic HTML and include lang, charset, and viewport meta tags
💡 Why This Matters
🌍 Real World
Buttons are everywhere on websites and apps. Knowing how to style them with Bootstrap helps you build user-friendly interfaces quickly.
💼 Career
Web developers often use Bootstrap to create consistent and accessible buttons that work well on all devices.
Progress0 / 4 steps
1
Create the basic HTML structure
Create a basic HTML5 document with lang="en", <head> containing <meta charset="UTF-8"> and <meta name="viewport" content="width=device-width, initial-scale=1">. Add a <body> with a <header> containing an <h1> with the text Bootstrap Button Variants.
Bootsrap
Hint
Remember to include the lang attribute in the <html> tag and the required meta tags inside <head>.
2
Add Bootstrap CSS link
Inside the <head>, add the Bootstrap 5 CSS CDN link: <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">.
Bootsrap
Hint
Use the official Bootstrap 5 CSS CDN link inside the <head> section.
3
Add four Bootstrap buttons with different variants
Inside the <body> after the <header>, add four <button> elements with classes btn btn-primary, btn btn-secondary, btn btn-success, and btn btn-danger. The buttons should have the text Primary, Secondary, Success, and Danger respectively.
Bootsrap
Hint
Use the Bootstrap button classes btn plus the variant classes like btn-primary on each button.
4
Make buttons accessible and add spacing
Add aria-label attributes to each button matching their text (e.g., aria-label="Primary button"). Also, add the Bootstrap class m-2 to each button to add margin spacing around them.
Bootsrap
Hint
Use the aria-label attribute for accessibility and add the Bootstrap margin class m-2 to each button.
Practice
(1/5)
1. Which Bootstrap class combination correctly creates a blue primary button?
easy
A. btn btn-secondary
B. btn btn-danger
C. btn btn-warning
D. btn btn-primary
Solution
Step 1: Understand Bootstrap button base class
All Bootstrap buttons require the base class btn to apply button styles.
Step 2: Identify the variant for blue color
The btn-primary class applies the blue color variant to the button.
Final Answer:
<button class='btn btn-primary'> -> Option D
Quick Check:
Blue primary button = btn btn-primary [OK]
Hint: Primary buttons always use btn-primary class [OK]
Common Mistakes:
Using btn-danger for blue instead of red
Omitting the base btn class
Confusing btn-secondary with btn-primary
2. Which of the following is the correct syntax to create a small green success button in Bootstrap?
easy
A. <button class='btn btn-primary btn-sm'>Success</button>
B. <button class='btn btn-success btn-sm'>Success</button>
C. <button class='btn btn-success btn-lg'>Success</button>
D. <button class='btn btn-danger btn-sm'>Success</button>
Solution
Step 1: Identify the success variant class
The green color for success buttons is applied with btn-success.
Step 2: Choose the small size modifier
The class btn-sm makes the button smaller in size.
Final Answer:
<button class='btn btn-success btn-sm'>Success</button> -> Option B
Quick Check:
Small green button = btn-success btn-sm [OK]
Hint: Use btn-sm for small size and btn-success for green [OK]
Common Mistakes:
Using btn-lg instead of btn-sm for small size
Mixing btn-primary with success text
Forgetting the btn base class
3. What color will the button have when using this code?