In this tutorial, we will see search bar in react with bootstrap 5. We will see search form component, search bar with search icon using react bootstrap 5.
Install & Setup Vite + React + Typescript + Bootstrap 5
React Bootstrap 5 Search Bar Example
1. Create simple react bootstrap search bar using react-bootstrap Form, Form.Control, Button component.
import { Button, Col, Container, Form, Row } from "react-bootstrap";
export default function SearchBar() {
return (
<Container className="mt-5">
<Row>
<Col sm={4}>
<Form className="d-flex">
<Form.Control
type="search"
placeholder="Search"
className="me-2"
aria-label="Search"
/>
<Button>
Search
</Button>
</Form>
</Col>
</Row>
</Container>
);
}
2. react bootstrap 5 rounded search bar.
import { Button, Col, Container, Form, Row } from "react-bootstrap";
export default function SearchBar() {
return (
<Container className="mt-5">
<Row>
<Col sm={4}>
<Form className="d-flex">
<Form.Control
type="search"
placeholder="Search"
className="me-2 rounded-pill"
aria-label="Search"
/>
<Button className="rounded-pill" variant="outline-primary">
Search
</Button>
</Form>
</Col>
</Row>
</Container>
);
}
3. react bootstrap 5 search bar with svg search icon.
import {
Form,
FormControl,
InputGroup,
Container,
Row,
Col,
} from "react-bootstrap";
export default function SearchBar() {
return (
<Container className="mt-5">
<Row>
<Col sm={4}>
<Form className="d-flex">
<InputGroup>
<InputGroup.Text className="bg-white">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="16"
height="16"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M9.5 3a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13zM1 9.5a8.5 8.5 0 1 1 17 0 8.5 8.5 0 0 1-17 0z"
/>
<path
fill-rule="evenodd"
d="M16.853 16.854a.5.5 0 0 0 .707 0l3.793-3.793a.5.5 0 0 0 0-.707l-3.793-3.793a.5.5 0 0 0-.707.707L19.293 12H10.5a.5.5 0 0 0 0 1h8.793l-2.646 2.646a.5.5 0 0 0 0 .707z"
/>
</svg>
</InputGroup.Text>
<FormControl type="search" className="me-2" placeholder="Search" />
</InputGroup>
</Form>
</Col>
</Row>
</Container>
);
}