How to create: Input fields in the menu

Learn how to create a navigation menu that includes input fields.

Home About

Try it yourself

How to add input fields in the navigation bar

Step 1 - Add HTML:

<div class="topnav">
  <a class="active" href="#home">Home</a>
  <a href="#about">About</a>
  <a href="#contact">Contact</a>
  <div class="search-container">
    <form action="/action_page.php">
      <input type="text" placeholder="Search.." name="search">
      <button type="submit">Submit</button>
    </form>
  </div>
</div>

Step 2 - Add CSS:

* {box-sizing: border-box;}
/* Set the style of the navigation bar */
.topnav {
  overflow: hidden;
  background-color: #e9e9e9;
}
/* Set the style of the navigation bar links */
.topnav a {
  float: left;
  display: block;
  color: black;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}
/* Set the style when the mouse hovers over the navigation bar links */
.topnav a:hover {
  background-color: #ddd;
  color: black;
}
/* Set the style of the current/active link */
.topnav a.active {
  background-color: #2196F3;
  color: white;
}
/* Set the style of the search box container */
.topnav .search-container {
  float: right;
}
/* Set the style of the input box within the navigation bar */
.topnav input[type=text] {
  padding: 6px;
  margin-top: 8px;
  font-size: 17px;
  border: none;
}
/* Set the style of the button within the search box container */
.topnav .search-container button {
  float: right;
  padding: 6px;
  margin-top: 8px;
  margin-right: 16px;
  background: #ddd;
  font-size: 17px;
  border: none;
  cursor: pointer;
}
.topnav .search-container button:hover {
  background: #ccc;
}
/* Add responsiveness - vertically instead of horizontally display the navigation bar on small screens */
@media screen and (max-width: 600px) {
  .topnav .search-container {
    float: none;
  }
  .topnav a, .topnav input[type=text], .topnav .search-container button {
    float: none;
    display: block;
    text-align: left;
    width: 100%;
    margin: 0;
    padding: 14px;
  }
  .topnav input[type=text] {
    border: 1px solid #ccc;
  }
}

Try it yourself