Q:

Align Navbar search form and button in the center with Bootstrap 4

Here is the code of the header and i want to align its search bar and button in center    

<header>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="#">Aditya Shrivastava</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
    <nav class="navbar navbar-light bg-light">
      <form class="form-inline">
        <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
        <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
      </form>
    </nav>
    <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
      <div class="navbar-nav ml-auto">
        <a class="nav-item nav-link" href="#">Twitter</a>
        <a class="nav-item nav-link" href="#">Resume</a>
        <a class="nav-item nav-link" href="#">Blog</a>
      </div>
    </div>
  </nav>
</header>

A:

To align Bootstrap 4 Navbar content use the utility classes

flex-grow-1 on the brand and form so they fill width
mx-lg-auto to center the form on lg and up (navbar-expand-lg breakpoint)
ml-auto on the right navbar-collapse to keep it right aligned
m-* and p-* to adjust margins or padding as desired

<header>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <a class="navbar-brand flex-grow-1" href="#">Aditya Shrivastava</a>
        <div class="flex-grow-1 d-flex">
            <form class="form-inline flex-nowrap bg-light mx-0 mx-lg-auto rounded p-1">
                <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-success" type="submit">Search</button>
            </form>
        </div>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
            <div class="navbar-nav ml-auto">
                <a class="nav-item nav-link" href="#">Twitter</a>
                <a class="nav-item nav-link" href="#">Resume</a>
                <a class="nav-item nav-link" href="#">Blog</a>
            </div>
        </div>
    </nav>
</header>

https://www.codeply.com/go/NXIwAj610b

Related: Bootstrap NavBar with left, center or right aligned items

