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 Center Div Horizontally And Vertically</title> <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.2.1"></script> </head> <body class="antialiased"> <div class="flex items-center justify-center min-h-screen bg-slate-100 dark:bg-slate-900 p-4"> <div class="bg-white dark:bg-slate-800 rounded-xl shadow-lg p-8 max-w-md w-full text-center"> <div class="w-16 h-16 bg-indigo-100 dark:bg-indigo-900/50 rounded-full flex items-center justify-center mx-auto mb-4"> <svg class="w-8 h-8 text-indigo-600 dark:text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"></path> </svg> </div> <h2 class="text-2xl font-bold text-slate-800 dark:text-white mb-2">Perfectly Centered</h2> <p class="text-slate-600 dark:text-slate-400 mb-6">This entire card is horizontally and vertically centered in the viewport using Tailwind's flex utilities.</p> <button class="bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-2 px-6 rounded-lg transition-colors">Amazing</button> </div> </div> </body> </html>