Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Design a Online Cake Shop Website in HTML CSS & JavaScript
Next article icon

Design a Online Grocery Website in HTML CSS & JavaScript

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Online grocery shopping has become increasingly popular, especially in recent times. This project aims to create a user-friendly and responsive website for purchasing groceries online. Users can browse through the various categories, add items to their cart, and proceed to checkout making their grocery shopping experience convenient and efficient.

Grocery Website preview
Online Grocery Store

Prerequisites:

  • HTML
  • CSS
  • JavaScript

Approach:

  • First, We Set up the project directory structure with the separate files for the HTML, CSS and JavaScript.
  • Then, we design the layout and structure of the website using the HTML incorporating sections for the <header>, navigation menu, product display, cart and checkout.
  • Style the website using the CSS to enhance the visual appeal and ensure consistency across different pages.
  • Implement interactive features and functionalities using the JavaScript, such as adding items to cart, updating quantities and calculating totals.
  • Test the website thoroughly to ensure functionality and responsiveness across different devices and browsers.
  • Deploy the website to the web hosting service to make it accessible online.

Example: Use the code below to develop a grocery website with HTML, CSS, and JavaScript.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <title>Online Grocery Store</title>     <style>         * {             box-sizing: border-box;         }          body {             font-family: Arial, sans-serif;             margin: 0;             padding: 0;             background-color: #f3f4f6;             color: #333;         }          .container {             max-width: 1200px;             margin: 0 auto;             padding: 20px;             display: flex;             justify-content: space-between;         }          header {             background: linear-gradient(to right, #11998e, #38ef7d);             color: #ffffff;             padding: 20px 0;             text-align: center;             margin-bottom: 20px;             width: 100%;             border-radius: 10px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);         }          header h1 {             font-size: 2.5rem;             margin: 0;         }          header nav ul {             list-style-type: none;             padding: 0;             margin: 0;             display: flex;             justify-content: center;             gap: 20px;         }          header nav ul li {             display: inline;         }          header nav ul li a {             color: #ffffff;             text-decoration: none;             font-size: 1.2rem;             transition: color 0.3s ease;         }          header nav ul li a:hover {             color: #f3f4f6;         }          #products {             margin-bottom: 20px;             flex: 1;         }          .product {             background-color: #ffffff;             border-radius: 10px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);             padding: 20px;             margin-bottom: 20px;             display: flex;             flex-direction: column;             align-items: center;             text-align: center;             transition: transform 0.3s ease;         }          .product:hover {             transform: translateY(-5px);         }          .product img {             width: 100%;             max-width: 200px;             height: auto;             margin-bottom: 1rem;             border-radius: 8px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);         }          .product h3 {             font-size: 1.5rem;             margin: 0;         }          .product p {             color: #666666;             margin-bottom: 0.5rem;         }          .product button {             background: linear-gradient(to right, #11998e, #38ef7d);             color: #ffffff;             border: none;             padding: 8px 16px;             border-radius: 4px;             cursor: pointer;             transition: background-color 0.3s ease;             outline: none;         }          .product button:hover {             background: linear-gradient(to right, #0c8976, #30c270);         }          #cart {             background-color: #ffffff;             border-radius: 10px;             box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);             padding: 20px;             width: 300px;         }          #cart h2 {             font-size: 2rem;             margin-bottom: 1rem;             color: #333;         }          #cart-items {             list-style-type: none;             padding: 0;             margin: 0;         }          .cart-item {             display: flex;             justify-content: space-between;             align-items: center;             margin-bottom: 0.5rem;         }          .cart-item button {             background: linear-gradient(to right, #ff4d4f, #ff6382);             color: #ffffff;             border: none;             padding: 4px 8px;             border-radius: 4px;             cursor: pointer;             transition: background-color 0.3s ease;             outline: none;         }          .cart-item button:hover {             background: linear-gradient(to right, #e63c3f, #f34d6f);         }          .quantity {             display: flex;             align-items: center;         }          .quantity button {             background: linear-gradient(to right, #11998e, #38ef7d);             color: #ffffff;             border: none;             padding: 4px 8px;             border-radius: 4px;             cursor: pointer;             transition: background-color 0.3s ease;             outline: none;         }          .quantity button:hover {             background: linear-gradient(to right, #0c8976, #30c270);         }          .quantity input {             width: 40px;             text-align: center;             border: 1px solid #ccc;             border-radius: 4px;             margin: 0 0.5rem;             padding: 4px;             outline: none;         }     </style> </head>  <body>     <header>         <div class="container">             <h1>Online Grocery Store</h1>             <nav>                 <ul>                     <li><a href="#">Home</a></li>                     <li><a href="#">Products</a></li>                     <li><a href="#">Cart</a></li>                     <li><a href="#">Contact</a></li>                 </ul>             </nav>         </div>     </header>     <div class="container">         <section id="products">             <h2>Available Products</h2>             <div class="grid grid-cols-1 sm:grid-cols-2                          md:grid-cols-3 lg:grid-cols-4 gap-6">                 <div class="product">                     <img                      src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308174326/d12.jpg"                      alt="Salt">                     <h3>Salt</h3>                     <p>$2.00</p>                     <button onclick="addToCart('Salt', 2.00)">                           Add to Cart                       </button>                 </div>                 <div class="product">                     <img                      src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308174500/f12.jpg"                      alt="Apple">                     <h3>Apple</h3>                     <p>$5.00</p>                     <button onclick="addToCart('Apple', 5.00)">                           Add to Cart                       </button>                 </div>                 <div class="product">                     <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308174616/o12.jpg" alt="Orange">                     <h3>Orange</h3>                     <p>$4.00</p>                     <button onclick="addToCart('Orange', 4.00)">                           Add to Cart                       </button>                 </div>                 <div class="product">                     <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240308181947/o123.jpg"                      alt="Oil">                     <h3>Oil</h3>                     <p>$8.00</p>                     <button onclick="addToCart('Oil', 8.00)">                           Add to Cart                       </button>                 </div>             </div>         </section>         <aside id="cart">             <h2>Shopping Cart</h2>             <ul id="cart-items">             </ul>             <button id="buy-button" onclick="checkout()">Buy</button>         </aside>     </div>     <script>         let Items = [];         function addToCart(name, price) {             const index = Items.findIndex(item => item.name === name);             if (index !== -1) {                 Items[index].quantity += 1;             } else {                 const item = {                     name: name,                     price: price,                     quantity: 1                 };                 Items.push(item);             }             updateCartDisplay();         }         function deleteFromCart(index) {             Items.splice(index, 1);             updateCartDisplay();         }         function updateQuantity(index, quantity) {             Items[index].quantity = quantity;             updateCartDisplay();         }         function checkout() {             let totalPrice = 0;             Items.forEach(item => {                 totalPrice += item.price * item.quantity;             });             alert(`Total price: $${totalPrice.toFixed(2)}`);         }         function updateCartDisplay() {             const cartElement = document.getElementById('cart-items');             cartElement.innerHTML = '';             Items.forEach((item, index) => {                 const li = document.createElement('li');                 li.className = 'cart-item';                 li.innerHTML = `                     <span>${item.name} - $${item.price.toFixed(2)} x                      <div class="quantity">                         <button onclick="updateQuantity(${index},                          ${item.quantity - 1})">-</button>                         <input type="number"                          value="${item.quantity}"                          min="1" max="10"                          onchange="updateQuantity(${index},                          this.value)">                         <button                          onclick="updateQuantity(${index},                          ${item.quantity + 1})">+</button>                     </div>                     </span>                     <button onclick="deleteFromCart(${index})">Delete</button>                 `;                 cartElement.appendChild(li);             });         }     </script> </body>  </html> 

Output:


You can Also Try Mentioned Features in Your Grocery App

To make your online grocery store more attractive and user-friendly , you can try following methods to it.

  • Add hover effects to buttons to improve user interaction and visual feedback.
    (Learn here)
  • Create a feedback or contact form so customers can send suggestions or issues.
    (Learn here)
  • Implement search functionality to help users find specific grocery items quickly.
    (Learn here)
  • Include user login and registration functionality for personalized user experiences.
    (Learn here)
  • Use local storage to save cart data so users don’t lose their cart on refresh.
    (Learn here)
  • Add a loading animation or spinner when fetching or updating cart items.
    (Learn here)
  • Display product ratings and reviews to help users make informed decisions.
    (Learn here)
  • Make it mobile-responsive using media queries for a great experience on all devices.
    (Learn here)

Next Article
Design a Online Cake Shop Website in HTML CSS & JavaScript

M

mguru4c05q
Improve
Article Tags :
  • Project
  • JavaScript
  • Web Technologies
  • Dev Scripter
  • JavaScript-Projects
  • Dev Scripter 2024

Similar Reads

  • Design a Online Cake Shop Website in HTML CSS & JavaScript
    Every business is going online nowadays for better growth and productivity. We are going to build an online cake shop website that will represent the shop in a good manner having features of online ordering and views and many more. PrerequisitesHTMLCSSJavaScriptApproachWe first create an HTML file w
    14 min read
  • Design a School Website in HTML CSS and JavaScript
    A School Website developed using HTML, CSS, and JavaScript is an interactive platform that provides information about the school, its faculty, courses, events, and other relevant details. It incorporates responsive design principles to ensure compatibility across various devices, offering an engagin
    8 min read
  • Design Responsive Flower Store in HTML CSS & JavaScript
    In this article, we will see how can we design a Responsive Flower Store with the help of HTML, CSS, and JavaScript. Prerequisites:HTMLCSSJAVASCRIPT Approach:Created a login form using basic html CSS Created Signup form .Created a Sign out Cart page on the main page first Created a navbar with home
    15+ min read
  • Design Joke Generator App in HTML CSS & JavaScript
    We will go to learn how can we create a Joke generator app using HTML, CSS, and JavaScript. We will also add a feature to copy the generated joke. We will use API to fetch the jokes and will show those jokes on the screen. PrerequisitesHTMLCSSJavaScriptApproachCreate the Joke Generator Application U
    3 min read
  • Design a Recipe App in HTML CSS & JavaScript
    We will create an attractive and styled application that gives the recipe of food, and dishes entered by the user. The user needs to enter the required food name and click on the button. The application uses an External API to fetch the food recipe and represent it in an attractive form. The user ca
    6 min read
  • Design a Business Agency Website in HTML CSS & JavaScript
    A business agency website can be used to showcase any kind of business in an attractive and interactive way to the users. It contains different sections that represent the services offered by your business. Approach:The HTML structure includes various sections such as the header, navigation, main co
    12 min read
  • Design a Double Slider Sign In & Sign Up Form in HTML CSS & JavaScript
    To design a double slider sign-in and sign-up form using HTML, CSS and JavaScript on a website. One can combine them into one form with a slider instead of having separate pages for logging in and registration. By clicking the buttons, we'll slide between the login and registration sections. We'll a
    5 min read
  • Design a Survey Form using HTML CSS and JavaScript
    In this article, we are going to implement a survey form using HTML, CSS, and JavaScript. In this form, we will get data about the interest of people in sports. In this implementation, the data will be stored in a CSV file after successful form validations. Preview of final output: Let us have a loo
    5 min read
  • Design a Student Attendance Portal in HTML CSS & JavaScript
    The Student Attendance Portal is a web application that allows users to mark attendance for students in different classes, add class and students according to requirements, providing a user-friendly interface to update and visualize attendance records. Approach:In the first step, we will create a fo
    10 min read
  • How to Host HTML, CSS & JavaScript Website on Vercel ?
    In this article, we will host HTML, CSS & JavaScript Websites on Vercel. Every web developer wants to not only create a website but also host it properly, ensuring that visitors and others have a problem-free experience while visiting your website and with Vercel you can seamlessly host your web
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences