For extra-small screens, the form-control is set to display: block
and width: 100%
. At small screens (≥576px), form-control switches to display: inline-block
and width: auto
. If you want your search box and button to always be on one line, then add the display and width settings for all screens.
To have the search form always in the center for medium and smaller screens, add justify-content-center
to the form and use the left auto margin just on larger displays.
To have the search form and button take up 100% of the available width, add flex-grow-1 to the input (or you could give the input a class of w-75 and it will be larger, but not too big).
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<style>
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle;
}
</style>