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
Linda HamiltonOriginal
2024-12-15 17:13:14592browse

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><pre class="brush:php;toolbar:false"><button>



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><pre class="brush:php;toolbar:false"><div>



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>
<pre class="brush:php;toolbar:false"><input>


<button>



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>
<pre class="brush:php;toolbar:false"><div>


<button>



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!

bootstrap for using class append this border background column input issue
Statement:
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
Previous article:How Can I Efficiently Get the Height of an Element Inside a Hidden Div Using jQuery?Next article:How Can I Efficiently Get the Height of an Element Inside a Hidden Div Using jQuery?

Related articles

See more