Icons help make buttons and inputs easier to understand quickly. They add clear pictures that show what the button or input does.
Icons in buttons and inputs in Bootsrap
<button type="button" class="btn btn-primary"> <i class="bi bi-icon-name"></i> Button Text </button> <div class="input-group"> <input type="text" class="form-control" placeholder="Search"> <span class="input-group-text"><i class="bi bi-search"></i></span> </div>
Use Bootstrap Icons by adding <i> tags with classes like bi bi-icon-name.
Wrap inputs and icons inside .input-group and use .input-group-text for icons next to inputs.
<button type="button" class="btn btn-success"> <i class="bi bi-check-circle"></i> Submit </button>
<div class="input-group"> <input type="text" class="form-control" placeholder="Search"> <span class="input-group-text"><i class="bi bi-search"></i></span> </div>
<button type="button" class="btn btn-danger"> <i class="bi bi-trash"></i> </button>
This page shows two buttons with icons and a search input with a magnifying glass icon on the right. The icons come from Bootstrap Icons. The input uses input-group to place the icon next to the text box.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Icons in Buttons and Inputs</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet"> </head> <body> <main class="container py-4"> <h1>Icons in Buttons and Inputs</h1> <section class="mb-3"> <button type="button" class="btn btn-primary"> <i class="bi bi-search"></i> Search </button> <button type="button" class="btn btn-danger ms-2"> <i class="bi bi-trash"></i> Delete </button> </section> <section> <label for="searchInput" class="form-label">Search Input with Icon</label> <div class="input-group"> <input type="text" id="searchInput" class="form-control" placeholder="Type to search..." aria-label="Search input"> <span class="input-group-text" id="search-icon"> <i class="bi bi-search" aria-hidden="true"></i> </span> </div> </section> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Make sure to include the Bootstrap Icons CSS link to see the icons.
Use aria-label and aria-hidden for better accessibility.
Spacing between icon and text in buttons can be controlled with margin classes like ms-2.
Icons make buttons and inputs easier to understand at a glance.
Use Bootstrap Icons with <i> tags and proper classes.
Wrap inputs and icons in .input-group for neat layout.
Practice
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 BQuick Check:
Icons improve clarity = A [OK]
- Thinking icons change button size automatically
- Assuming icons change colors by default
- Believing icons disable inputs
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 DQuick Check:
Bootstrap icons use <i> + bi classes = A [OK]
- Using <icon> tag which is invalid HTML
- Using <span> without Bootstrap icon classes
- Using <img> instead of icon classes
<div class="input-group"> <span class="input-group-text"><i class="bi bi-envelope"></i></span> <input type="email" class="form-control" placeholder="Email" aria-label="Email"> </div>
Solution
Step 1: Understand input-group structure
The.input-groupwraps input and icon for inline layout with styling.Step 2: Analyze icon placement
The icon inside.input-group-textappears on the left side inside a styled box next to the input.Final Answer:
An email input with an envelope icon on the left inside a styled box -> Option AQuick Check:
Input group with icon left = B [OK]
- Expecting icon inside placeholder text
- Thinking icon appears below input
- Missing .input-group wrapper for layout
<button class="btn btn-primary"> <i class="bi bi-search"></i>Search </button>
Solution
Step 1: Check icon and text spacing
The icon and text run together without space, making them look joined.Step 2: Confirm correct classes and tags
Icon class "bi bi-search" and<i>tag are correct; button tag is correct.Final Answer:
Missing space between icon and text -> Option AQuick Check:
Icon and text need space = D [OK]
- Assuming icon class is wrong
- Changing button tag unnecessarily
- Replacing <i> with <span> without reason
Solution
Step 1: Understand Bootstrap input groups
To add an icon inside input on the right, wrap input and icon in.input-group.Step 2: Place icon after input inside
Placing icon after input inside.input-group-text.input-group-textaligns it on the right side and makes it clickable.Final Answer:
Wrap input and icon in .input-group with icon inside .input-group-text placed after input -> Option CQuick Check:
Right icon in input = input-group + input-group-text after input [OK]
- Trying to put icon inside placeholder
- Adding icon tag inside input element (invalid)
- Placing button outside input group losing alignment
Ready to prove it?
Pass the test and this pattern moves unknown
