Sling Academy
Home/Tailwind CSS/How to Create a Hero Image with Tailwind CSS

How to Create a Hero Image with Tailwind CSS

Last updated: December 07, 2023

On many modern websites, there are usually one or several hero images. These are large photos and often take up space at the top of the page. The purpose of hero images is to highlight the website’s purpose in a concise way. The example below shows you how to create a typical hero image (with some text and a button in the foreground) by using Tailwind CSS.

Screenshot:

The code:

<body>
    <header
        class="w-full h-96 bg-[url('https://www.slingacademy.com/wp-content/uploads/2022/10/hero-image-example.webp')] bg-cover bg-center flex justify-center items-center">
        <div class="flex flex-col justify-center items-center">
            <h1 class=" text-center text-5xl text-white font-bold drop-shadow-lg">WELCOME TO
                <span class="text-amber-500">SLING ACADEMY</span>
            </h1>
            <p class="mt-5 text-center text-lg text-white opacity-70">This webiste is about programming and things like
                that</p>
            <a class="mt-8 px-12 py-3 bg-gradient-to-r from-amber-500 to-red-600 hover:from-amber-600 hover:to-red-700 text-xl text-white/70 font-semibold drop-shadow-lg rounded-full"
                href="#">Get Started</a>
        </div>
    </header>
    <div class="container p-20">
        <h1 class="text-4xl">Other Content</h1>
    </div>
</body>

That’s it. Happy coding & have fun with Tailwind CSS.

Next Article: Tailwind CSS: Create Image Hover Overlay Effects

Previous Article: Tailwind CSS: How to place text over an image

Series: Styling Text & Images with Tailwind CSS

Tailwind CSS

You May Also Like

  • Tailwind CSS: Make a Div 100% Height & Width of the Viewport
  • How to Zoom on Hover with Tailwind CSS (the easiest approach)
  • Using :not() selector in Tailwind CSS
  • Tailwind CSS: How to Create a Stepper
  • Using ::before and ::after in Tailwind CSS
  • Tailwind CSS: How to Create a Vertical Divider Line
  • How to Create Pill Buttons with Tailwind CSS
  • Tailwind CSS: How to Disable Text Selection
  • Tailwind CSS: How to Disable Resizing of Textarea
  • Tailwind CSS: Create a Floating Action Button (FAB)
  • Tailwind CSS: How to style the Select element
  • Tailwind CSS: Expand a Text Input on Focus (without Javascript)
  • Tailwind CSS: Create Image Hover Overlay Effects
  • How to Disable a Link with Tailwind CSS
  • Tailwind CSS: How to place text over an image
  • How to Create Frosted Glass Effect in Tailwind CSS
  • Styling Figure & Figcaption with Tailwind CSS
  • Tailwind CSS: How to Create Blurred Background Image
  • Tailwind CSS: Red Notification Badge with a Count