Simple Dropdown Menu Using HTML and CSS

In this tutorial we will see how to create Simple Dropdown Menu Using HTML and CSS. CSS position property and :hover selector is used for this purpose.

HTML Code

Simple HTML Code is given below, In this code we have a main ul tag which has four list items, while the second list item contain another ul tag which has four more list items.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Simple Dropdown Menu Using HTML and CSS</title>
</head>
<body>
  <ul>
     <li><a href="#">Home</a></li>
     <li>
       <a href="#">Languages ▾</a>
       <ul class="dropdown">
        <li><a href="#">HTML</a></li>
        <li><a href="#">CSS</a></li>
        <li><a href="#">JavaScript</a></li>
        <li><a href="#">PHP</a></li>
       </ul>
       </li>
     <li><a href="#">About Us</a></li>
     <li><a href="#">Contact Us</a></li>
  </ul>
</body>
</html>

CSS Code

CSS code is given below, In this code CSS position property is used, with the values relative and absolute. CSS :hover selector is also used to change the background-color of anchor tags and display properties of inner ul tag.

* {
padding: 0;
margin: 0;
font-family: monospace;
}
ul {
list-style: none;
background: #22438C;
}
ul li {
display: inline-block;
position: relative;
}
ul li a {
display: block;
padding: 20px 25px;
color: #FFF;
text-decoration: none;
text-align: center;
font-size: 20px;
}
ul li ul.dropdown li {
display: block;
}
ul li ul.dropdown {
width: 100%;
background: #22438C;
position: absolute;
z-index: 999;
display: none;
}
ul li a:hover {
background: #112C66;
}
ul li:hover ul.dropdown {
display: block;
}

Demo

Video Tutorial

Watch video tutorial on Simple Dropdown Menu Using HTML and CSS.

Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS 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 Profile Card With Hover Effect using HTML and CSS Simple Price Range Slider With HTML CSS and JavaScript Circle With Two Colors using CSS Card With Ribbon using HTML and CSS Simple Loading Screen using HTML and CSS Disable Textarea Resizable Property using CSS Button like Links using CSS Simple Dropdown Menu Using HTML and CSS Background Color Transition using CSS Highlight Required Input Fields using CSS Disable HTML Link using CSS Difference Between Descendant Selector and Child Selector How To Change Color and Size of Hr Tag Using CSS How To Center Align HTML Table Convert Checkbox To Toggle Button Using CSS Drawing Stars using HTML and CSS Button Bounce Effect using CSS Image as Text Background using CSS background-clip Property Vertically Rotate HTML Element using CSS Vertical Align Middle using CSS Text Over Image Hover Effect - Css Hover Simple CSS Button Hover Effect using Before Selector