📖 Scenario: You are creating a simple web form that uses Bootstrap to add icons inside buttons and input fields. This helps users quickly understand the purpose of each element, like a search box with a magnifying glass icon or a submit button with a checkmark.
🎯 Goal: Build a small HTML page using Bootstrap 5 that includes a search input with a search icon inside it and a submit button with a checkmark icon. The icons should be from Bootstrap Icons and placed correctly inside the elements.
📋 What You'll Learn
Use Bootstrap 5 CSS and Bootstrap Icons CSS from CDN
Create a search input with a search icon inside it on the left
Create a submit button with a checkmark icon on the left
Use proper Bootstrap classes for input groups and buttons
Ensure the icons are accessible with appropriate aria-labels
💡 Why This Matters
🌍 Real World
Icons in buttons and inputs are common in web forms and apps to make interfaces easier to understand and use. For example, search boxes often have a magnifying glass icon, and submit buttons may have checkmarks.
💼 Career
Knowing how to use Bootstrap and Bootstrap Icons to enhance form controls is a valuable skill for front-end web developers and UI designers. It improves user experience and accessibility.
Progress0 / 4 steps
1
Set up the basic HTML structure with Bootstrap and Bootstrap Icons
Create a basic HTML5 page with lang="en", meta charset="UTF-8", and viewport meta tag. Include Bootstrap 5 CSS and Bootstrap Icons CSS from their official CDN links inside the <head>. Add a <body> with a <main> container where you will add the form later.
Bootsrap
Hint
Remember to include the Bootstrap CSS and Bootstrap Icons CSS links inside the <head> section.
2
Add a search input with a search icon inside using Bootstrap input group
Inside the <main> container, add a Bootstrap input group with a text input for search. Add a <span> with class input-group-text containing the Bootstrap icon bi bi-search on the left side of the input. The input should have type="search", placeholder="Search", and aria-label="Search input".
Bootsrap
Hint
Use a span with class input-group-text for the icon and link it with the input using aria-describedby.
3
Add a submit button with a checkmark icon on the left
Below the input group, add a Bootstrap button with class btn btn-primary. Inside the button, add a Bootstrap icon bi bi-check-lg on the left, followed by the text Submit. The icon should have aria-hidden="true" for accessibility.
Bootsrap
Hint
Place the icon inside the button before the text and add aria-hidden="true" to the icon.
4
Add accessibility and responsive spacing
Add aria-label="Submit form" to the submit button for screen readers. Also, add a Bootstrap margin utility class mt-3 to the button to add space above it on all screen sizes.
Bootsrap
Hint
Add the aria-label attribute and the mt-3 class inside the button tag.
Practice
(1/5)
1. What is the main purpose of adding icons inside Bootstrap buttons or inputs?
easy
A. To increase the size of buttons automatically
B. To make buttons and inputs easier to understand visually
C. To change the button color to blue
D. To disable the input field
Solution
Step 1: Understand the role of icons in UI
Icons provide visual clues that help users quickly understand the purpose of buttons or inputs.
Step 2: Relate to Bootstrap usage
Bootstrap uses icons to improve user experience by making controls more intuitive.
Final Answer:
To make buttons and inputs easier to understand visually -> Option B
Quick Check:
Icons improve clarity = A [OK]
Hint: Icons help users recognize actions quickly [OK]
Common Mistakes:
Thinking icons change button size automatically
Assuming icons change colors by default
Believing icons disable inputs
2. Which is the correct way to add a Bootstrap icon inside a button?
easy
A. Search
B. Search
C. Search
D. Search
Solution
Step 1: Identify Bootstrap icon syntax
Bootstrap icons use <i> tags with classes like "bi bi-search".
Step 2: Check each option
<button><i class="bi bi-search"></i> Search</button> uses <i> with correct classes; others use wrong tags or methods.
Final Answer:
<button><i class="bi bi-search"></i> Search</button> -> Option D
Quick Check:
Bootstrap icons use <i> + bi classes = A [OK]
Hint: Use <i> tag with 'bi' classes for Bootstrap icons [OK]