This article introduces how to use CSS to create a navigation bar with search.

The following examples are all responsive.

You can first look at the preview image:

Create a Search Bar

HTML Code

<div class="topnav"> <a class="active" href="#home">Home</a> <a href="#about">About</a> <a href="#contact">Contact Us</a> <input type="text" placeholder="Search.."> </div>

CSS Code

/*Add a black background color to the top navigation bar*/ .topnav { overflow: hidden; background-color: #e9e9e9; } /*Set the link style of the navigation bar*/ .topnav a { float: left; display: block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } /*Change the link color on hover*/ .topnav a:hover { background-color: #ddd; color: black; } /*Highlight the currently selected element*/ .topnav a.active { background-color: #2196F3; color: white; } /*Set the style of the search box in the navigation bar*/ .topnav input[type=text] { float: right; padding: 6px; border: none; margin-top: 8px; margin-right: 16px; font-size: 17px; } /*When the screen width is less than 600px, display the menu options and search box stacked vertically*/ @media screen and (max-width: 600px) { .topnav a, .topnav input[type=text] { float: none; display: block; text-align: left; width: 100%; margin: 0; padding: 14px; } .topnav input[type=text] { border: 1px solid #ccc; } }

Try it yourself »

More Examples

Example - Search Navigation Bar with Submit Button


Try it yourself »

Example - Search Navigation Bar with Search Icon


Try it yourself »