Responsive Mobile Tab Navigation Bar Using HTML CSS & JS

Hey, learner today In this blog post, We will be Creating a Responsive Mobile Tab Navigation Bar Using HTML CSS, and JS. In the past post, we have created many projects one of them Password Strength Background blurred Using HTML CSS, and JS. Now it is time to create a Responsive Mobile Tab Navigation Bar.

Responsive Mobile Tab Navigation Bar Using HTML CSS & JS

Creating a responsive navigation bar is an essential part of improving your user experience and web design skills. It is obvious that most website owners want new visitors. The first step towards doing so is showing the visitors a clear and concise path. supposed that you are building a navbar that inspires curiosity and attracts visitors simultaneously. you have create attractive, user-friendly, and responsive the device

So, in this project, we have created a responsive and user-friendly nav bar in the mobile version. In this project, there is a Home section Work section Blog section and last, there is an About us section in the Nav bar. This design is created by using HTML and CSS. We make this project responsive to all devices by using Javascript.

Preview of Responsive Mobile Tab Navigation Bar on Codepen

Codepen Link

You might like this

Responsive Mobile Tab Navigation Bar Using HTML CSS and JS [Source code]

To create a Responsive Mobile Tab Navigation Bar Using HTML CSS and JS At first, you have to create three files (HTML, CSS, and JS) files with the named index.html, style.css, and Script.js in the same folder and you have to link the CSS and JS files to HTML. after that paste, the HTML code in index.html, and paste the CSS code in style.css at last paste the Javascript code in Script.js that’s all after pasting the code.

At first, you have to create an HTML file with the named index.html and paste the below HTML code on it and save it. Remember to give a .html extension to the HTML file.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />
    <link rel="stylesheet" href="style.css" />
    <title>Mobile Tab Navigation</title>
    <div class="phone">
      <img src="" alt="home" class="content show">
      <img src="" alt="work" class="content">
      <img src="" alt="blog" class="content">
      <img src="" alt="about" class="content">
          <li class="active">
            <i class="fas fa-home"></i>
            <i class="fas fa-box"></i>
            <i class="fas fa-book-open"></i>
            <i class="fas fa-users"></i>
            <p>About Us</p>
    <script src="script.js"></script>

After pasting the HTML code, Now have to create a second CSS file with the named style.css. Paste the below code on it and save it. Again remember to give .css extension to CSS file.

@import url('');

* {
  box-sizing: border-box;

body {
  background-color: rgba(155, 89, 182, 0.7);
  font-family: 'Open Sans', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  margin: 0;

.phone {
  position: relative;
  overflow: hidden;
  border: 3px solid #eee;
  border-radius: 15px;
  height: 600px;
  width: 340px;

.phone .content {
  opacity: 0;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
  height: calc(100% - 60px);
  width: 100%;
  transition: opacity 0.4s ease;

.phone {
  opacity: 1;

nav {
  position: absolute;
  bottom: 0;
  left: 0;
  margin-top: -5px;
  width: 100%;

nav ul {
  background-color: #fff;
  display: flex;
  list-style-type: none;
  padding: 0;
  margin: 0;
  height: 60px;

nav li {
  color: #777;
  cursor: pointer;
  flex: 1;
  padding: 10px;
  text-align: center;

nav ul li p {
  font-size: 12px;
  margin: 2px 0;

nav ul li:hover,
nav ul {
  color: #8e44ad;

At last, you have to create a Javascript file with the named script.js and paste the Js code on it and save it again don’t forget to give the .js extension to the Javascript file.

const contents = document.querySelectorAll('.content')
const listItems = document.querySelectorAll('nav ul li')

listItems.forEach((item, idx) => {
    item.addEventListener('click', () => {


function hideAllContents() {
    contents.forEach(content => content.classList.remove('show'))

function hideAllItems() {
    listItems.forEach(item => item.classList.remove('active'))

That’s all after pasting the code now your code will be successfully run. If you get any kind of error/problem in the code just comment down or contact me

About the Author

One thought on “Responsive Mobile Tab Navigation Bar Using HTML CSS & JS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these