DEV Community

Cover image for Building a Stunning Hero Section in React with Tailwind CSS
Devmaster
Devmaster

Posted on

Building a Stunning Hero Section in React with Tailwind CSS

In modern web development, a well-designed hero section serves as the focal point of a website, capturing the visitor's attention and setting the tone for the rest of the site. In this article, we'll walk through the creation of an eye-catching hero section using React and Tailwind CSS.

**

Creating a Dynamic Hero Section

**

The HeroSection component featured here demonstrates how to leverage React's capabilities alongside Tailwind CSS to create a visually appealing and responsive hero section. Here's a breakdown of the implementation:

import React from 'react';

const HeroSection = () => {
  return (
    <div className="bg-gradient-to-r from-purple-900 via-black to-blue-900 min-h-screen flex flex-col text-white">
      {/* Navbar */}
      <nav className="w-full flex justify-between items-center py-4 px-8">
        <div className="text-2xl font-bold text-white">Bakar</div>
        <ul className="hidden md:flex space-x-8 text-lg">
          <li><a href="#home" className="hover:underline">Home</a></li>
          <li><a href="#about" className="hover:underline">About</a></li>
          <li><a href="#service" className="hover:underline">Service</a></li>
          <li><a href="#portfolio" className="hover:underline">Portfolio</a></li>
          <li><a href="#contact" className="hover:underline">Contact</a></li>
        </ul>
        <button className="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">Hire Me</button>
      </nav>

      {/* Hero Section */}
      <div className="flex-grow flex flex-col lg:flex-row items-center justify-center text-center lg:text-left space-y-8 lg:space-y-0 lg:space-x-8 mt-12">
        <div className="flex flex-col items-center lg:items-start max-w-lg">
          <p className="text-lg mb-2">HELLO THERE, WELCOME TO MY SITE</p>
          <h1 className="text-5xl font-bold mb-2">I'm Alex Stark</h1>
          <h2 className="text-3xl font-bold text-pink-500 mb-4">A Full Stack Developer & UI/UX Designer</h2>
          <div className="flex space-x-4 mb-4">
            <button className="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">See Portfolio</button>
            <button className="bg-gray-800 hover:bg-gray-900 text-white font-bold py-2 px-4 rounded">Contact Me</button>
          </div>
        </div>
        <div className="relative">
          <img 
            src="https://img.freepik.com/premium-photo/flat-style-vector-illustration-web-developer-character_1237084-86771.jpg?w=740" 
            alt="Alex Stark" 
            className="w-64 h-64 lg:w-80 lg:h-80 rounded-lg border-4 object-cover border-pink-500" 
          />
        </div>
      </div>
    </div>
  );
};

export default HeroSection;

Enter fullscreen mode Exit fullscreen mode

**

Key Features:

**
Gradient Background: The section utilizes a gradient background (bg-gradient-to-r from-purple-900 via-black to-blue-900) to create a vibrant and engaging visual experience that transitions smoothly between colors.

Responsive Design: Tailwind CSS's utility classes ensure that the component is responsive, adapting gracefully to different screen sizes. For example, the navbar and hero text scale accordingly, providing a seamless user experience across devices.

Modern Navbar: The navbar is designed with a clean, minimalistic approach, featuring navigation links and a "Hire Me" button that stands out with its pink background and hover effects.

Hero Content Layout: The hero content is split into two sections: text and an image. This layout is adaptable to both small and large screens, enhancing the overall visual hierarchy and making the content more accessible.

Interactive Elements: The buttons within the hero section are styled to offer clear call-to-action prompts. The "See Portfolio" and "Contact Me" buttons are prominently displayed, encouraging user engagement with interactive hover effects.

Image Styling: The hero image is carefully chosen and styled with rounded corners and a border, which complements the overall theme while drawing attention to the central visual element.

**

Conclusion

**
This HeroSection component showcases how to effectively combine React and Tailwind CSS to build a striking hero section that not only looks great but also performs well on various devices. By employing responsive design techniques and Tailwind's utility classes, developers can create components that are both visually appealing and user-friendly.

Top comments (0)