Toggle navigation
☰
HTML
CSS
Scripting
Database
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tailwind CSS Sticky Navbar</title> <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.2.1"></script> </head> <body class="bg-gray-50 min-h-[300vh]"> <!-- Main Sticky Navbar --> <nav class="sticky top-0 z-50 bg-white border-b border-gray-200 px-6 h-16 flex items-center justify-between" x-data="{ open: false }"> <div class="flex items-center"> <div class="w-8 h-8 rounded bg-indigo-600 flex items-center justify-center text-white font-bold mr-2">S</div> <span class="text-xl font-bold tracking-tight">StickNav</span> </div> <!-- Desktop Navigation --> <div class="hidden md:flex items-center space-x-10 h-full"> <a href="##" class="text-sm font-bold text-gray-500 hover:text-indigo-600 border-b-2 border-transparent hover:border-indigo-600 h-full flex items-center transition pt-1">Features</a> <a href="##" class="text-sm font-bold text-gray-500 hover:text-indigo-600 border-b-2 border-transparent hover:border-indigo-600 h-full flex items-center transition pt-1">Resources</a> <a href="##" class="text-sm font-bold text-gray-500 hover:text-indigo-600 border-b-2 border-transparent hover:border-indigo-600 h-full flex items-center transition pt-1">About</a> <button class="bg-indigo-600 text-white px-5 py-2 rounded-lg text-sm font-bold shadow-lg shadow-indigo-100 transition hover:bg-indigo-700">Explore</button> </div> <!-- Mobile Button --> <button @click="open = !open" class="md:hidden p-2 text-gray-600"> <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" /> </svg> </button> <!-- Mobile Menu --> <div class="md:hidden absolute top-16 left-0 right-0 bg-white border-b border-gray-100 p-6 space-y-4 shadow-xl" x-show="open" @click.away="open = false" style="display: none;"> <a href="##" class="block text-lg font-bold text-gray-800">Features</a> <a href="##" class="block text-lg font-bold text-gray-800">Resources</a> <a href="##" class="block text-lg font-bold text-gray-800 border-b pb-4">About</a> <button class="block w-full bg-indigo-600 text-white py-4 rounded-xl font-bold">Explore Now</button> </div> </nav> <!-- Instructional Content --> <main class="max-w-4xl mx-auto py-20 px-6 text-center"> <h1 class="text-5xl font-black text-gray-900 mb-8 leading-tight">Scroll down to see the navbar stick to the top.</h1> <p class="text-gray-500 text-lg mb-12">This standard sticky navbar gives users quick and constant access to site navigation no matter how far they scroll through your content.</p> <!-- Repeated Content Blocks to Enable Scrolling --> <div class="space-y-12"> <div class="h-64 bg-white rounded-3xl shadow-sm border border-gray-100 p-8 flex items-center justify-center italic text-gray-300">Content Block 1</div> <div class="h-64 bg-white rounded-3xl shadow-sm border border-gray-100 p-8 flex items-center justify-center italic text-gray-300">Content Block 2</div> <div class="h-64 bg-white rounded-3xl shadow-sm border border-gray-100 p-8 flex items-center justify-center italic text-gray-300">Content Block 3</div> <div class="h-64 bg-white rounded-3xl shadow-sm border border-gray-100 p-8 flex items-center justify-center italic text-gray-300">Content Block 4</div> </div> </main> <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script> </body> </html>