Creating a stunning e-commerce website involves a combination of clean HTML, CSS, and JavaScript, along with optional frameworks like React, Bootstrap, or backend tools like Node.js, Firebase, or Shopify for a full-featured store.
Below, I’ll give you a complete responsive e-commerce website template using HTML, CSS (with Flexbox), and a bit of JavaScript for interactivity. This includes:
- A responsive layout
- Product grid
- Shopping cart functionality
- Modal for product details
- Mobile-friendly design
🛍️ E-Commerce Website Template (HTML + CSS + JS)
📁 File Structure
ecommerce-site/
├── index.html
├── style.css
└── script.js
1. index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Stylish E-Commerce</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
<div class="container">
<h1>Stylish Shop</h1>
<nav>
<a href="#">Home</a>
<a href="#">Shop</a>
<a href="#">Contact</a>
<button id="cart-icon" onclick="toggleCart()">🛒 <span id="cart-count">0</span></button>
</nav>
</div>
</header>
<main>
<section class="products">
<!-- Sample Product -->
<div class="product" onclick="showModal('product1')">
<img src="https://via.placeholder.com/250x200?text=Product+1" alt="Product 1">
<h3>Product One</h3>
<p>$29.99</p>
<button onclick="addToCart('Product One', 29.99, event)">Add to Cart</button>
</div>
<div class="product" onclick="showModal('product2')">
<img src="https://via.placeholder.com/250x200?text=Product+2" alt="Product 2">
<h3>Product Two</h3>
<p>$49.99</p>
<button onclick="addToCart('Product Two', 49.99, event)">Add to Cart</button>
</div>
<div class="product" onclick="showModal('product3')">
<img src="https://via.placeholder.com/250x200?text=Product+3" alt="Product 3">
<h3>Product Three</h3>
<p>$19.99</p>
<button onclick="addToCart('Product Three', 19.99, event)">Add to Cart</button>
</div>
</section>
<!-- Modal -->
<div id="product-modal" class="modal">
<div class="modal-content">
<span onclick="closeModal()">×</span>
<img id="modal-img" src="" alt="Product">
<h2 id="modal-title"></h2>
<p id="modal-price"></p>
<button onclick="addToCartFromModal()">Add to Cart</button>
</div>
</div>
<!-- Shopping Cart -->
<div id="cart" class="cart">
<h2>Shopping Cart</h2>
<ul id="cart-items"></ul>
<p><strong>Total: $<span id="cart-total">0.00</span></strong></p>
<button onclick="checkout()">Checkout</button>
</div>
</main>
<footer>
<p>© 2025 Stylish Shop. All rights reserved.</p>
</footer>
<script src="script.js"></script>
</body>
</html>
2. style.css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', sans-serif;
background-color: #f8f8f8;
color: #333;
line-height: 1.6;
}
.container {
width: 90%;
max-width: 1200px;
margin: auto;
}
header {
background: #111;
color: white;
padding: 1rem 0;
}
header h1 {
font-size: 1.8rem;
}
header nav {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
header a, #cart-icon {
color: white;
text-decoration: none;
margin: 0 10px;
font-size: 1rem;
background: none;
border: none;
cursor: pointer;
}
.products {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 20px;
padding: 20px;
}
.product {
background: white;
border-radius: 8px;
padding: 15px;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
cursor: pointer;
}
.product img {
max-width: 100%;
height: auto;
}
.product h3 {
margin: 10px 0;
}
.product p {
color: #e91e63;
font-weight: bold;
}
.modal {
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0,0,0,0.6);
display: none;
justify-content: center;
align-items: center;
}
.modal-content {
background: white;
padding: 20px;
border-radius: 10px;
position: relative;
max-width: 500px;
text-align: center;
}
.modal-content img {
max-width: 100%;
}
.modal-content span {
position: absolute;
top: 10px;
right: 20px;
font-size: 1.5rem;
cursor: pointer;
}
.cart {
background: white;
margin: 20px auto;
padding: 20px;
max-width: 400px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.cart ul {
list-style: none;
}
.cart li {
padding: 5px 0;
}
footer {
text-align: center;
padding: 20px;
background: #111;
color: white;
margin-top: 30px;
}
3. script.js
let cart = [];
let modalProduct = {};
function addToCart(productName, price, event) {
event.stopPropagation(); // prevent modal from opening when clicking "Add to Cart"
cart.push({ name: productName, price: price });
updateCart();
}
function addToCartFromModal() {
if (modalProduct.name) {
cart.push({ name: modalProduct.name, price: modalProduct.price });
updateCart();
closeModal();
}
}
function updateCart() {
const cartItems = document.getElementById("cart-items");
cartItems.innerHTML = "";
let total = 0;
cart.forEach((item, index) => {
const li = document.createElement("li");
li.textContent = `${item.name} - $${item.price.toFixed(2)}`;
cartItems.appendChild(li);
total += item.price;
});
document.getElementById("cart-count").textContent = cart.length;
document.getElementById("cart-total").textContent = total.toFixed(2);
}
function checkout() {
alert("Thank you for your purchase!");
cart = [];
updateCart();
}
function showModal(productId) {
const productMap = {
product1: { name: "Product One", price: 29.99, img: "https://via.placeholder.com/400x300?text=Product+1" },
product2: { name: "Product Two", price: 49.99, img: "https://via.placeholder.com/400x300?text=Product+2" },
product3: { name: "Product Three", price: 19.99, img: "https://via.placeholder.com/400x300?text=Product+3" }
};
modalProduct = productMap[productId];
document.getElementById("modal-img").src = modalProduct.img;
document.getElementById("modal-title").textContent = modalProduct.name;
document.getElementById("modal-price").textContent = `$${modalProduct.price.toFixed(2)}`;
document.getElementById("product-modal").style.display = "flex";
}
function closeModal() {
document.getElementById("product-modal").style.display = "none";
}
function toggleCart() {
const cartDiv = document.getElementById("cart");
cartDiv.style.display = cartDiv.style.display === "none" ? "block" : "block";
}
✅ Features
- Fully responsive layout
- Interactive product cards
- Click to open product detail modal
- Add to cart functionality
- Real-time cart updates
- Checkout alert
🚀 How to Use
- Save the code into
index.html, style.css, and script.js files.
- Open
index.html in your browser.
- You can replace placeholder images and product data with your own.
🔌 Want to Add More?
Here are some features you can add:
- Backend integration (Node.js, Firebase, Shopify)
- User authentication
- Product search & filters
- Payment integration (Stripe, PayPal)
- Admin dashboard
Would you like me to:
- Turn this into a React app?
- Connect it to Firebase or Stripe?
- Add product search or filters?
Let me know and I’ll help you take it to the next level! 🚀