Creating Stylish Grid Layout with Hover Effects Using HTML and CSS

7 min read

In the dynamic world of web development, creating visually appealing layouts that engage users is essential.

In this tutorial, we’ll explore how to design a stylish grid layout with hover effects using HTML and CSS. This approach not only enhances the aesthetics of your webpage but also provides a delightful user experience.

Step-by-step Stylish Grid Layout with Hover Effects

Grid layouts are a popular choice for structuring content on webpages due to their flexibility and responsiveness. Adding hover effects to elements within the grid can further elevate the user experience by providing interactive and visually pleasing transitions.

See the Pen Hover Effects Using HTML and CSS – Botboxai by amitwebdev (@fitabouts) on CodePen.

Ready to transform your web design? Here are four stunning CSS hover effects to get you started:

  1. Subtle Opacity Fade:
  • Apply a subtle opacity transition to your elements for a sophisticated effect.
  • Experience the magic as the background darkens and the text becomes more prominent on hover.
  1. Colorful Transitions:
  • Infuse life into your design by incorporating vibrant color transitions.
  • Watch as each element transforms into a burst of color, adding a dynamic touch to your web page.
  1. Box Shadow Play:
  • Elevate your design with a playful box shadow transition on hover.
  • Experience the depth and dimensionality as elements lift off the page with a subtle shadow effect.
  1. Selective Disappearance:
  • Add an element of mystery with selective disappearance on hover.
  • Witness the intrigue as one element fades away while the others shine, creating a captivating visual experience.

HTML Structure

Let’s start by setting up the HTML structure. We’ll create a container with sibling elements, each representing a grid item.

<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS HOVER EFFECTS</title>
    /* CSS styles will be added here */

  <div class="container">
    <div class="sibling">Alice</div>
    <div class="sibling">Bob</div>
    <div class="sibling">Charlie</div>
    <div class="sibling">Diana</div>


CSS Styling

Now, let’s apply the CSS styles to create an eye-catching grid layout with hover effects.

body {
  background: #3c4858;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5rem;

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  border: 2px solid #237562;
  border-radius: 9px;
  padding: 50px;
  background-color: #165b67;

.sibling {
  padding: 18px;
  background-color: #56ccb0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 0.2em 0.2em rgba(0, 0, 0, 0.1);

.container:hover .sibling:not(:hover) {
  opacity: 0.6;

These styles create a grid layout with a border, padding, and a subtle hover effect on the grid items.

Understanding the Purpose and Effects of CSS Code

Let’s delve deeper into the CSS code to understand the purpose and effects of each section.

ALSO READ:  Creating a Love Calculator Using HTML, CSS, and JavaScript

1. Body Styling

body {
  background: #3c4858;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5rem;
  • Background Color: The background property sets the background color of the entire webpage to a dark blue-gray (#3c4858).
  • Flex Display: Using display: flex allows for a flexible box model. align-items and justify-content are set to ‘center,’ ensuring both horizontal and vertical centering of content within the viewport.
  • Margin: The margin property adds a margin of 5rem around the body, providing spacing between the content and the edges of the viewport.

2. Container Styling

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  border: 2px solid #237562;
  border-radius: 9px;
  padding: 50px;
  background-color: #165b67;
  • Grid Display: The container is styled as a grid using display: grid. It consists of four columns, each occupying an equal fraction of available space (1fr).
  • Gap: Introduces a 10px gap between grid items, enhancing visual separation.
  • Border: Applies a 2px solid border with a dark teal color (#237562) and rounded corners (border-radius: 9px).
  • Padding: Adds 50px of padding inside the container, providing space between the container’s content and its border.
  • Background Color: Sets the background color of the container to a teal shade (#165b67).

3. Sibling Styling

.sibling {
  padding: 18px;
  background-color: #56ccb0;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 0.2em 0.2em rgba(0, 0, 0, 0.1);
  • Padding: Adds 18px of padding to each sibling element, contributing to their overall size.
  • Background Color: Sets the background color of each sibling to a light green shade (#56ccb0).
  • Transition: Establishes a smooth transition effect over 0.3 seconds for changes in background-color and box-shadow properties, providing a visually appealing transformation on hover.
  • Box Shadow: Introduces a subtle box shadow to each sibling, creating a lifted appearance with a slight shadow effect.

4. Hover Effects

.container:hover .sibling:not(:hover) {
  opacity: 0.6;
  • Container Hover: Activates when the container is hovered.
  • Siblings Not Hovered: Selects sibling elements within the container that are not currently being hovered over.
  • Opacity Change: Reduces the opacity of non-hovered siblings to 0.6. This results in a visual effect where the sibling being hovered over becomes more prominent while others partially fade away, adding a dynamic and interactive aspect to the design.

What is Grid Layouts?

Grid Layout is a CSS layout system that allows web developers to create complex and responsive web designs with a two-dimensional grid structure. It enables precise control over the placement and sizing of elements in both rows and columns, providing a powerful and flexible way to organize content on a webpage.

Key features of CSS Grid Layout:

1. Two-Dimensional Layout: Unlike traditional layouts that primarily focus on one dimension (either rows or columns), CSS Grid Layout works in two dimensions, allowing for a grid of rows and columns.
2. Grid Container and Items: The layout is structured within a container element (the grid container) that holds a set of child elements (the grid items).
3. Explicit Grids and Implicit Grids: Developers can define an explicit grid by specifying the number and size of rows and columns. Additionally, the grid can also accommodate items that are placed dynamically, forming an implicit grid.
4. Fractional Units (fr): The fr unit allows developers to specify a fraction of the available space, making it easy to create flexible and responsive layouts.
5. Alignment and Justification: CSS Grid provides properties for aligning and justifying items within the grid, both vertically and horizontally.
6. Grid Lines and Gutters: Grid lines separate the rows and columns, and gutters define the space between them. Developers have control over the sizing of these elements.
7. Responsive Design: CSS Grid is particularly useful for creating responsive designs. Media queries can be used to adjust the layout based on the device’s screen size.
8. Nested Grids: Grids can be nested within one another, allowing for even more complex and hierarchical layouts.

ALSO READ:  Unlock Engagement: Social Media Icons Hover Effect CSS Animation Guide

What is Hover Effects?

Hover effects, in the context of web design, refer to visual changes or animations that occur when a user hovers their mouse pointer over an interactive element on a webpage. These effects are a way to enhance user experience, providing feedback and interactivity, making the website more engaging and dynamic. When a user hovers over an element, such as a button, image, or link, the appearance or behavior of that element can change, creating a responsive and interactive design.

Common hover effects include changes in color, size, opacity, or the addition of animations and transitions. The goal is to provide visual cues to users, indicating that an element is interactive or clickable. Hover effects are widely used in navigation menus, buttons, image galleries, and other interactive components to make the user interface more intuitive and visually appealing.


In conclusion, combining HTML and CSS allows you to easily create visually stunning grid layouts with hover effects. These effects not only enhance the user experience but also add a touch of interactivity to your webpage.

Feel free to customize the colors, content, and layout according to your preferences and branding. Experiment with different styles to make your website stand out in the vast landscape of the internet.

Remember, a well-designed and interactive website not only attracts users but also contributes to a positive user experience, which is crucial for the success of any web project.

Happy coding!😘

Avatar for Amit

Amit (7)

Hello! I'm Amit Kumar, a passionate teacher specializing in web development and digital marketing. With several years of experience in the industry, I am dedicated to sharing my knowledge and expertise to empower aspiring learners like you.

ALSO READ:  Modern CSS Input Animations: Enhancing Form Input UX with CSS Animation

Teaching Philosophy:

I believe in creating a dynamic and engaging learning environment where students can thrive. My teaching approach focuses on hands-on experience, practical applications, and real-world examples. I strive to make complex concepts understandable and enjoyable, ensuring that you not only grasp the fundamentals but also develop the skills necessary to excel in web development and digital marketing.

Web Development Expertise:

As a web development instructor, I am well-versed in HTML, CSS, JavaScript, and various frameworks such as React and Angular. I will guide you through the process of building responsive and user-friendly websites, exploring topics like front-end development, back-end integration, database management, and more. Together, we will delve into the latest trends and best practices in web development, equipping you with the tools to create stunning online experiences.

Digital Marketing Mastery:

In the rapidly evolving digital landscape, digital marketing is crucial for businesses to thrive. Through my digital marketing courses, I will help you navigate the intricacies of search engine optimization (SEO), social media marketing, content strategy, email marketing, and analytics. Gain insights into effective marketing techniques, harness the power of data-driven decision-making, and learn how to craft compelling campaigns that drive results.

Passion for Teaching:

Teaching is not just a profession for me; it's my passion. I find great joy in witnessing my students grow and succeed. I am committed to fostering a supportive learning community where questions are encouraged, ideas are shared, and challenges are overcome together. I am here to guide you every step of the way and provide the necessary resources for your personal and professional development.

Join me on this exciting journey of learning and discovery. Let's unlock your potential in web development and digital marketing together. Enroll in my courses today and embark on a transformative educational experience that will propel your career forward.
Start Learning Today!

5 1 vote
Article Rating
Notify of


Inline Feedbacks
View all comments
Would love your thoughts, please comment.x

Discover more from Botboxai

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top