In this tutorial we will see how to create a Pure CSS Dropdown Menu. For this dropdown menu we have used only HTML and CSS, no JavaScript is used.
Table of Contents
HTML Code
Take a look at the HTML code given below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dropdown Menu Using HTML and CSS</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li>
<a href="#">Skills ▾</a>
<ul class="dropdown">
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</li>
<li><a href="#">Contact Us</a></li>
</ul>
</body>
</html>
CSS Code
CSS code is given below.
<style>
* {
padding: 0;
margin: 0;
font-family:sans-serif;
}
body
{
background-color: #00FF8C;
}
ul {
list-style: none;
background: #333;
text-align: center;
}
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: 16px;
}
ul li ul.dropdown li {
display: block;
background: #333;
margin: 2px 0px;
}
ul li ul.dropdown {
width:auto;
background: #00FF8C;
position: absolute;
z-index: 999;
display: none;
}
ul li a:hover {
background: #222;
}
ul li:hover ul.dropdown{
display: block;
}
</style>
Video Tutorial
Watch our video tutorial on Pure CSS Dropdown Menu.