Tailwind helps you style your web pages quickly using ready-made classes. This example shows how to create a simple component that says "Hello World" with nice styles.
First Tailwind component (Hello World)
<div class="text-center text-blue-600 font-bold text-2xl">Hello World</div>Use class attribute to add Tailwind classes.
Classes like text-center and text-blue-600 control alignment and color.
<div class="text-center text-red-500 font-semibold text-xl">Hello World</div><div class="text-left text-green-700 italic text-3xl">Hello World</div>This is a complete HTML page using Tailwind CSS from a CDN. The body uses flexbox to center the message both vertically and horizontally. The message is styled with blue color, bold font, and larger text size. It also includes accessibility with role and aria-label.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>First Tailwind Component</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-100 flex items-center justify-center min-h-screen"> <div class="text-center text-blue-600 font-bold text-2xl" role="main" aria-label="Greeting message"> Hello World </div> </body> </html>
Tailwind classes are mobile-first and responsive by default.
Use semantic HTML and accessibility attributes for better user experience.
You can try changing the color or size by editing the class names and refreshing the browser.
Tailwind uses simple class names to style elements quickly.
Adding classes like text-center and text-blue-600 changes alignment and color.
Using Tailwind CDN lets you try styles without setup.