SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 24 of 35

CSS Navigation Bar Tutorial — Dropdown Menu Included

4 min read · Free · No login needed

Almost every website has a navigation bar — the row of links at the top that takes you to Home, Courses, About, or Contact. Without it, a visitor would be lost on the very first page. A navigation bar is just an HTML list of links, styled with CSS until it looks like a proper menu instead of a bullet list.

Diagram — see how it fits together
Diagram: CSS Navigation Bar

The trick is simple: take a <ul>, remove its bullets and spacing, lay its items out in a row, and style the links inside them as blocks with padding and a background colour. Once that base is in place, you can add hover effects, mark the current page, and even build dropdown menus.

Turning a list into a bar

Start with a <ul> inside a <nav> element. Remove the bullets with list-style-type: none and the default spacing with margin: 0 and padding: 0. Then give the <ul> a dark background colour and make it a flex container with display: flex — the list items line up in a row automatically.

Syntax — a horizontal bar

ul.nav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  background-color: #333;
  display: flex;
}
ul.nav a {
  display: block;
  color: white;
  padding: 14px 20px;
  text-decoration: none;
}

Each link is display: block, so the whole padded area is clickable — not just the letters. That matters on phones, where a finger is much wider than a mouse pointer.

Hover and the active page

A link should react when the mouse passes over it. The :hover pseudo-class changes its background colour, which tells the visitor "you can click here". The page the visitor is currently on gets a special class, usually called active, with a different colour — often green — so they always know where they are.

ul.nav a:hover {
  background-color: #111;
}
ul.nav a.active {
  background-color: #04aa6d;
}
Note: The active class is not automatic — you add class="active" to the link of the current page in your HTML. Each page of your site marks its own link as active.

Dropdown menus

A dropdown is a small menu that appears when you hover over one link, like "Courses" opening to show HTML, CSS, and Python. It works with two ideas: the parent <li> is position: relative, and the submenu is position: absolute and hidden with display: none. A :hover rule on the parent flips it to display: block, and the submenu drops down underneath.

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
}
.dropdown:hover .dropdown-content {
  display: block;
}
Tip: Use display: flex on the <ul> instead of floating the <li> elements. Floats need a clearfix and are easy to break; flex lines the items up in a row with one line of CSS.

Common mistakes

  • Forgetting list-style-type: none — the bullets stay and the bar looks like a plain list.
  • Forgetting margin: 0 and padding: 0 on the <ul> — the browser's default spacing pushes the bar away from the edges.
  • Styling the <li> instead of the <a> — only the letters become clickable, and the padding area does nothing.
  • Positioning the dropdown without position: relative on its parent — the submenu appears in a random place on the page instead of under its link.
  • Making the hover colour the same as the normal colour — the visitor gets no feedback that the link can be clicked.

Remember

  • A nav bar is a <ul> with bullets and spacing removed, laid out in a row.
  • Make links display: block with padding, so the whole area is clickable.
  • :hover changes the link's background; .active marks the current page.
  • A dropdown hides with display: none and appears on :hover.
  • The dropdown's parent needs position: relative and the menu needs position: absolute.

Example explained

  • ul.nav — the whole menu: bullets and default spacing removed, a dark background, and display: flex so the items sit in a row.
  • ul.nav a — every link is a block with white text and wide padding, so the full coloured area is clickable.
  • ul.nav a:hover — when the mouse passes over a link, its background turns darker, showing it can be clicked.
  • ul.nav a.active — the Home link carries the active class, so it is green and the visitor knows which page they are on.
  • .dropdown-content — the Courses submenu is hidden with display: none and position: absolute; .dropdown:hover .dropdown-content shows it when the mouse hovers over Courses.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Chai Shop Navigation</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; }
ul.nav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  background-color: #333;
  display: flex;
}
ul.nav li { position: relative; }
ul.nav a {
  display: block;
  color: white;
  padding: 14px 20px;
  text-decoration: none;
}
ul.nav a:hover { background-color: #111; }
ul.nav a.active { background-color: #04aa6d; }
.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
.dropdown-content a { color: black; padding: 12px 16px; }
.dropdown-content a:hover { background-color: #f1f1f1; color: black; }
.dropdown:hover .dropdown-content { display: block; }
main { padding: 20px; }
h1 { color: #333; }
</style>
</head>
<body>

<ul class="nav">
<li><a class="active" href="#">Home</a></li>
<li class="dropdown"><a href="#">Courses</a>
  <div class="dropdown-content">
  <a href="#">HTML</a>
  <a href="#">CSS</a>
  <a href="#">Python</a>
  </div>
</li>
<li><a href="#">Menu</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>

<main>
<h1>Welcome to Kamal Chai Shop</h1>
<p>Hover over <strong>Courses</strong> in the bar above to see the dropdown menu open.</p>
<p>The green link is the page you are on right now.</p>
</main>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Navigation Bar Tutorial — Dropdown Menu Included

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is a navigation bar made of?

An HTML list of links, with bullets and spacing removed, laid out in a row.

2. How do you make a whole nav link clickable?

Make the links display: block with padding, so the whole area, not just the letters, is clickable.

3. How does a dropdown menu appear?

It hides with display: none and appears on :hover. Its parent needs position: relative and the menu needs position: absolute.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Ethical Hacking & Cyber Security Workshop
View
Full Stack PHP Development Course 2026
₹3,000
View
AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →