Bootstrap snippet and html example. calculator

Bootstrap 3.3.7 snippet "calculator" with HTML, CSS, and JS. Copy, paste, and customize this responsive UI component for your project.

HTML code

Clean, semantic HTML that powers this Bootstrap 3.3.7 snippet. Copy and paste it into your page (with Bootstrap loaded) to reproduce the exact layout shown in the preview.

İŞTE KOD 

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>JavaScript Projects</title>
    <meta ID="description" content="">
    <meta ID="viewport" content="width=device-width, initial-scale=1">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <style>
        #output {
            height: 45px;
            background-color: black;
            color: aqua;
            width: 100%;
            font-size: 2em;
            padding: 5px;
            text-align: right;
            margin-bottom: 25px;
            overflow: hidden;
        }
             #mycalcu {
            width: 350px;
            background-color: dimgray;
            height: 350px;
            padding: 5px;
        }
          .cbutton {
            font-size: 2em;
            width: 40px;
            margin: 4px;
            padding: 4px;
        }
        .container {
            padding: 25px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div id="mycalcu">
            <div class="col-xs-12">
                <div id="output"></div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">1</div>
                    <div class="btn btn-primary cbutton">2</div>
                    <div class="btn btn-primary cbutton">3</div>
                    <div class="btn btn-primary cbutton">+</div>
                    <div class="btn btn-primary cbutton">C</div>
                </div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">4</div>
                    <div class="btn btn-primary cbutton">5</div>
                    <div class="btn btn-primary cbutton">6</div>
                    <div class="btn btn-primary cbutton">-</div>
                </div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">7</div>
                    <div class="btn btn-primary cbutton">8</div>
                    <div class="btn btn-primary cbutton">9</div>
                    <div class="btn btn-primary cbutton">*</div>
                </div>
                <div class="col-xs-12">
                    <div class="btn btn-primary cbutton">.</div>
                    <div class="btn btn-primary cbutton">0</div>
                    <div class="btn btn-primary cbutton">=</div>
                    <div class="btn btn-primary cbutton">/</div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var mybtn = document.getElementsByClassName("cbutton");
        var myOutput = document.getElementById("output");
        var myCal = '';
        var myCom = false;
        var mySwitch = false;
        var myOpe = ["+", "-", "*", "/"];
        //console.log(mybtn);
        for (var i = 0; i < mybtn.length; i++) {
            mybtn[i].addEventListener("click", function () {
                var myValue = this.innerHTML;
                if (myCom || myCal == "0") {
                    myCom = false;
                    myCal = '';
                }
                if (myValue == "+" || myValue == "-" || myValue == "*" || myValue == "/") {
                    if (mySwitch) {
                        mySwitch = false;
                        if (myOpe.indexOf(myOutput.innerHTML.slice(-1)) > -1) {
                            myCal = myCal.substring(0, myCal.length - 1);
                        } else {
                            myCal = eval(myCal);
                        }
                    }
                    mySwitch = true;
                }
                if (myValue == "=") {
                    myValue = '';
                    if (myOpe.indexOf(myOutput.innerHTML.slice(-1)) == -1) {
                        myCal = eval(myCal);
                    }
                } else if (myValue == "C") {
                    myCal = 0;
                    myCom = true;
                } else if (myOutput.innerHTML.indexOf(".") > -1 && myValue == ".") {
                    myValue = '';
                } else {
                    myCal = myCal + myValue;
                }
                myOutput.innerHTML = myCal;
            });
        }
    </script>
</body>
</html>
 

CSS code

Scoped CSS that styles the component. Paste it after Bootstrap 3.3.7 to keep the design, spacing, and responsiveness consistent.

body{margin-top:20px;}

Similar snippets

Bootstrap example and template. social network login

social network login

Bootstrap example and template. meet our team with hover effect

meet our team with hover effect

Bootstrap example and template. user profile with timeline photos and setting

user profile with timeline photos and setting

Bootstrap example and template. profile timeline

profile timeline

Bootstrap example and template. Admin Panel Quick Shortcuts

Admin Panel Quick Shortcuts

Bootstrap example and template. responsive video with description

responsive video with description

Bootstrap example and template. Responsive UI Card

Responsive UI Card

Bootstrap example and template. service icons

service icons

FAQ

How do I use this snippet?

Include Bootstrap 3.3.7, paste the HTML, add the CSS block, and include the JS (if any) to mirror the live preview.

Can I use it in commercial projects?

Yes. It’s free for personal and commercial work; check the snippets license for details.

Is it responsive?

Yes. It inherits the responsive grid and components from Bootstrap 3.3.7.

Bootstrap example and template. calculator

About this bootstrap example/template

Optimized for copy‑paste: clean HTML, scoped CSS, and minimal JS so you can ship production‑ready UI faster and keep designs consistent.

Mobile‑first and responsive by default. Tested across modern browsers to reduce polish time on your project.

Already trusted in 2.7K+ views. Reuse this snippet to speed up landing pages, dashboards, or onboarding flows.

Bootstrap 3.3.7

<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>

<script src='https://netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>

This code example is based on bootstrap 3.3.7 and the grid system of this framework

Responsive

Based on bootstrap framework makes all the layouts perfectly responsive for all devices

Crossbrowser compatibility

Tested on all major browsers, it works smoothly on all of them

semantic html 5

Built on html / css3 the code quality is really amazing

Simple Integration

This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working