Centered navigation bar in HTML and CSS
Logo on the left, links in the middle, call to action on the right, collapsible menu on mobile.
Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.
This component also comes in
The code in HTML and CSS
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Barre de navigation centrée</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="demo">
<header class="nav" data-nav>
<div class="nav__bar">document.querySelectorAll("[data-nav]").forEach((nav) => {
const toggle = nav.querySelector("[data-nav-toggle]");
const setOpen = (open) => {
nav.toggleAttribute("data-open", open);
toggle.setAttribute("aria-expanded", String(open));
};
toggle.addEventListener("click", () => setOpen(!nav.hasAttribute("data-open")));
nav.addEventListener("keydown", (event) => {
if (event.key === "Escape" && nav.hasAttribute("data-open")) {
setOpen(false);
toggle.focus();
}:root {
--nav-bg: #ffffff;
--nav-border: #e2e8f0;
--nav-text: #334155;
--nav-strong: #0f172a;
--nav-accent: #1d4ed8;
--nav-accent-text: #ffffff;
--nav-ring: #1d4ed8;
--demo-bg: #f8fafc;
--demo-text: #334155;
}
Free component: copy it freely, including for commercial projects.
Other navigation bars components in HTML and CSS
Navigation bars components in HTML and CSS
A navigation that sits at the bottom of the screen, under the thumb, on phones, and becomes a horizontal bar at the top on desktop.
- Tailwind
- React
- CSS
- WordPress

The house name in the middle, links split on each side, restaurant or designer-shop style.
- Tailwind
- React
- CSS
- WordPress

A strip of practical details (phone, opening hours) above the main navigation.
- Tailwind
- React
- CSS
- WordPress