Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- CALCULATOR -->
<div class="calculator">
		<!-- CALCULATOR FORM -->
		<form class="calculator__form">
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<input class="calculator__display" id="display" type="text" disabled />
				</div>
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<button type="button" value="c" class="calculator__key calculator__clear"></button>
						<button type="button" value="<--" class="calculator__key calculator__backspace"></button>
						<button type="button" value="^3" class="calculator__key calculator__power"></button>
						<button type="button" value="+" class="calculator__key calculator__button"></button>
				</div>
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<button type="button" value="9" class="calculator__key calculator__button"></button>
						<button type="button" value="8" class="calculator__key calculator__button"></button>
						<button type="button" value="7" class="calculator__key calculator__button"></button>
						<button type="button" value="-" class="calculator__key calculator__button"></button>
				</div>
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<button type="button" value="6" class="calculator__key calculator__button"></button>
						<button type="button" value="5" class="calculator__key calculator__button"></button>
						<button type="button" value="4" class="calculator__key calculator__button"></button>
						<button type="button" value="*" class="calculator__key calculator__button"></button>
				</div>
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<button type="button" value="3" class="calculator__key calculator__button"></button>
						<button type="button" value="2" class="calculator__key calculator__button"></button>
						<button type="button" value="1" class="calculator__key calculator__button"></button>
						<button type="button" value="/" class="calculator__key calculator__button"></button>
				</div>
				<!-- CALCULATOR ROW -->
				<div class="calculator__row">
						<button type="button" value="0" class="calculator__key calculator__button"></button>
						<button type="button" value="." class="calculator__key calculator__button"></button>
						<button type="button" value="=" class="calculator__key calculator__key--equal"></button>
				</div>
		</form>
</div>
              
            
!

CSS

              
                *, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
}

body {
    font-family: sans-serif;
}

/* -------------- MAIN RULES ------------- */

.calculator {
    width: 250px;
    height: 350px;
    border: 2px solid black;
    margin: 100px auto 0;
    text-align: center;
    background-color: yellowgreen;
    box-shadow: 0 0 30px grey;
    border-radius: 4px;
}

.calculator__form {
    height: 100%;
    padding: 20px;
}

.calculator__row {
    margin: 10px 0;
    display: flex;
    justify-content: space-between;
}

.calculator__display {
    margin: 0 0 20px;
    width: 100%;
    border: 1px solid darkslateblue;
    padding: 4px 2px;
    text-align: right;
    font: 700 16px/1 Arial, sans-serif;
    color: darkslateblue;
    background-color: whitesmoke;
}

.calculator__key {
    width: 41px;
    height: 35px;
    cursor: pointer;
    border: none;
    transition: all .2s;
    text-transform: uppercase;
}

.calculator__key--equal {
    width: 98px;
}

.calculator__key:hover {
    background-color: yellow;
    font-weight: 700;
}

.calculator__key::-moz-focus-inner {
    border: none
}
              
            
!

JS

              
                $(document).ready(function () {

    // VARIABLES
    var calc = $('.calculator');
    var calcDisplay = calc.find('.calculator__display');
    var calcKeys = calc.find('.calculator__key');
    var calcButton = calc.find('.calculator__button');
    var calcClear = calc.find('.calculator__clear');
    var calcEqual = calc.find('.calculator__key--equal');
    var calcPower = calc.find('.calculator__power');
    var calcSpace = calc.find('.calculator__backspace');

    // INIT CALC KEYS
    calcKeys.each(function () {
        var current = $(this).attr('value');
        $(this).text(current);
    });

    // ADD NUMBERS TO INPUT
    calcButton.on('click', function () {
        calcDisplay.val( calcDisplay.val() + $(this).attr('value') );
    });

    // CLEAR INPUT
    calcClear.on('click', function () {
        calcDisplay.val('');
    });

    // SHOW RESULT
    calcEqual.on('click', function () {
        calcDisplay.val( eval( calcDisplay.val() ) );
    });

    // POWER BUTTON
    calcPower.on('click', function () {
        calcDisplay.val( Math.pow( calcDisplay.val(), 3 ) );
    });

    // BACKSPACE BUTTON
    calcSpace.on('click', function () { // https://www.w3schools.com/jsref/jsref_substring.asp
        calcDisplay.val( calcDisplay.val().substring(0, calcDisplay.val().length-1) );
    });

});
              
            
!
999px

Console