Here's an example of a Responsive Header created using Html & pure CSS.
1. Create an HTML file and include a basic structure with a head and body tag. You can use the following code as a starting point and Add the CSS files to your HTML document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to create a responsive mobile header with CSS | Mobile Menu</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.2/css/all.css" type="text/css" media="all" />
</head>
<body>
</body>
</html>
2. Inside the body tag, create a header element with a class of "header".
<header class="header">
<div class="mobile-header flexCe">
<div class="nav-button">
<input type="checkbox" name="navButton" id="navButton">
<label for="navButton" class="icon"><i class="fab fa-bars"></i></label>
<label for="navButton" class="nav-close"></label>
<div class="navigation">
<div class="navigation-header flexCe">
<label for="navButton" class="icon"><i class="fab fa-arrow-left"></i></label>
<div class="logo">Application</div>
</div>
<div class="menu-item">
<div class="s-menu-title">title</div>
<ul class="group">
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
</ul>
<div class="s-menu-title">title</div>
<ul class="group">
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
</ul>
</div>
</div>
</div>
<div class="logo">Application</div>
<div class="search flexCe">
<input type="checkbox" name="searchButton" id="searchButton">
<label for="searchButton" class="search-open icon"><i class="fab fa-search"></i></label>
<form action="" class="form flexCe">
<label for="searchButton" class="search-close icon"><i class="fab fa-arrow-left"></i></label>
<div class="search-input flexCe">
<input type="text" placeholder="Search something">
</div>
<div class="microphone icon">
<i class="fab fa-microphone"></i>
</div>
</form>
</div>
<div class="right-menu icon">
<i class="fab fa-ellipsis-v"></i>
</div>
</div>
</header>
3. Create a CSS file and style your Application Header to make it look nice. You can use the following code as a starting point:
.fab::after,
.fab::before {
font-family: "Font Awesome 6 Pro";
font-size: 14px;
}
body {
margin: 0;
padding: 0;
background: #0084ff;
width: 100%;
height: 100vh;
font-family: system-ui;
}
.icon {
position: relative;
width: 28px;
height: 28px;
padding: 5px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
user-select: none;
overflow: hidden;
}
.icon::before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.icon:hover {
background: #0001;
}
.icon:active {
background: #0002;
}
.flexCe {
display: flex;
align-items: center;
}
.mobile-header {
position: relative;
width: 340px;
width: 100%;
height: 40px;
background: #fff;
gap: 5px;
}
.logo {
width: -webkit-fill-available;
font-weight: 600;
}
.form {
position: absolute;
left: 0;
right: 0;
top: 0;
width: 100%;
height: 40px;
gap: 2px;
background: #fff;
z-index: -1;
opacity: 0;
transition: all 0.3s;
}
.form .search-input {
flex: 1;
height: 100%;
}
.search-input input {
width: 0;
padding: 8px 10px;
border: none;
outline: none;
font-weight: 500;
transition: all 0.3s;
color: #555;
}
.search-input input {
width: 100%;
}
#navButton,
#searchButton {
display: none !important;
}
#searchButton:checked~.form {
opacity: 1;
z-index: 99;
}
.nav-close,
.navigation {
background: #fff;
position: fixed;
left: -100%;
top: 0;
width: 220px;
height: -webkit-fill-available;
transition: all 0.3s;
}
.nav-close {
background: transparent;
width: 100%;
}
#navButton:checked~.navigation,
#navButton:checked~.nav-close {
left: 0;
z-index: 9999;
}
.navigation .s-menu-title {
padding: 10px;
font-size: 12px;
letter-spacing: 1px;
text-transform: uppercase;
font-weight: 500;
}
.navigation .menu-item ul {
padding: 0;
margin: 0;
}
.navigation .menu-item .list a {
text-decoration: none;
color: #555;
padding: 10px 10px 10px 30px;
}
.navigation .menu-item .list a:hover {
background: #0001;
}
.navigation .menu-item .list a:active {
background: #0002;
}
4. Save the file and open it in a web browser to see your Application Header.
<link rel="stylesheet" href="https://site-assets.fontawesome.com/releases/v6.4.2/css/all.css" type="text/css" media="all" />
<header class="header">
<div class="mobile-header flexCe">
<div class="nav-button">
<input type="checkbox" name="navButton" id="navButton">
<label for="navButton" class="icon"><i class="fab fa-bars"></i></label>
<label for="navButton" class="nav-close"></label>
<div class="navigation">
<div class="navigation-header flexCe">
<label for="navButton" class="icon"><i class="fab fa-arrow-left"></i></label>
<div class="logo">Application</div>
</div>
<div class="menu-item">
<div class="s-menu-title">title</div>
<ul class="group">
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
</ul>
<div class="s-menu-title">title</div>
<ul class="group">
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
<li class="list"> <a class="flexCe" href="#">Your menu title</a></li>
</ul>
</div>
</div>
</div>
<div class="logo">Application</div>
<div class="search flexCe">
<input type="checkbox" name="searchButton" id="searchButton">
<label for="searchButton" class="search-open icon"><i class="fab fa-search"></i></label>
<form action="" class="form flexCe">
<label for="searchButton" class="search-close icon"><i class="fab fa-arrow-left"></i></label>
<div class="search-input flexCe">
<input type="text" placeholder="Search something">
</div>
<div class="microphone icon">
<i class="fab fa-microphone"></i>
</div>
</form>
</div>
<div class="right-menu icon">
<i class="fab fa-ellipsis-v"></i>
</div>
</div>
</header>
.fab::after,
.fab::before {
font-family: "Font Awesome 6 Pro";
font-size: 14px;
}
body {
margin: 0;
padding: 0;
background: #0084ff;
width: 100%;
height: 100vh;
font-family: system-ui;
}
.icon {
position: relative;
width: 28px;
height: 28px;
padding: 5px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
user-select: none;
overflow: hidden;
}
.icon::before {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.icon:hover {
background: #0001;
}
.icon:active {
background: #0002;
}
.flexCe {
display: flex;
align-items: center;
}
.mobile-header {
position: relative;
width: 340px;
width: 100%;
height: 40px;
background: #fff;
gap: 5px;
}
.logo {
width: -webkit-fill-available;
font-weight: 600;
}
.form {
position: absolute;
left: 0;
right: 0;
top: 0;
width: 100%;
height: 40px;
gap: 2px;
background: #fff;
z-index: -1;
opacity: 0;
transition: all 0.3s;
}
.form .search-input {
flex: 1;
height: 100%;
}
.search-input input {
width: 0;
padding: 8px 10px;
border: none;
outline: none;
font-weight: 500;
transition: all 0.3s;
color: #555;
}
.search-input input {
width: 100%;
}
#navButton,
#searchButton {
display: none !important;
}
#searchButton:checked~.form {
opacity: 1;
z-index: 99;
}
.nav-close,
.navigation {
background: #fff;
position: fixed;
left: -100%;
top: 0;
width: 220px;
height: -webkit-fill-available;
transition: all 0.3s;
}
.nav-close {
background: transparent;
width: 100%;
}
#navButton:checked~.navigation,
#navButton:checked~.nav-close {
left: 0;
z-index: 9999;
}
.navigation .s-menu-title {
padding: 10px;
font-size: 12px;
letter-spacing: 1px;
text-transform: uppercase;
font-weight: 500;
}
.navigation .menu-item ul {
padding: 0;
margin: 0;
}
.navigation .menu-item .list a {
text-decoration: none;
color: #555;
padding: 10px 10px 10px 30px;
}
.navigation .menu-item .list a:hover {
background: #0001;
}
.navigation .menu-item .list a:active {
background: #0002;
}