How to make responsive header for website using HTML and CSS

By | December 9, 2021

Responsive Header for website with Text Logo

How to make responsive header for website using HTML and CSS

HTML Code:

<nav>
<div class="logo">YourLogo</div>
<input type="checkbox" id="click">
<label for="click" class="menu-btn">
<i class="fas fa-bars"></i>
</label>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Feedback</a></li>
</ul>
</nav>

CSS Code:

*{
    margin: 0;
    padding: 0;
}
nav{
    height: 83px;
    background: #111;
    display: flex;
    justify-content: space-between;
    padding: 0px 50px 0px 100px;
}
nav .logo{
    padding-top: 15px;
    font-size: 33px;
    color: white;
    font-weight: 600;
}
nav ul {
    display: flex;
    list-style: none;
}
nav ul li{
    margin: 0px 5px;
    padding-top: 30px;
}
nav ul li a {
    color: #1b1b1b;
    text-decoration: none;
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 1px;
    background: white;
    padding: 8px 10px;
    border-radius: 10px;
    transition: all 0.3s ease;
    margin-top: 5px;
}
nav ul li a:hover{
    color: white;
    background: #1b1b1b;
}
nav .menu-btn i{
    color: white;
    font-size: 22px;
    cursor: pointer;
    display: none;
}
#click{
    display: none;

For Responsive Header, Copy this code:

@media (max-width: 940px){
    nav .menu-btn i{
        padding-top: 25px;
        display: block;
    }
    #click:checked ~ .menu-btn i::before{
        content: "\f00d";
    }
    nav ul{
        position: fixed;
        top: 80px;
        left: -100%;
        background: #111;
        height: 100vh;
        width: 100%;
        display: block;
        text-align: center;
        transition: all 0.3s ease;
    }
    #click:checked ~ ul{
        left: 0%;
    }
    nav ul li{
        margin-top: 40px 0;
        
    }
    nav ul li a{
        font-size: 20px;
        display: block;
        background: #111;
        color: white;
    }
    nav ul li a:hover{
        color: cyan;
        background: none;
    }
}

Paste this Script tag in your <Head> tag:

<script src="https://kit.fontawesome.com/a076d05399.js"></script>