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

Auto Save

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

              
                <!--  Switch to full page view so the Dark Mode toggle will be in the frame ^_^  -->

<!-- Fork it on Github: https://github.com/theHocineSaad/Neumorphism-JavaScript-Calculator-with-Dark-Mode -->

<div class="nightModeToggle">
        <div class="switch"></div>
        <svg id="sun" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 60 60" style="enable-background:new 0 0 60 60;" xml:space="preserve">
            <g>
            <path style="fill:#F0C419;" d="M30,0c-0.552,0-1,0.448-1,1v6c0,0.552,0.448,1,1,1s1-0.448,1-1V1C31,0.448,30.552,0,30,0z"></path>
            <path style="fill:#F0C419;" d="M30,52c-0.552,0-1,0.448-1,1v6c0,0.552,0.448,1,1,1s1-0.448,1-1v-6C31,52.448,30.552,52,30,52z"></path>
            <path style="fill:#F0C419;" d="M59,29h-6c-0.552,0-1,0.448-1,1s0.448,1,1,1h6c0.552,0,1-0.448,1-1S59.552,29,59,29z"></path>
            <path style="fill:#F0C419;" d="M8,30c0-0.552-0.448-1-1-1H1c-0.552,0-1,0.448-1,1s0.448,1,1,1h6C7.552,31,8,30.552,8,30z"></path>
            <path style="fill:#F0C419;" d="M46.264,14.736c0.256,0,0.512-0.098,0.707-0.293l5.736-5.736c0.391-0.391,0.391-1.023,0-1.414
                    s-1.023-0.391-1.414,0l-5.736,5.736c-0.391,0.391-0.391,1.023,0,1.414C45.752,14.639,46.008,14.736,46.264,14.736z"></path>
            <path style="fill:#F0C419;" d="M13.029,45.557l-5.736,5.736c-0.391,0.391-0.391,1.023,0,1.414C7.488,52.902,7.744,53,8,53
                    s0.512-0.098,0.707-0.293l5.736-5.736c0.391-0.391,0.391-1.023,0-1.414S13.42,45.166,13.029,45.557z"></path>
            <path style="fill:#F0C419;" d="M46.971,45.557c-0.391-0.391-1.023-0.391-1.414,0s-0.391,1.023,0,1.414l5.736,5.736
                    C51.488,52.902,51.744,53,52,53s0.512-0.098,0.707-0.293c0.391-0.391,0.391-1.023,0-1.414L46.971,45.557z"></path>
            <path style="fill:#F0C419;" d="M8.707,7.293c-0.391-0.391-1.023-0.391-1.414,0s-0.391,1.023,0,1.414l5.736,5.736
                    c0.195,0.195,0.451,0.293,0.707,0.293s0.512-0.098,0.707-0.293c0.391-0.391,0.391-1.023,0-1.414L8.707,7.293z"></path>
            <path style="fill:#F0C419;" d="M50.251,21.404c0.162,0.381,0.532,0.61,0.921,0.61c0.13,0,0.263-0.026,0.39-0.08l2.762-1.172
                    c0.508-0.216,0.746-0.803,0.53-1.311s-0.804-0.746-1.311-0.53l-2.762,1.172C50.272,20.309,50.035,20.896,50.251,21.404z"></path>
            <path style="fill:#F0C419;" d="M9.749,38.596c-0.216-0.508-0.803-0.746-1.311-0.53l-2.762,1.172
                    c-0.508,0.216-0.746,0.803-0.53,1.311c0.162,0.381,0.532,0.61,0.921,0.61c0.13,0,0.263-0.026,0.39-0.08l2.762-1.172
                    C9.728,39.691,9.965,39.104,9.749,38.596z"></path>
            <path style="fill:#F0C419;" d="M54.481,38.813L51.7,37.688c-0.511-0.207-1.095,0.041-1.302,0.553
                    c-0.207,0.512,0.041,1.095,0.553,1.302l2.782,1.124c0.123,0.049,0.25,0.073,0.374,0.073c0.396,0,0.771-0.236,0.928-0.626
                    C55.241,39.603,54.994,39.02,54.481,38.813z"></path>
            <path style="fill:#F0C419;" d="M5.519,21.188L8.3,22.312c0.123,0.049,0.25,0.073,0.374,0.073c0.396,0,0.771-0.236,0.928-0.626
                    c0.207-0.512-0.041-1.095-0.553-1.302l-2.782-1.124c-0.513-0.207-1.095,0.04-1.302,0.553C4.759,20.397,5.006,20.98,5.519,21.188z"></path>
            <path style="fill:#F0C419;" d="M39.907,50.781c-0.216-0.508-0.803-0.745-1.311-0.53c-0.508,0.216-0.746,0.803-0.53,1.311
                    l1.172,2.762c0.162,0.381,0.532,0.61,0.921,0.61c0.13,0,0.263-0.026,0.39-0.08c0.508-0.216,0.746-0.803,0.53-1.311L39.907,50.781z"></path>
            <path style="fill:#F0C419;" d="M21.014,9.829c0.13,0,0.263-0.026,0.39-0.08c0.508-0.216,0.746-0.803,0.53-1.311l-1.172-2.762
                    c-0.215-0.509-0.802-0.747-1.311-0.53c-0.508,0.216-0.746,0.803-0.53,1.311l1.172,2.762C20.254,9.6,20.625,9.829,21.014,9.829z"></path>
            <path style="fill:#F0C419;" d="M21.759,50.398c-0.511-0.205-1.095,0.04-1.302,0.553l-1.124,2.782
                    c-0.207,0.512,0.041,1.095,0.553,1.302c0.123,0.049,0.25,0.073,0.374,0.073c0.396,0,0.771-0.236,0.928-0.626l1.124-2.782
                    C22.519,51.188,22.271,50.605,21.759,50.398z"></path>
            <path style="fill:#F0C419;" d="M38.615,9.675c0.396,0,0.771-0.236,0.928-0.626l1.124-2.782c0.207-0.512-0.041-1.095-0.553-1.302
                    c-0.511-0.207-1.095,0.041-1.302,0.553L37.688,8.3c-0.207,0.512,0.041,1.095,0.553,1.302C38.364,9.651,38.491,9.675,38.615,9.675z"></path>
            </g>
            <circle style="fill:#F0C419;" cx="30" cy="30" r="20"></circle>
            <circle style="fill:#EDE21B;" cx="30" cy="30" r="15"></circle></svg>

        <svg id="moon" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 499.712 499.712" style="enable-background:new 0 0 499.712 499.712;" xml:space="preserve">
                <path style="fill:#FFD93B;" d="M146.88,375.528c126.272,0,228.624-102.368,228.624-228.64c0-55.952-20.16-107.136-53.52-146.88
                    C425.056,33.096,499.696,129.64,499.696,243.704c0,141.392-114.608,256-256,256c-114.064,0-210.608-74.64-243.696-177.712
                    C39.744,355.368,90.944,375.528,146.88,375.528z"></path>
                <path style="fill:#F4C534;" d="M401.92,42.776c34.24,43.504,54.816,98.272,54.816,157.952c0,141.392-114.608,256-256,256
                    c-59.68,0-114.448-20.576-157.952-54.816c46.848,59.472,119.344,97.792,200.928,97.792c141.392,0,256-114.608,256-256
                    C499.712,162.12,461.392,89.64,401.92,42.776z"></path>
                <g>
                <polygon style="fill:#FFD83B;" points="128.128,99.944 154.496,153.4 213.472,161.96 170.8,203.56 180.864,262.296 
                        128.128,234.568 75.376,262.296 85.44,203.56 42.768,161.96 101.744,153.4 	"></polygon>
                <polygon style="fill:#FFD83B;" points="276.864,82.84 290.528,110.552 321.104,114.984 298.976,136.552 304.208,166.984 
                        276.864,152.616 249.52,166.984 254.752,136.552 232.624,114.984 263.2,110.552 	"></polygon></g></svg>            
    </div>
    <span class="tooltip">Click To Copy ❤</span>
    <div class="calculator">

        <div class="screen">
            <div class="screenContent">
                <p id="result"><span id="resultText" onclick="copy()" onmouseleave="restoreText()" style="color: #373737">0</span></p>
                
                <p class="calculation"><span id="calculationText"></span></p>
            </div>
        </div>

        <div class="numPad">
            <div id="clear" class="style circle"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="#eb3b5a"><path d="M17.573 1.848c.083.699-.476 1.152-1.182 1.152h-8.774c-.704 0-1.266-.452-1.182-1.156-1.329.281-4.435 1.159-4.435 2.516 0 .303.103.7.235 1.361 3.175 2.953 15.758 3.088 19.476.244.159-.824.289-1.278.289-1.611 0-1.333-3.091-2.223-4.427-2.506zm3.113 6.897c-.868 4.587-2.184 10.54-2.709 13.287-1.079 1.312-3.545 1.968-6.013 1.968s-4.935-.656-6.013-1.968c-.529-2.884-1.834-8.868-2.684-13.414 3.154 1.274 7.398 1.401 8.895 1.401 1.771 0 5.561-.151 8.524-1.274zm-13.069-6.763c.922 0 1.669-1.08 1.669-1.982h5.437c0 .902.747 1.982 1.668 1.982h-8.774z"/></svg></div>
            <div id="division" class="style circle ariOpeColor">/</div>
            <div id="multiplication" class="style circle ariOpeColor">x</div>
            <div id="subtraction" class="style circle ariOpeColor">-</div>
            <div id="num7" class="style circle numColor">7</div>
            <div id="num8" class="style circle numColor">8</div>
            <div id="num9" class="style circle numColor">9</div>
            <div id="addition" class="style circle ariOpeColor">+</div>
            <div id="num4" class="style circle numColor">4</div>
            <div id="num5" class="style circle numColor">5</div> 
            <div id="num6" class="style circle numColor">6</div>
            <div id="num1" class="style circle numColor">1</div>
            <div id="num2" class="style circle numColor">2</div>
            <div id="num3" class="style circle numColor">3</div>
            <div id="num0" class="style zero">0</div>
            <div id="dot" class="style circle numColor">.</div>
            <div id="equal" class="style equal">=</div>
        </div> 

    </div>

              
            
!

CSS

              
                /*  Switch to full page view so the Dark Mode toggle will be in the frame ^_^  */
  
/* Fork it on Github: https://github.com/theHocineSaad/Neumorphism-JavaScript-Calculator-with-Dark-Mode */

@import url('https://fonts.googleapis.com/css?family=Nova+Round&display=swap');

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body{
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(-45deg, #FA8BFF, #2BD2FF, #FFE53B,#FF2525, #FBDA61);
	background-size: 800% 800%;
	animation: gradient 40s ease infinite;
}

@keyframes gradient {
	0% {
		background-position: 0% 50%;
	}
	50% {
		background-position: 100% 50%;
	}
	100% {
		background-position: 0% 50%;
	}
}

.nightModeToggle{
    width: 60px;
    height: 30px;   
    background-color: white;
    margin-bottom: 10px;
    border-radius: 500px;
    box-shadow: 0px 10px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 9px;
    position: relative;
    cursor: pointer;
    transition: background-color .5s ease-in-out;
}

.nightModeToggleNM{
    background: #373737;
}

.nightModeToggle svg{
    width: 15px;
    height: 15px;
}

.switch{
    width: 20px;
    height: 20px;
    background-color: #373737;
    border-radius: 500px;
    position: absolute;
    left: 6px;
    transition: left 0.5s ease-in-out, background-color 0.5s ease-in-out;
}

.switchNM{
    left: 33px;
    background-color: white;
}

.calculator{
    min-width: 273px;
    min-height: 448px;


    background: #EBECF1;
    box-shadow: 0px 10px 50px rgba(0, 0, 0, 0.15);
    border-radius: 24px;

    font-family: Nova Round;
    font-style: normal;
    font-weight: normal;
    font-size: 24px;
    line-height: 29px;
    transition: background-color .5s ease-in-out, box-shadow .5s ease-in-out;
}

.screen{
    width: 233px;
    height: 91px;
    background-color: #EBECF1;
    box-shadow: inset 1.5px 1.5px 3px #CBCBCB, inset -1.5px -1.5px 3px #FFFFFF;
    border-radius: 24px 24px 10px 10px;
    margin: 20px 20px 20px 20px;
    transition: background-color .5s ease-in-out, box-shadow .5s ease-in-out;
}

.screenContent{
    text-align: end;
    padding: 17px;
    font-size: 30px;
}

#result{
    font-size: 30px;
    line-height: 36px;
    margin-bottom: 5px;
    overflow: auto;
    user-select: all;
}

#resultText{
    transition: color .5s ease-in-out;
    cursor: copy
}

.resultTextNM{
   color: #F7B731 !important;
}


.tooltip {
    position: fixed;
    height: fit-content;
    width: fit-content;
    background-color: white;
    padding: 5px 12px;
    border-radius: 5px;
    font-family: Nova Round;
    display: none;
    font-size: 20px;
    font: icon;
    box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.15);
}

.calculation{
    font-size: 12px;
    line-height: 14px;
    color: rgb(153, 153, 153);
    overflow: auto;
    transition: color .5s ease-in-out;
}

.calculationNM{
    color: white;
}

.numPad{
    width: 233px;
    height: 296px;
    margin: 20px 20px 20px 20px;

    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    grid-column-gap: 19px;
    grid-row-gap: 19px;

    
}

.style{
    box-shadow: 4.5px 4.5px 9px #CBCBCB,
                -4.5px -4.5px 9px #FFFFFF;
    border-radius: 500px; 
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color .5s ease-in-out, box-shadow .5s ease-in-out, color .5s ease-in-out;
}

.styleOnClick{
    box-shadow: inset 2px 2px 4px #CBCBCB,
                inset -2px -2px 4px #FFFFFF;
    font-size: 20px;
    opacity: 0.8;
}

.circle{
    width: 44px;
    height: 44px;            
}



.numColor{
    color: #373737;
}



.trashCan{
    width: 15px;
    height: 15px;
}


/* Night Mode */
.styleNM{
    background: #191A1E;
    box-shadow: 6px 6px 12px #0E0E0E, -4px -4px 10px rgba(95, 94, 94, 0.25);
    color: white;
}

.screenNM{
    background-color: #191A1E;
    background: #191A1E;
    box-shadow: inset 1.5px 1.5px 3px #0E0E0E, inset -1.5px -1.5px 3px #5F5E5E;
}

/* Night Mode */

.ariOpeColor{
    color: #2D98DA;
}

.zero{
    width: 107px;
    height: 44px;
    color: #F7B731;
    grid-area: 5 / 1 / 6 / 3;
}

.equal{
    width: 44px;
    height: 170px;
    color: #20BF6B;
    grid-area: 3 / 4 / 6 / 5;
}
              
            
!

JS

              
                // Switch to full page view so the Dark Mode toggle will be in the frame ^_^

// Fork it on Github: https://github.com/theHocineSaad/Neumorphism-JavaScript-Calculator-with-Dark-Mode

for (var item of document.querySelectorAll(".style")) {
    item.addEventListener("mousedown", function (evt) {
        evt.target.classList.add("styleOnClick");
    }, false);
}


document.getElementById('clear').addEventListener("mousedown", function () {
    document.querySelector(".style").classList.add("styleOnClick");
    document.getElementsByTagName('svg')[0].setAttribute("width", "13px");
    document.getElementsByTagName('svg')[0].setAttribute("height", "13px");
});

document.addEventListener("mouseup", function (){

 for (var item of document.querySelectorAll(".style")) {
     item.classList.remove("styleOnClick");
}
    document.getElementsByTagName('svg')[0].classList.remove('styleOnClick');
    document.querySelector(".style").classList.remove("styleOnClick");
    document.getElementsByTagName('svg')[0].setAttribute("width", "15px");
    document.getElementsByTagName('svg')[0].setAttribute("height", "15px");
});

const toolTip = document.querySelector('.tooltip');
window.addEventListener('mousemove', toolTipXY);
function toolTipXY(e) {
    let x = e.clientX,
        y = e.clientY;
    toolTip.style.top = (y + 20) + 'px';
    toolTip.style.left = (x + 20) + 'px';
};

document.getElementById('resultText').addEventListener('mouseenter', function(){
    toolTip.setAttribute('style', 'display: block')
})

document.getElementById('resultText').addEventListener('mouseleave', function(){
    toolTip.removeAttribute('style', 'display: block')
})

const result = document.getElementById('resultText');
const calculation = document.getElementById('calculationText');

function formula(){
    var calMath = '';
    calculation.textContent.split('').map(element => {
    if(element === 'x'){
        calMath += '*';
    }else{
        calMath += element;
    }
    });
    return calMath;
}


function calc(formula){
    if (['+', '-', "x", '/'].includes(formula[formula.length -1])){
        formula = formula.slice(0, formula.length - 1);
    }

    return eval(formula);
    
    
}

function wrightNum(num){
    calculation.textContent += num;
}

function op(btn){
    if(calculation.textContent.length !== 0){
        if(!['+', '-', "x", '/'].includes(calculation.textContent[calculation.textContent.length -1])){
            result.textContent =  calc(formula());
            calculation.textContent += btn;
        }else{
            // result.textContent =  calc(formula());
            calculation.textContent = calculation.textContent.slice(0, formula.length - 1);
            calculation.textContent += btn;
        }
    }
}


document.getElementById('num0').addEventListener('click', function(){
    wrightNum(0)
});
document.getElementById('num1').addEventListener('click', function(){
    wrightNum(1)
});
document.getElementById('num2').addEventListener('click', function(){
    wrightNum(2)
});
document.getElementById('num3').addEventListener('click', function(){
    wrightNum(3)
});
document.getElementById('num4').addEventListener('click', function(){
    wrightNum(4)
});
document.getElementById('num5').addEventListener('click', function(){
    wrightNum(5)
});
document.getElementById('num6').addEventListener('click', function(){
    wrightNum(6)
});
document.getElementById('num7').addEventListener('click', function(){
    wrightNum(7)
}); 
document.getElementById('num8').addEventListener('click', function(){
    wrightNum(8)
}); 
document.getElementById('num9').addEventListener('click', function(){
    wrightNum(9)
});


document.getElementById('addition').addEventListener('click', function(){
    op('+')
}); 
document.getElementById('subtraction').addEventListener('click', function(){
    op('-')
}); 
document.getElementById('division').addEventListener('click', function(){
    op('/')
}); 
document.getElementById('multiplication').addEventListener('click', function(){
    op('x')
}); 


document.getElementById('clear').addEventListener('click', function(){
    calculation.textContent = '';
    result.textContent = 0;
});  

document.getElementById('dot').addEventListener('click', function(){
    op('.')
}); 

document.getElementById('equal').addEventListener('click', function(){
    result.textContent =  (calc(formula()).length !== 0) ? calc(formula()) : result.textContent;
    calculation.textContent = result.textContent;
}); 

const tooltip = document.getElementsByClassName('tooltip')[0];
function restoreText(){
    tooltip.textContent = 'Click To Copy ❤';
}

function copy() {
    document.execCommand("copy");
    tooltip.textContent = 'Copied!'
  }

document.getElementsByClassName('nightModeToggle')[0].addEventListener('click', function(){
    document.getElementsByClassName('switch')[0].classList.toggle("switchNM");
    document.getElementsByClassName('nightModeToggle')[0].classList.toggle("nightModeToggleNM");
    document.getElementsByClassName('calculator')[0].classList.toggle("styleNM");
    document.getElementsByClassName('screen')[0].classList.toggle("screenNM");
    document.querySelectorAll('.style').forEach(function(button) {
        button.classList.toggle("styleNM");
     });
    result.classList.toggle('resultTextNM');
    calculation.classList.toggle('calculationNM');
})

              
            
!
999px

Console