Button sizes help make buttons look right for different parts of your page. They can be small, normal, or large to fit the space and importance.
Button sizes in Bootsrap
<button class="btn btn-primary btn-sm">Small Button</button> <button class="btn btn-primary">Default Button</button> <button class="btn btn-primary btn-lg">Large Button</button>
Use btn-sm for small buttons and btn-lg for large buttons.
If you don't add a size class, the button will be the default size.
<button class="btn btn-secondary btn-sm">Small Button</button>
<button class="btn btn-success">Default Button</button>
<button class="btn btn-danger btn-lg">Large Button</button>
This page shows three buttons in different sizes using Bootstrap classes. The small button is compact, the default button is normal size, and the large button is bigger for emphasis. Each button has an accessible label.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Button Sizes</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 Sizes Example</h1> <button type="button" class="btn btn-primary btn-sm" aria-label="Small button">Small Button</button> <button type="button" class="btn btn-primary" aria-label="Default button">Default Button</button> <button type="button" class="btn btn-primary btn-lg" aria-label="Large button">Large Button</button> </main> </body> </html>
Always use semantic <button> elements for buttons to keep accessibility.
Use aria-label if the button text is not descriptive enough for screen readers.
Test button sizes on different screen sizes to make sure they are easy to tap on mobile devices.
Button sizes in Bootstrap use btn-sm for small and btn-lg for large buttons.
Default buttons have no size class and fit most uses.
Choosing the right button size helps users notice and use buttons easily.
Practice
<button class="btn btn-primary ?">Click</button>Solution
Step 1: Understand Bootstrap button size classes
Bootstrap usesbtn-smfor small buttons andbtn-lgfor large buttons. The default button has no size class.Step 2: Identify the class for smaller buttons
The classbtn-smis the correct one to make a button smaller than default.Final Answer:
btn-sm -> Option AQuick Check:
Small button class = btn-sm [OK]
- Using btn-lg for small buttons
- Using btn-default which is not a size class
- Using btn-small which does not exist
<button class="btn btn-primary ?">Submit</button>Solution
Step 1: Recall Bootstrap large button class
Bootstrap usesbtn-lgto make buttons larger than the default size.Step 2: Match the correct class syntax
The correct class isbtn-lg. Other options likebtn-large,btn-big, orbtn-xlare not valid Bootstrap classes.Final Answer:
btn-lg -> Option AQuick Check:
Large button class = btn-lg [OK]
- Using btn-large instead of btn-lg
- Using btn-big which is not a Bootstrap class
- Using btn-xl which does not exist in Bootstrap
<button class="btn btn-primary">Default</button> <button class="btn btn-primary btn-sm">Small</button>
Solution
Step 1: Identify button classes and their sizes
The first button has onlybtn btn-primary, so it is default size. The second button addsbtn-sm, making it smaller.Step 2: Understand visual difference
The second button will appear smaller than the first because of thebtn-smclass.Final Answer:
The first button is default size, the second is smaller -> Option DQuick Check:
btn-sm makes button smaller [OK]
- Thinking btn-sm makes button larger
- Assuming both buttons look the same
- Confusing btn-sm with btn-lg
<button class="btn btn-primary btn-small">Click Me</button>
Solution
Step 1: Check Bootstrap size classes
Bootstrap usesbtn-smandbtn-lgfor sizes.btn-smallis not valid.Step 2: Verify other classes and syntax
Thebtn-primaryandbtnclasses are correct and present. The button tag is properly closed.Final Answer:
btn-small is not a valid Bootstrap size class -> Option CQuick Check:
Use btn-sm or btn-lg for sizes [OK]
- Using btn-small instead of btn-sm
- Thinking btn-primary can't combine with size classes
- Missing btn class in button
Solution
Step 1: Match button colors to meanings
Bootstrap usesbtn-successfor green andbtn-dangerfor red buttons.Step 2: Apply correct sizes to buttons
The 'Save' button should be large, so usebtn-lg. The 'Cancel' button should be small, so usebtn-sm.Step 3: Verify the correct combination
<button class="btn btn-success btn-lg">Save</button> <button class="btn btn-danger btn-sm">Cancel</button> correctly usesbtn-success btn-lgfor 'Save' andbtn-danger btn-smfor 'Cancel'. Other options swap colors or sizes incorrectly.Final Answer:
<button class="btn btn-success btn-lg">Save</button> <button class="btn btn-danger btn-sm">Cancel</button> -> Option BQuick Check:
Green = btn-success, Large = btn-lg, Red = btn-danger, Small = btn-sm [OK]
- Swapping btn-success and btn-danger classes
- Using wrong size classes for buttons
- Mixing colors and sizes incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
