Open In App

How to Create “Add to cart” Button in Bootstrap?

Last Updated : 18 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Creating an “Add to Cart” button in Bootstrap is simple and helps improve the shopping experience on your website. Bootstrap has ready-made styles that make it easy to create buttons that look good and work well on all devices.

Approach to creating an “Add to cart” Button in Bootstrap

  • Use a Bootstrap container to hold your content. This helps with responsive design. Inside this container, you can add headings, paragraphs, and buttons for your shopping cart.
  • Add a button for adding items to the cart. Use Bootstrap’s button classes and include an icon (like a shopping cart) using Glyphicons for visual appeal.
  • Use custom CSS to apply additional styling, such as margins and colors, to make the page visually appealing. Ensure that the text and buttons match your design theme

Example: In this example, we will see how to add a cart button using Bootstrap.

HTML
<!DOCTYPE html>
<html>
<head>
    <title>Bootstrap Shopping Cart</title>
    <meta name="viewport" 
          content="width=device-width, initial-scale=1" />
    <!-- CSS only -->
    <link rel="stylesheet" 
          href=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" />

    <!-- JavaScript Bundle with Popper -->
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
    </script>

    <script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js">
    </script>
    <!--CSS Code-->
    <style>
        .container {
            margin-top: 30px;
            color: green;
        }

        span {
            color: green;
        }
    </style>
</head>
<!--Body tag-->
<body>
    <div class="container" align="center">
        <h2>Code World</h2>
        <h3>Shopping-cart</h3>
        <p>
            <button type="button" class="btn btn-default btn-sm">
                <span class="glyphicon
                    glyphicon-shopping-cart">
                </span>
                <b> Add to Cart </b>
            </button>
        </p>
    </div>
</body>
</html>

Output:

Output

Output



Similar Reads