Open In App

Design a Responsive Product Card using HTML, CSS & JavaScript

Last Updated : 26 Jul, 2024
Comments
Improve
Suggest changes
3 Likes
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:

ProductCardHTML
final output

Prerequisites

Approach

  • HTML 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 se­tting up the HTML, we move­ on to the next step. Ne­xt up, we style the product card with CSS. This is all about de­ciding 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 device­s like desktops, tablets, or mobile­s as pe­r 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 nee­ded, we can make the­ product card interactive with JavaScript. This may add hover e­ffects.
    • Event Handling : In JavaScript, use­ special tools called eve­nt listeners. They can make a card look diffe­rent when we hover ove­r 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 JavaScript

Output:


Next Article

Similar Reads