Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?
Next article icon

How to Create a Horizontal Navigation Bar in HTML and CSS?

Last Updated : 16 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Creating a horizontal navigation bar in HTML and CSS involves using an unordered list (<ul>) for navigation items and applying CSS to style them for a horizontal layout.

We will create a horizontal navigation bar using HTML and CSS, including styling for layout, spacing, and appearance, as well as adding interactivity with hover effects and ensuring responsiveness to media queries.

Approach to Create Horizontal Navigation Bar

  • Create a <nav> Element: The <nav> element will serve as the container for your navigation bar. Inside it, you’ll use an unordered list (<ul>) with list items (<li>) for each navigation link.
  • Use CSS Flexbox for Layout: CSS Flexbox allows you to arrange the list items horizontally and control their spacing and alignment.
  • Add Styling for Links: Each navigation link (<a>) inside the list items will be styled for color, spacing, and hover effects to improve interactivity.
  • Make the Navbar Responsive: Media queries will help make the navigation bar responsive, adjusting the layout on smaller screens by switching from a horizontal layout to a vertical one.

Example: Horizontal Navigation Bar in HTML and CSS

Here is a complete example, including HTML and CSS:

HTML
<!DOCTYPE html> <html>  <head>     <title>Building a Horizontal Navigation Bar</title>     <style>         * {             margin: 0;             padding: 0;         }          body {             font-family: 'Arial', sans-serif;         }          .navbar {             display: flex;             position: sticky;             align-items: center;             justify-content: space-between;             top: 0px;             background: rgb(255 127 39);             background-blend-mode: darken;             background-size: cover;             color: white;             padding: 10px 20px;         }          .nav-list {             display: flex;             list-style: none;         }          .nav-list li {             margin-right: 20px;         }          .nav-list li:last-child {             margin-right: 0;         }          .nav-list li a {             text-decoration: none;             color: white;             font-size: 18px;             transition: color 0.3s ease-in-out;         }          .nav-list li a:hover {             color: #ffd700;             /* Change the color on hover */         }          .rightNav {             text-align: right;         }          #search {             padding: 8px;             font-size: 16px;             border: 2px solid #fff;             border-radius: 5px;         }          .btn {             background-color: #ffd700;             color: #000;             border: none;             padding: 8px 12px;             border-radius: 5px;             cursor: pointer;             transition: background-color 0.3s ease-in-out;         }          .btn:hover {             background-color: #000;             /* Change the background color on hover */             color: #ffd700;         }     </style> </head>  <body>     <nav class="navbar">         <ul class="nav-list">             <li><a href="#home">Home</a></li>             <li><a href="#about">About Us</a></li>             <li><a href="#services">Services</a></li>             <li><a href="#contact">Contact</a></li>         </ul>         <div class="rightNav">             <input type="text" name="search" id="search" placeholder="Search">             <button class="btn btn-sm">Search</button>         </div>     </nav> </body>  </html> 

Output:

horizontal-navigation-bar

Horizontal Navigation Bar in HTML and CSS



Next Article
How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?

C

codingbeast12
Improve
Article Tags :
  • Web Technologies
  • Web Templates

Similar Reads

  • How to create Vertical Navigation Bar using HTML and CSS ?
    After reading this article, you will be able to build your own vertical navigation bar. To follow this article you only need some basic understanding of HTML and CSS. Let us start writing our vertical navigation bar, first, we will write the structure of the navigation bar. In this tutorial, we crea
    3 min read
  • How to Create Animated Navigation Bar with Hover Effect using HTML and CSS ?
    The Navigation bar or navbar or menu-bar is the most important component of any web or mobile application. The user can only navigate from one page to another page through this menu. It is usually provided at the top of the website to provide a better UX (user experience). Approach: The approach is
    3 min read
  • Create a Hoverable Side Navigation with HTML, CSS and JavaScript
    To create hoverable side navigation with icon on any website there is a need for two things HTML and CSS. If you want to attach the icons on the navigation bar then you need a font-awesome CDN link. These features make the website looks cool than a normal website where the nav-bar is old-school desi
    4 min read
  • How to Create a Navigation Bar with CSS Flexbox?
    The navigation bar is a crucial aspect of modern web design. We can create a responsive navigation bar using CSS Flexbox, which provides a flexible and efficient way to layout elements, making it an excellent choice for creating navigation bars. Below are different possible ways for creating differe
    5 min read
  • How to create navigation bar using <div> tag in HTML ?
    In this article, we will know to create the navigation bar using the <div> tag in HTML. The Navbar is a navigation header that contains the links to navigate to the different pages or sections of the site that helps to make the website interactive. The navbar is an important & fundamental
    3 min read
  • Create A Bottom Navigation Menu using HTML and CSS
    This article will show you how to create a bottom navigation menu using HTML and CSS. The navigation menu is an essential component in modern web design. It allows users to navigate through a website easily. Here, we use HTML to create the structure of the Bottom Navigation menu, and CSS add styles
    2 min read
  • How to add horizontal line in HTML ?
    Creating a visually appealing and well-structured webpage often involves the use of horizontal lines. These lines help separate different sections of content, making it easier for users to read and understand the information presented. In this guide, we’ll explore two effective methods to add horizo
    3 min read
  • How To Create a More Button in a Navigation Bar using CSS?
    Adding a More button in a navigation bar is used to handle overflow items when there is insufficient space to display all navigation links. We will explore how to implement a More button using CSS. ApproachCreate a web page structure using the <nav> element, which contains list items for each
    2 min read
  • How to Create a Navigation Bar with Icons in Tailwind CSS ?
    A navigation bar, commonly known as a nav bar, serves as a fundamental component of user interface design, facilitating seamless navigation across a website or application. Using the icons in the navigation bar gains a distinctive advantage in visual communication. Icons streamline navigation by usi
    2 min read
  • How to create a top navigation bar using CSS?
    A top navigation bar is a horizontal bar that typically contains links to different sections of a website. It is a fundamental part of a website's layout and helps users navigate easily. In this article, we will explore different approaches to creating a top navigation bar using CSS. These are the f
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences