Buttons help users click to do things on a website. Different styles make buttons look special and show what they do.
Button styles and variants in Bootsrap
<button type="button" class="btn btn-primary">Primary</button>
Use btn class to start a button style.
Add btn-variant classes like btn-primary, btn-secondary, btn-success, etc. to change color and meaning.
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-success btn-lg">Large Success</button>
This page shows different Bootstrap button styles and sizes. Each button uses a class to change its color and size. You can see how buttons look for different meanings and importance.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Button Styles</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="p-4"> <h1>Button Styles and Variants</h1> <section class="mb-3"> <button type="button" class="btn btn-primary">Primary</button> <button type="button" class="btn btn-secondary">Secondary</button> <button type="button" class="btn btn-success">Success</button> <button type="button" class="btn btn-danger">Danger</button> <button type="button" class="btn btn-warning">Warning</button> <button type="button" class="btn btn-info">Info</button> <button type="button" class="btn btn-light">Light</button> <button type="button" class="btn btn-dark">Dark</button> </section> <section> <button type="button" class="btn btn-primary btn-lg">Large Primary</button> <button type="button" class="btn btn-secondary btn-sm">Small Secondary</button> </section> </main> </body> </html>
Use semantic type="button" to make buttons accessible.
Bootstrap buttons respond to keyboard and screen readers by default.
You can combine size classes like btn-lg or btn-sm with color variants.
Buttons use btn plus a variant class to change color and meaning.
Variants include primary, secondary, success, danger, warning, info, light, and dark.
You can change button size with btn-lg and btn-sm.
Practice
Solution
Step 1: Understand Bootstrap button base class
All Bootstrap buttons require the base classbtnto apply button styles.Step 2: Identify the variant for blue color
Thebtn-primaryclass applies the blue color variant to the button.Final Answer:
<button class='btn btn-primary'> -> Option DQuick Check:
Blue primary button = btn btn-primary [OK]
- Using btn-danger for blue instead of red
- Omitting the base btn class
- Confusing btn-secondary with btn-primary
Solution
Step 1: Identify the success variant class
The green color for success buttons is applied withbtn-success.Step 2: Choose the small size modifier
The classbtn-smmakes the button smaller in size.Final Answer:
<button class='btn btn-success btn-sm'>Success</button> -> Option BQuick Check:
Small green button = btn-success btn-sm [OK]
- Using btn-lg instead of btn-sm for small size
- Mixing btn-primary with success text
- Forgetting the btn base class
<button class='btn btn-warning btn-lg'>Warning</button>
Solution
Step 1: Identify the variant class
The classbtn-warningapplies a yellow/orange color to the button.Step 2: Understand the size modifier
Thebtn-lgclass makes the button larger but does not affect color.Final Answer:
Yellow -> Option AQuick Check:
btn-warning = Yellow color [OK]
- Confusing btn-warning with btn-danger (red)
- Thinking btn-lg changes color
- Mixing btn-primary with warning text
<button class='btn btn-info btn-small'>Info</button>
Solution
Step 1: Check variant class validity
btn-infois a valid Bootstrap variant for a light blue button.Step 2: Verify size class correctness
Bootstrap usesbtn-smandbtn-lgfor sizes, notbtn-small.Final Answer:
btn-small is not a valid size class -> Option CQuick Check:
Size classes are btn-sm or btn-lg only [OK]
- Using btn-small instead of btn-sm
- Assuming btn-info is invalid
- Forgetting btn base class (not the case here)
Solution
Step 1: Understand Bootstrap button variants
Bootstrap does not have a combined variant likebtn-dark-warning. Variants are separate classes likebtn-warning(yellow) orbtn-dark(dark gray).Step 2: Choose the correct variant for dark theme
The dark theme is applied bybtn-dark. Addingbtn-warningalongside it causes conflicting colors.Step 3: Apply large size modifier
Thebtn-lgclass correctly makes the button large.Final Answer:
btn btn-dark btn-lg -> Option AQuick Check:
Use one variant class plus size class [OK]
- Combining multiple variant classes causing style conflicts
- Using non-existent combined variant classes
- Forgetting the btn base class
Ready to prove it?
Pass the test and this pattern moves unknown
