How to create a split navigation bar using CSS ?
Last Updated :
28 Apr, 2025
The article will demonstrate how to create a split navigation bar using CSS. There are two ways to make the split navigation bar these are with the help of flexbox properties and CSS position property. A split navigation bar is a popular layout where navigation links are divided into two sections. It is used to achieve a balanced look for the navbar.
Syntax
// Syntax forFlexbox and space-between
.class{
display: flex;
}
// Syntax for CSS Position Property
.class{
position: absolute;
right: 20px;
}
Using Flexbox and space-between
Using Flexbox with ' justify-content: space-between ' aligns items with maximum space between them, pushing the first item to the start and the last item to the end of the container. This creates a layout where space is distributed evenly, providing a clean and organized appearance to the elements.
Approach
- Create the structure of the navbar in HTML using different types of the elements including <div>, <ul>, <li>, and button.
- There are two unordered list defined where the first have three list items and the second have only one list item.
- Cretae a external stylesheet and link to the index.html file for defining the style to the navbar.
- Use property display flex and justify-content space between to split navigation bar.
Example 1: The example shows split navigation bar using CSS with various flexbox properties.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,initial-scale=1.0">
<title>Navbar</title>
<link rel="stylesheet"
href="index.css">
<link rel="stylesheet" href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<div class="box">
<div class="nav_list_box">
<div class="navlistleft">
<ul>
<li>
<a href="#">
<i class="fa fa-solid fa-house">
</i>
Home
</a>
</li>
<li>
<a href="#">
<i class="fa fa-solid fa-address-card">
</i>
About
</a>
</li>
<li>
<a href="#">
<i class="fa fa-solid fa-address-book">
</i>
Contact Us
</a>
</ul>
</div>
<div class="navlistright">
<ul>
<li>
<a href="#">
<i class="fa fa-solid fa-book">
</i>
Courses
</a>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
CSS
/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
background-color: rgb(111, 201, 108);
font-family: 'Poppins', sans-serif;
}
.nav_list_box {
display: flex;
justify-content: space-between;
align-items: center;
height: 10vh;
}
ul {
list-style: none;
}
.navlistleft ul {
display: flex;
align-items: center;
gap: 20px;
margin-left: 20px;
}
li {
font-size: 20px;
}
.navlistright ul {
margin-right: 20px;
}
li {
transition: .2s linear;
}
li:hover {
color: rgb(9, 21, 4);
transform: translateY(-3px);
}
a {
text-decoration: none;
color: rgb(23, 64, 7);
}
a:hover {
color: rgb(9, 21, 4);
font-weight: 700;
}
@media only screen and (max-width: 513px) {
li {
font-size: 15px;
}
}
@media only screen and (max-width: 424px) {
li {
font-size: 10px;
}
}
Output:
OutputUsing CSS Position Property
The CSS ' position: absolute' property allows an element to be positioned relative to its nearest positioned ancestor or the initial containing block. Elements with `position: absolute` are positioned based on their nearest positioned ancestor, creating layouts with more control over element placement.
Approach
- Create the structure of the navbar in HTML using different types of the elements including <div>, <ul>, <li>, and button. There is unordered list defined where four list items are defined.
- Cretae a external stylesheet and link to the index.html file for defining the style to the navbar.
- Style the list item and set the position property to absolute and right to 20px. It will give the effect of split navigation bar.
- Use fontawsome icons and different CSS properties to style the navbar.
Example 2: The example shows split navigation bar using CSS with position property.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Navbar</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href=
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<div class="box">
<div class="navlist">
<ul>
<li>
<a href="#">
<i class="fa fa-solid fa-house"></i>
Home
</a>
</li>
<li>
<a href="#">
<i class="fa fa-solid fa-address-card"></i>
About
</a>
</li>
<li>
<a href="#">
<i class="fa fa-solid fa-address-book"></i>
Contact Us
</a>
</li>
<li class="split">
<a href="#">
<i class="fa fa-solid fa-book"></i>
Courses
</a>
</li>
</ul>
</div>
</div>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
background-color: rgb(187, 121, 189);
font-family: 'Poppins', sans-serif;
}
ul {
list-style: none;
}
.navlist ul {
display: flex;
align-items: center;
gap: 20px;
margin-left: 20px;
height: 10vh;
}
li {
font-size: 20px;
transition: .2s linear;
}
li:hover {
transform: translateX(3px);
}
a {
text-decoration: none;
color: rgb(89, 10, 94);
}
a:hover {
color: rgb(68, 16, 67);
font-weight: 700;
}
.split {
position: absolute;
right: 20px;
}
@media only screen and (max-width: 513px) {
li {
font-size: 15px;
}
}
@media only screen and (max-width: 424px) {
li {
font-size: 10px;
}
}
Output:
Output
Similar Reads
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
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 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 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 a Responsive Navigation Bar in Tailwind CSS ? A Responsive Navigation Bar with collapsible elements is a crucial component of modern web design, allowing users to navigate seamlessly across various screen sizes. In this article, we'll explore how to implement such a navigation bar using Tailwind CSS, a utility-first CSS framework that enables r
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 Menu Icon using CSS ? The Menu Icon is mostly used on smaller screens, there's limited space to display a full navigation menu. A menu icon helps in hiding the navigation items initially and revealing them when the user needs them. In this article, we will see how To Create a Menu Icon using CSS. There are many ways to c
3 min read
How to Create A Sticky NavBar Using Tailwind CSS? Sticky Navbar in Tailwind CSS is mostly used in applications where maintaining quick access to navigation links is essential as users scroll through content. It ensures that the navbar remains visible at the top of the screen, enhancing user experience by providing constant access to key sections of
4 min read
How to create a Split Button Dropdown using CSS ? In this article, we will learn how to design a split button dropdown using CSS. Split buttons combine a main button with a dropdown, useful for adding interactive features to your website. This guide helps you improve your web design skills by showing you how to make a split button in easy steps. Ta
4 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