loader

Loading

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup

Getting Started with CSS

Quick StartCSS FAQs

Styling Properties

CSS ColorsCSS BackgroundsCSS BordersCSS Box ModelCSS MarginCSS PaddingCSS Size PropertiesCSS Text StylingCSS FontsCSS LinksCSS Hover EffectsCSS List StylesCSS ImagesCSS ButtonsCSS FormsCSS CursorsCSS PositioningCSS FloatCSS OverflowCSS Z-IndexCSS CombinatorsCSS Pseudo-ClassesCSS !importantCSS Math FunctionsCSS Navigation BarCSS Video Embedding

Advanced Techniques

CoderrShyam logo

CoderrShyam

HomeAboutContactBlogTutorials
LoginSignup
TutorialsCSS TutorialPropertiesCSS Navigation Bar

CSS Navigation Bar

Learn to create beautiful, responsive navigation bars with CSS including dropdowns, mobile menus, and modern patterns.

Navigation bars are critical for website usability. CSS provides powerful tools for creating attractive, accessible navigation.

Basic Horizontal Nav

nav {
  background-color: #333;
  padding: 0;
}

nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}

nav li {
  position: relative;
}

nav a {
  display: block;
  padding: 15px 20px;
  color: white;
  text-decoration: none;
  transition: background-color 0.3s ease;
}

nav a:hover,
nav a.active {
  background-color: #007bff;
}

Sticky Navigation

nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

Dropdown Menu

/* Parent item */
nav li {
  position: relative;
}

/* Dropdown container */
nav ul ul {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  display: none;
  flex-direction: column;
  background-color: #444;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Show on hover */
nav li:hover > ul {
  display: flex;
}

/* Dropdown items */
nav ul ul a {
  padding: 10px 15px;
}

nav ul ul a:hover {
  background-color: #555;
}

Mobile Menu (Hamburger)

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 15px;
}

@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }

  nav ul {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #333;
  }

  nav ul.active {
    display: flex;
  }

  nav li {
    width: 100%;
  }
}

Search Bar in Nav

.nav-search {
  margin-left: auto;
  padding: 5px;
}

.nav-search input {
  padding: 8px 15px;
  border: none;
  border-radius: 20px;
  outline: none;
}

Nav with Logo

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.logo {
  font-size: 24px;
  font-weight: bold;
  color: white;
}

.nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

Mega Menu

.mega-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: white;
  display: none;
  padding: 30px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.has-mega:hover .mega-menu {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
}

Tab Navigation

.tabs {
  display: flex;
  border-bottom: 2px solid #ddd;
}

.tab {
  padding: 15px 30px;
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  transition: all 0.3s ease;
}

.tab:hover {
  background-color: #f8f9fa;
}

.tab.active {
  border-bottom-color: #007bff;
  color: #007bff;
}

Sidebar Navigation

.sidenav {
  width: 250px;
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  background-color: #2c3e50;
  padding: 20px 0;
  overflow-y: auto;
}

.sidenav a {
  display: block;
  padding: 15px 25px;
  color: white;
  text-decoration: none;
  transition: background-color 0.3s ease;
}

.sidenav a:hover,
.sidenav a.active {
  background-color: #34495e;
  border-left: 4px solid #007bff;
}

Breadcrumb Navigation

.breadcrumb {
  display: flex;
  list-style: none;
  padding: 10px 0;
  margin: 0;
}

.breadcrumb li + li::before {
  content: "/";
  padding: 0 10px;
  color: #6c757d;
}

.breadcrumb a {
  color: #007bff;
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

Best Practices

Navigation Best Practices

  • Keep navigation simple and clear
  • Highlight current page
  • Make links large enough to tap (44x44px)
  • Ensure keyboard navigation works
  • Use semantic HTML (<nav>, <ul>, <li>)
  • Provide skip navigation link
  • Test on mobile devices
  • Use ARIA labels for accessibility
  • Maintain consistent navigation across pages
  • Consider sticky navigation for long pages

Accessibility

<nav aria-label="Main navigation">
  <button aria-label="Toggle menu" aria-expanded="false">Menu</button>
  <ul>
    <li><a href="/" aria-current="page">Home</a></li>
    <li><a href="/about">About</a></li>
  </ul>
</nav>

Master navigation styling to create intuitive, accessible website navigation!

How is this guide?

March 7th, 2026

CSS Math Functions

Master CSS mathematical functions like calc(), min(), max(), and clamp() for dynamic, responsive layouts.

CSS Video Embedding

Learn CSS techniques for embedding and styling videos with responsive sizing, custom controls, and overlays.

© 2026CoderrShyamAll Rights Reserved.

On this page

Basic Horizontal Nav
Sticky Navigation
Dropdown Menu
Mobile Menu (Hamburger)
Search Bar in Nav
Nav with Logo
Mega Menu
Tab Navigation
Sidebar Navigation
Breadcrumb Navigation
Best Practices
Accessibility
Follow us on GitHub