Menu
How TO – Pill Navigation
Learn how to create a pill navigation menu with CSS.
Example
<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.pill-nav a {
display: inline-block;
color: black;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
border-radius: 5px;
}
.pill-nav a:hover {
background-color: #ddd;
color: black;
}
.pill-nav a.active {
background-color: dodgerblue;
color: white;
}
</style>
</head>
<body>
<h2>How To Create a Pill Navigation Menu</h2>
<div>
<a href=”#home”>Home</a>
<a href=”#news”>News</a>
<a href=”#contact”>Contact</a>
<a href=”#about”>About</a>
</div>
</body>
</html>
Create a Pill Navigation
Step 1) Add HTML:
Example
<div class=”pill-nav”>
<a class=”active” href=”#home”>Home</a>
<a href=”#news”>News</a>
<a href=”#contact”>Contact</a>
<a href=”#about”>About</a>
</div>
Step 2) Add CSS:
Example
<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.pill-nav a {
display: inline-block;
color: black;
text-align: center;
padding: 14px;
text-decoration: none;
font-size: 17px;
border-radius: 5px;
}
.pill-nav a:hover {
background-color: #ddd;
color: black;
}
.pill-nav a.active {
background-color: dodgerblue;
color: white;
}
</style>
</head>
<body>
<h2>How To Create a Pill Navigation Menu</h2>
<div>
<a href=”#home”>Home</a>
<a href=”#news”>News</a>
<a href=”#contact”>Contact</a>
<a href=”#about”>About</a>
</div>
</body>
</html>
Vertical Pill Navigation
Add display: block to the links, and they will appear vertically instead of horizontally:
Example
<!DOCTYPE html>
<html>
<head>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
.pill-nav a {
display: block;
color: black;
padding: 14px;
text-decoration: none;
font-size: 17px;
border-radius: 5px;
}
.pill-nav a:hover {
background-color: #ddd;
color: black;
}
.pill-nav a.active {
background-color: dodgerblue;
color: white;
}
</style>
</head>
<body>
<h2>How To Create a Vertical Pill Navigation</h2>
<div>
<a href=”#home”>Home</a>
<a href=”#news”>News</a>
<a href=”#contact”>Contact</a>
<a href=”#about”>About</a>
</div>
</body>
</html>