Horizontal Navigation

A responsive top navigation bar with dropdown menus, mobile hamburger menu, and call-to-action buttons. Ideal for marketing sites and web applications.

DropdownsMobile MenuResponsiveCTA Buttons

Installation

Terminal
ReactTailwind
TSX
npx @uiblox/cli add horizontal-nav

Preview

Source Code

Copy this code into your project. The navigation includes desktop dropdowns and a responsive mobile menu.

horizontal-nav.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"use client"; import { useState } from "react"; import Link from "next/link"; import { cn } from "@/lib/utils"; interface NavItem { label: string; href?: string; children?: { label: string; href: string; description?: string }[]; } const navItems: NavItem[] = [ { label: "Home", href: "/" }, { label: "Products", children: [ { label: "Analytics", href: "/products/analytics", description: "Measure and optimize" }, { label: "Automation", href: "/products/automation", description: "Streamline workflows" }, { label: "Integration", href: "/products/integration", description: "Connect your tools" }, ], }, { label: "Solutions", children: [ { label: "Enterprise", href: "/solutions/enterprise", description: "For large teams" }, { label: "Startups", href: "/solutions/startups", description: "Scale fast" }, { label: "Developers", href: "/solutions/developers", description: "Build with ease" }, ], }, { label: "Pricing", href: "/pricing" }, { label: "Docs", href: "/docs" }, ]; export function HorizontalNav() { const [mobileOpen, setMobileOpen] = useState(false); const [activeDropdown, setActiveDropdown] = useState<string | null>(null); return ( <header className="bg-white dark:bg-slate-900 border-b border-slate-200 dark:border-slate-800"> <nav className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div className="flex items-center justify-between h-16"> {/* Logo */} <Link href="/" className="flex items-center gap-2"> <div className="w-8 h-8 rounded-lg bg-gradient-to-br from-purple-500 to-indigo-600 flex items-center justify-center text-white font-bold"> B </div> <span className="text-xl font-bold text-slate-900 dark:text-white">Brand</span> </Link> {/* Desktop Navigation */} <div className="hidden md:flex items-center gap-1"> {navItems.map((item) => ( <div key={item.label} className="relative" onMouseEnter={() => item.children && setActiveDropdown(item.label)} onMouseLeave={() => setActiveDropdown(null)} > {item.href ? ( <Link href={item.href} className="px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors" > {item.label} </Link> ) : ( <button className="flex items-center gap-1 px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors"> {item.label} <ChevronDownIcon className="w-4 h-4" /> </button> )} {/* Dropdown */} {item.children && activeDropdown === item.label && ( <div className="absolute top-full left-0 mt-1 w-64 bg-white dark:bg-slate-900 rounded-xl shadow-lg border border-slate-200 dark:border-slate-700 py-2 z-50"> {item.children.map((child) => ( <Link key={child.href} href={child.href} className="block px-4 py-3 hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors" > <span className="block text-sm font-medium text-slate-900 dark:text-white"> {child.label} </span> {child.description && ( <span className="block text-xs text-slate-500 dark:text-slate-400 mt-0.5"> {child.description} </span> )} </Link> ))} </div> )} </div> ))} </div> {/* Right Section */} <div className="hidden md:flex items-center gap-3"> <Link href="/login" className="px-4 py-2 text-sm font-medium text-slate-600 dark:text-slate-300 hover:text-slate-900 dark:hover:text-white"> Sign in </Link> <Link href="/signup" className="px-4 py-2 text-sm font-medium text-white bg-purple-600 hover:bg-purple-700 rounded-lg transition-colors"> Get Started </Link> </div> {/* Mobile Menu Button */} <button onClick={() => setMobileOpen(!mobileOpen)} className="md:hidden p-2 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg" > {mobileOpen ? <XIcon /> : <MenuIcon />} </button> </div> </nav> {/* Mobile Menu */} {mobileOpen && ( <div className="md:hidden border-t border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900"> <nav className="px-4 py-4 space-y-1"> {navItems.map((item) => ( <div key={item.label}> {item.href ? ( <Link href={item.href} className="block px-4 py-3 text-slate-700 dark:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg"> {item.label} </Link> ) : ( <div> <span className="block px-4 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide"> {item.label} </span> {item.children?.map((child) => ( <Link key={child.href} href={child.href} className="block px-4 py-2 pl-8 text-slate-600 dark:text-slate-300 hover:bg-slate-100 dark:hover:bg-slate-800 rounded-lg"> {child.label} </Link> ))} </div> )} </div> ))} </nav> </div> )} </header> ); } function ChevronDownIcon({ className }: { className?: string }) { return ( <svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" /> </svg> ); } function MenuIcon() { return ( <svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" /> </svg> ); } function XIcon() { return ( <svg className="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> </svg> ); }