Home > Web Front-end > CSS Tutorial > How to add an icon to a search input in Bootstrap 4?

How to add an icon to a search input in Bootstrap 4?

Linda Hamilton
Release: 2024-12-15 17:13:14
Original
597 people have browsed it

How to add an icon to a search input in Bootstrap 4?

Bootstrap 4 - Search input with an icon

The question involves integrating an icon into a Bootstrap 4 search input. The issue arises as Bootstrap 4 does not support Glyphicons. Here's a detailed explanation of how to incorporate an icon into the search input using various techniques:

Input Group with Append

This technique uses an input-group with an append or a prepend for the icon. The icon is placed either before or after the input field.

<br><div>  <input class="form-control py-2" type="search" value="search">  <span><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><button>
Copy after login
Copy after login



Input Group with Input Group Text

This technique utilizes an input-group with input-group-text for the icon. The input-group-text provides a placeholder for the icon without a gray background.

<br><div>  <input class="form-control py-2 border-right-0 border" type="search" value="search">  <span><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><div>
Copy after login
Copy after login



Grid System (Row & Column)

This technique uses the grid system (row & column) to create a search input with an icon. No-gutters are used to eliminate spacing between columns, resulting in a seamless layout.

<br><div>  <div class="col"></p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><input>
Copy after login


<button>
Copy after login



Input Group with Prepend

Similar to the input group with append, this technique utilizes an input group with input-group-prepend. The icon is placed in the prepend, located before the input field.

<br><div>  <span class="input-group-prepend"></p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><div>
Copy after login
Copy after login


<button>
Copy after login
Copy after login



The choice of technique depends on the desired appearance and functionality. These examples demonstrate several methods for integrating an icon into a search input using Bootstrap 4, providing flexibility in design and implementation.

The above is the detailed content of How to add an icon to a search input in Bootstrap 4?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Previous article:How Can I Efficiently Get the Height of an Element Inside a Hidden Div Using jQuery? Next article:Access CSS Animations with Gradienty!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template