Discover how a simple font can replace dozens of images and make your website shine effortlessly!
Why Icon font usage in Bootsrap? - Purpose & Use Cases
Imagine you want to add small pictures like stars, hearts, or arrows to your website buttons and menus by drawing each shape yourself or using separate image files.
Using separate images means you must create, resize, and manage many files. It slows down your site and makes it hard to keep icons consistent in size and color.
Icon fonts let you use icons like letters in a special font. You can easily change their size and color with simple code, just like text, without extra image files.
<button><img src='star.png' alt='star icon'> Favorite</button>
<button><i class='bi bi-star-fill' aria-hidden='true'></i> Favorite</button>
Icon fonts make adding and styling icons fast, flexible, and consistent across your whole website.
On an online store, you can quickly add shopping cart, search, and user icons that scale perfectly on phones and desktops without extra images.
Managing icons as fonts saves time and reduces files.
Icons scale smoothly and match text styles easily.
Improves website speed and visual consistency.
Practice
Solution
Step 1: Understand Bootstrap icon usage
Bootstrap icons use theitag with classes starting withbito display icons.Step 2: Identify the correct class for alarm icon
The alarm icon uses the classbi-alarm, so the full class isbi bi-alarm.Final Answer:
<i class='bi bi-alarm'></i> -> Option DQuick Check:
Bootstrap icon tag = <i class='bi bi-iconname'></i> [OK]
- Using <icon> tag which is not valid
- Using <span> without correct classes
- Using <img> instead of icon font
Solution
Step 1: Recall Bootstrap icon class format
Bootstrap icons require two classes:biand the specific icon name likebi-check.Step 2: Check the tag and classes
The correct tag isiwith both classes:bi bi-check.Final Answer:
<i class='bi bi-check'></i> -> Option AQuick Check:
Two classes: 'bi' + 'bi-iconname' on <i> tag [OK]
- Using only one class instead of two
- Using wrong tag like <span> or <icon>
- Missing the 'bi' base class
<i class='bi bi-alarm'></i> Alarm
Solution
Step 1: Understand icon font rendering
Theitag with classesbi bi-alarmrenders a scalable alarm icon before the text.Step 2: Check the text placement
The text 'Alarm' appears after the icon, so the user sees the icon followed by the word.Final Answer:
A text 'Alarm' with a small alarm clock icon before it -> Option CQuick Check:
Icon + text = icon visible before text [OK]
- Thinking icon won't show without <img>
- Assuming <i> tag is invalid
- Expecting icon after text instead of before
<i class='bi-alarm'></i>
What is the likely problem?
Solution
Step 1: Check icon class usage
The class 'bi-alarm' alone is not enough; Bootstrap icons require both 'bi' and 'bi-alarm' classes.Step 2: Verify CSS inclusion
Even with correct classes, if the Bootstrap Icons CSS file is missing, icons won't show.Final Answer:
You forgot to include the Bootstrap Icons CSS file in your page. -> Option BQuick Check:
Missing CSS file = icons not visible [OK]
- Using only one class instead of two
- Not linking the Bootstrap Icons CSS file
- Thinking <i> tag is invalid for icons
Solution
Step 1: Choose scalable icon method
Bootstrap icons useitag with classes likebi bi-trashfor scalable vector icons that scale well on all devices.Step 2: Combine icon with button and label
Placing the icon inside the button before the text label ensures they appear side by side and respond to button styling.Final Answer:
<button class='btn btn-danger'><i class='bi bi-trash'></i> Delete</button> -> Option AQuick Check:
Use <i> with 'bi bi-icon' inside button for responsive icons [OK]
- Using <img> which may not scale well
- Using wrong classes like 'icon-trash'
- Not placing icon inside button element
Ready to prove it?
Pass the test and this pattern moves unknown
