Design a Responsive Product Card using HTML, CSS & JavaScript Last Updated : 26 Jul, 2024 Summarize Suggest changes Share Like Article Like Report We'll create a responsive product card using HTML, CSS, and JavaScript. A product card is a basic UI element used in e-commerce websites to show product details in a simple format. We're creating a one-size-fits-all product card for online use. It's designed to work well on any screen size so it will be fully responsive. Output preview:final outputPrerequisitesBasic knowledge of HTML, CSS, and JavaScriptText editor Visual Studio CodeWeb browser Google ChromeApproachHTML Structure:First, we create an HTML structure for the product card including the product image, product title, and product price. Plan how to place everything on the card.CSS Styling:After setting up the HTML, we move on to the next step. Next up, we style the product card with CSS. This is all about deciding on the look. Colors, fonts, space, borders, and alignment.Responsive Design: Use CSS media queries. This makes sure the product card fits well on all devices like desktops, tablets, or mobiles as per screen width.Use CSS FLEXBOX : Learn to use CSS Flexbox. It makes a card layout flexible and adjusts itself based on the space available. Make sure it's flexible. This helps adjust with space.JavaScript Interactivity: If needed, we can make the product card interactive with JavaScript. This may add hover effects. Event Handling : In JavaScript, use special tools called event listeners. They can make a card look different when we hover over it. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PRODUCT CARD</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="product-wrapper"> <div class="product"> <div class="img"> <img src= "https://media.geeksforgeeks.org/img-practice/prod/courses/261/Web/Content/dsa-web_1705410455.webp"> </div> <div class="info"> <div class="details"> <h1>DSA - Python</h1> <p>₹3998 <del>₹3999</del></p> </div> <div class="buy-btn"> <button>DETAILS</button> </div> </div> </div> </div> <div class="product-wrapper"> <div class="product"> <div class="img"> <img src= "https://media.geeksforgeeks.org/img-practice/prod/courses/439/Web/Content/bootstrap-graphic_1705401384.webp"> </div> <div class="info"> <div class="details"> <h1>Bootstrap</h1> <p>₹499 <del>₹999</del></p> </div> <div class="buy-btn"> <button>DETAILS</button> </div> </div> </div> </div> <div class="product-wrapper"> <div class="product"> <div class="img"> <img src= "https://media.geeksforgeeks.org/img-practice/prod/courses/270/Web/Content/Java-Programming_1705409391.webp"> </div> <div class="info"> <div class="details"> <h1>Java Programming</h1> <p>₹1999 <del>₹3999</del></p> </div> <div class="buy-btn"> <button>DETAILS</button> </div> </div> </div> </div> <div class="product-wrapper"> <div class="product"> <div class="img"> <img src= "https://media.geeksforgeeks.org/img-practice/prod/courses/554/Web/Content/ds-applied_1705409158.webp"> </div> <div class="info"> <div class="details"> <h1>Data Science</h1> <p>₹21999 <del>₹29999</del></p> </div> <div class="buy-btn"> <button>DETAILS</button> </div> </div> </div> </div> </div> <script src="./script.js"></script> </body> </html> CSS /* style.css */ * { margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif; } body { background: #e3e3e3; } .container { width: 100%; min-height: 100vh; padding: 20px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 20px; } del { color: red; } .product-wrapper { width: calc(25% - 20px); background: white; overflow: hidden; border-radius: 10px 10px 10px 10px; transform: scale(0.95); } .product { width: 100%; background: #e8c8fb; } .product .img { height: 80%; width: 100%; } .product .img img { height: 100%; width: 100%; transition: all 0.5s; object-fit: contain; } .product .info { width: 100%; height: 20%; transition: transform 0.5s; display: flex; } .info .details { height: 100%; width: 65%; padding: 20px; } h1 { font-size: 15px; } .buy-btn { display: flex; justify-content: center; align-items: center; width: 35%; } .buy-btn button { cursor: pointer; padding: 10px 20px; border: 1px solid #3d0686; background: #5f00dd; color: #fff; box-shadow: 0 19px 38px rgba(0, 0, 0, 0.30), 0 15px 12px rgba(0, 0, 0, 0.22); border-radius: 25px; } @media screen and (max-width:1200px) { .product-wrapper { width: calc(33.33% - 20px); } .container { align-content: start; } } @media screen and (max-width:950px) { .product-wrapper { width: calc(50% - 20px); } } @media screen and (max-width:600px) { .product-wrapper { width: 100%; } } @media screen and (max-width:350px) { .product-wrapper { height: auto; } .info .details { width: 100%; } .info { flex-direction: column; } .buy-btn { width: 100%; padding-bottom: 10px; } } JavaScript // Script.js document.addEventListener("DOMContentLoaded", function () { const images = document.querySelectorAll("img"); images.forEach(image => { image.addEventListener("mouseenter", function () { this.style.transform = "scale(1.1) translateY(-15px)"; this.style.boxShadow = "5px 20px 30px rgba(0, 0, 0, 0.2)"; }); image.addEventListener("mouseleave", function () { this.style.transform = "scale(1) translateY(0)"; this.style.boxShadow = "none"; }); }); }); Output: Advertise with us Next Article Design a Responsive Product Card using HTML, CSS & JavaScript A abulhax Follow Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read Article Tags : Project JavaScript Web Technologies JavaScript-Projects Like