---
id: css-horizontal-navbar
title: "CSS Horizontal Navbar"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["horizontal navbar", "top navigation", "horizontal navigation bar", "flex navbar", "float navbar", "sticky navbar"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.87
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["css", "web", "frontend", "w3schools", "navbar", "navigation"]
raw_sources: ["https://www.w3schools.com/css/css_navbar_horizontal.asp"]
applied_in: []
github_commit: ""
---
# [[CSS Horizontal Navbar]]
## π― ν μ€ ν΅μ°° (One-line insight)
A horizontal navbar lays its list items side by side using either floating list items or a flexbox `
`, then adds hover/active states, dividers, and fixed or sticky positioning. [S1]
## π§ ν΅μ¬ κ°λ
(Core concepts)
- **Float method** β `ul li { float: left; }` with `overflow: hidden` on the `` lays links horizontally. [S1]
- **Flex method** β `display: flex` on the `` arranges links in a row. [S1]
- **Block links** β `display: block` on `a` makes the full link area clickable. [S1]
- **Active class** β `a.active` marks the current link with a highlight color. [S1]
- **Fixed/sticky positioning** β `position: fixed` (top/bottom) or `position: sticky` (with `top`) keeps the navbar in view while scrolling. [S1]
## π§© μΆμΆλ ν¨ν΄ (Extracted patterns)
- **Two layout methods** β floating list items (`float: left`) or a flex container (`display: flex`) both yield a horizontal row. [S1]
- **Dividers** β `border-right` on each `li` with `li:last-child { border-right: none; }` removes the trailing divider. [S1]
- **Right-aligned item** β `style="float:right"` on a single `- ` pushes one link to the right. [S1]
- **Sticky requires an offset** β at least one of `top`/`right`/`bottom`/`left` must be set for sticky to work. [S1]
## π μΈλΆ λ΄μ© (Details)
**Horizontal navbar with float** [S1]
```css
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
ul li {
float: left;
}
ul li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
ul li a:hover {
background-color: #111111;
}
```
**Horizontal navbar with flex** [S1]
```css
ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #333333;
display: flex;
}
ul li a {
display: block;
color: white;
padding: 14px 16px;
text-decoration: none;
}
ul li a:hover {
background-color: #111111;
}
```
**Horizontal centered navbar with flex** [S1]
```css
ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #333333;
display: flex;
justify-content: center;
}
```
**Active state** [S1]
```css
ul li a.active {
background-color: #04AA6D;
}
```
**Gray horizontal navbar** [S1]
```css
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: flex;
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}
```
**Right-align the last link** [S1]
```html
```
**Border dividers** [S1]
```css
/* Add a lightgray right border to all list items, except the last */
ul li {
float: left;
border-right: 1px solid #bbbbbb;
}
ul li:last-child {
border-right: none;
}
```
**Fixed top navbar** [S1]
```css
ul {
position: fixed;
top: 0;
width: 100%;
}
```
**Fixed bottom navbar** [S1]
```css
ul {
position: fixed;
bottom: 0;
width: 100%;
}
```
**Note** [S1]
Fixed position might not work properly on mobile devices.
**Sticky navbar** [S1]
```css
ul {
position: sticky;
top: 0;
}
```
**Note** [S1]
You must specify at least one of the `top`, `right`, `bottom` or `left` properties, for sticky positioning to work.
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
The page's applied examples are the dark float navbar, the flex navbar, the centered flex navbar, the green `.active` link, the gray flex navbar, the right-aligned About link, border dividers, fixed top/bottom navbars, and the sticky navbar. No external project/commit applications found in the source.
## π» μ½λ ν¨ν΄ (Code patterns)
Float-based horizontal navbar (language: CSS):
```css
ul li {
float: left;
}
ul li a {
display: block;
padding: 14px 16px;
text-decoration: none;
}
```
Sticky navbar (language: CSS):
```css
ul {
position: sticky;
top: 0;
}
```
## βοΈ λΉκ΅ λ° μ ν κΈ°μ€ (Comparison & decision criteria)
- **Float vs Flex layout** β The source presents two methods for laying out a horizontal navbar: floating the list items (`ul li { float: left; }`, with `overflow: hidden` on the `
`) or using a flex container (`display: flex` on the ``). Both produce a horizontal row of links; the flex method additionally enables `justify-content: center` for easy centering. [S1]
- **Fixed vs Sticky positioning** β `position: fixed` pins the navbar to the top or bottom of the viewport (but may not work properly on mobile), while `position: sticky` keeps it in flow until scrolled and requires at least one offset (`top`/`right`/`bottom`/`left`) to work. [S1]
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
No contradictions found in the source.
## β
κ²μ¦ μν λ° μ λ’°λ
- **μν:** draft
- **κ²μ¦ λ¨κ³:** conceptual (μ€μ μ μ© μ¬λ‘ λ°κ²¬ μ applied/validatedλ‘ μΉκ²© κ°λ₯)
- **μΆμ² μ λ’°λ:** B (W3Schools β widely used educational reference, not a primary standards body)
- **μ λ’° μ μ:** 0.87
- **μ€λ³΅ κ²μ¬ κ²°κ³Ό:** μ κ· μμ± (New discovery)
## π μ§μ κ·Έλν (Knowledge Graph)
- **μμ/루νΈ:** [[CSS Tutorial]]
- **κ΄λ ¨ κ°λ
:** [[CSS Navigation Bar]], [[CSS Vertical Navbar]], [[CSS Position]], [[CSS Flexbox]]
- **μ°Έμ‘° λ§₯λ½:** Referenced when building a top or bottom navigation bar with float or flex layout.
## π μΆμ² (Sources)
- [S1] W3Schools β CSS Horizontal Navbar β https://www.w3schools.com/css/css_navbar_horizontal.asp
## π λ³κ²½ μ΄λ ₯ (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "CSS Horizontal Navbar" page (Astra wiki-curation, P-Reinforce v3.1 format).