Dropdown Menu with Search bar using HTML and CSS

In this tutorial we will see how to create a Dropdown Menu with Search bar using HTML and CSS. Simple HTML and CSS is used for this purpose, complete code is given.

HTML Code

Take a look at the HTML code given below.

<!DOCTYPE html>
<html lang="">
<head>
	<meta charset="utf-8">
	<title>Dropdown Menu with Search using HTML and CSS</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
</head>
<body>
 <nav>
  <ul class="primary">
   <li><a href="#">Menu 1</a></li>   
   <li><a href="#">Menu 2</a>
    <ul class="sub">
      <li><a href="#">Sub Menu 1</a></li>   
      <li><a href="#">Sub Menu 2</a></li>   
      <li><a href="#">Sub Menu 3</a></li>   
    </ul>   
   </li>   
   <li><a href="#">Menu 3</a></li>   
   <li><a href="#">Menu 4</a></li>   
  </ul>
  <input type="search" class="search" placeholder="Search">      
 </nav>    
</body>
</html>

CSS Code

CSS code is given below.

<style>
body{ 
      background: #ccc;
      font-family: monospace;
      margin: 0;    
}
ul{
      list-style: none;
      padding: 0;
      margin: 0;    
}
nav{
      background: #4000ad;
      position: relative;
      padding: 0px 20px;
}
.search
{
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 0%;
      margin-right: 20px;
      padding: 10px;
      border-radius: 5px;
}
a{
      text-decoration: none;
      color: #fff;
      display: block;
      padding: 20px;
}
li{
      float: left;
      font-size: 15px;
}
ul:after{
      clear: both;
}
ul:before,
ul:after {
        content: " ";
        display: table;
}
ul.primary li a:hover {
      color: #000;
}
ul.sub {
      position: absolute;
      z-index: 200;
      box-shadow: 2px 2px 0 #BEBEBE;
      width: 35%;
      display:none;
}
ul.sub li {
      float: none;
      margin: 0;
}
ul.sub li a {
      border-top: 1px solid #fff;
      border-right: none;
      padding: 15px 30px;
}
ul.sub li:last-child a {
      border-bottom: none;
}
ul.primary li:hover ul {
      display: block;
}
ul.primary li:hover a {
      background: #fff;
      color: #666;
      text-shadow: none;
}
ul.primary li:hover > a{
      color: #000;
} 
ul.sub li a:hover {
      color: #fff;
      background: #4000ad;
}
</style>           

Video Tutorial

Watch our video tutorial on Dropdown Menu with Search bar using HTML and CSS.

Social Media Menu with Popup Tooltip using HTML and CSS Horizontal Navigation Menu with HTML and CSS Responsive Sidebar Menu with CSS and JavaScript Cool CSS Button with Hover Animation Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Color Picker Design with HTML CSS and JavaScript Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Simple Price Range Slider With HTML CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Circle With Two Colors using CSS Simple FAQ Accordion With HTML CSS and JavaScript