Discover how a few simple classes can transform your icons from messy to perfect in seconds!
Why Icon sizing and colors in Bootsrap? - Purpose & Use Cases
Imagine you want to add icons to your website buttons and menus. You pick icons from different sources and try to make them look good by changing their size and color manually using images or custom CSS.
Manually resizing and coloring icons is slow and tricky. You might end up with inconsistent sizes, colors that don't match your design, or icons that look blurry or pixelated on different screens.
Bootstrap provides easy classes to control icon sizes and colors consistently. You just add simple classes to your icons, and they automatically adjust to the right size and color that fits your design perfectly.
<i class="icon-star" style="width: 20px; height: 20px; color: red;"></i>
<i class="bi bi-star fs-3 text-danger"></i>
This lets you quickly and reliably style icons across your whole site, keeping everything neat, consistent, and visually appealing without extra hassle.
Think about a shopping site where the cart icon changes size on mobile and desktop and turns red when items are added. Using Bootstrap's icon sizing and color classes makes this easy and smooth.
Manual icon styling is slow and inconsistent.
Bootstrap classes simplify icon sizing and coloring.
Consistent, responsive icons improve user experience.
Practice
Solution
Step 1: Understand Bootstrap icon sizing
Bootstrap usesfs-*classes to control font size, which affects icon size.Step 2: Identify correct class pattern
The correct pattern isfs-*, where * is a number like 1, 2, 3, etc.Final Answer:
<code>fs-*</code> classes -> Option AQuick Check:
Icon size = fs-* classes [OK]
- Confusing icon size classes with color classes
- Using non-existent class names like icon-size-*
- Thinking size is controlled by icon-fs-*
Solution
Step 1: Recall Bootstrap font size scale
Bootstrap font sizes range from fs-1 (largest) to fs-6 (smallest).Step 2: Identify medium size
fs-3 is roughly in the middle, so it represents medium size.Final Answer:
fs-3 -> Option CQuick Check:
Medium size = fs-3 [OK]
- Choosing fs-1 thinking it's medium
- Using fs-0 which does not exist
- Confusing fs-6 as medium size
text-danger?Solution
Step 1: Understand Bootstrap text color classes
Bootstrap uses semantic color classes liketext-dangerfor red color.Step 2: Match class to color
text-dangerapplies a red color to text or icons.Final Answer:
Red -> Option AQuick Check:
text-danger = red color [OK]
- Thinking text-danger is blue
- Confusing text-success with text-danger
- Assuming text-danger is gray
<i class='bi bi-check fs-1 text-successs'></i>. What is the problem?Solution
Step 1: Check class names for typos
The color classtext-successshas an extra 's' and is invalid.Step 2: Confirm other classes
bi-checkis a valid icon,fs-1is valid for large size, aria-label is optional but recommended.Final Answer:
Misspelled color class <code>text-successs</code> -> Option DQuick Check:
Check spelling of color classes [OK]
- Ignoring typos in class names
- Assuming fs-1 is invalid
- Forgetting aria-label but thinking it's an error
Solution
Step 1: Check icon name and size
bi-info-circleis correct icon name;fs-3is medium size.Step 2: Verify color and accessibility
text-primaryis blue color;aria-label='Info icon'provides accessible label.Step 3: Review other options
<i class='bi bi-info-circle fs-5 text-info' aria-label='Info icon'></i>usesfs-5(small size) andtext-info(lighter blue).<i class='bi bi-info fs-3 text-primary' aria-hidden='true'></i>misses accessible label and usesaria-hidden.<i class='bi-info-circle fs-3 text-primary' aria-label='Info icon'></i>missesbiclass prefix.Final Answer:
<i class='bi bi-info-circle fs-3 text-primary' aria-label='Info icon'></i> -> Option BQuick Check:
Correct icon, size, color, and aria-label [OK]
- Missing bi prefix on icon class
- Using wrong size or color classes
- Forgetting aria-label for accessibility
Ready to prove it?
Pass the test and this pattern moves unknown
