AnimationsButtonsTutorials

Animated Toggle Buttons Pure CSS

Animated Toggle Buttons Pure CSS

Animated Toggle Buttons Pure CSS

Before We Start to Animated Toggle Buttons Pure CSS

Animated Toggle Buttons Pure CSS can be used to animate Forms, Buttons, etc. and create user attractive UI components.

So if you are a person who wishes to develop a website, you have to know how to create animations properly. Check out our tutorial and you can learn this techniques and use it on your web development. Below sections shows how to develop this animations.

How to create? We are here to solve your problem. In this article we discuss how to create a hover effect animations. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag as below.

<body>
<div class="container">
        <div class="toggle">
            <input type="checkbox">
            <span class="button"></span>
            <span class="label">+</span>
        </div>
        <div class="toggle">
            <input type="checkbox" checked>
            <span class="button"></span>
            <span class="label">–</span>
        </div>
    </div>
</body>

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag as below.

<style>
        html,
        body {
            text-align: center;
            background-color: #304000;
            height: 100vh;
        }

        .container {
            text-align: center;
            position: absolute;
            margin-top: -80px;
            width: 100%;
            top: 50%;
        }

        .toggle {
            margin: 4px;
            display: inline-block;
        }

        .toggle {
            box-shadow: inset 0 0 35px 5px rgba(0, 0, 0, 0.25), inset 0 2px 1px 1px rgba(255, 255, 255, 0.9), inset 0 -2px 1px 0 rgba(0, 0, 0, 0.25);
            border-radius: 8px;
            background: #ccd0d4;
            position: relative;
            height: 140px;
            width: 140px;
        }

        .toggle:before {
            box-shadow: 0 0 17.5px 8.75px #fff;
            border-radius: 118.3px;
            background: #fff;
            position: absolute;
            margin-left: -50.4px;
            margin-top: -50.4px;
            opacity: 0.2;
            content: "";
            height: 100.8px;
            width: 100.8px;
            left: 50%;
            top: 50%;
        }

        .toggle .button {
            -webkit-filter: blur(1px);
            -moz-filter: blur(1px);
            filter: blur(1px);
            transition: all 300ms cubic-bezier(0.23, 1, 0.32, 1);
            box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.5), inset 0 -3px 4px -1px rgba(0, 0, 0, 0.3), 0 -10px 15px -1px rgba(235, 224, 224, 0.6), inset 0 3px 4px -1px rgba(235, 224, 224, 0.3), inset 0 0 5px 1px rgba(235, 224, 224, 0.8), inset 0 20px 30px 0 rgba(255, 255, 255, 0.3);
            border-radius: 96.32px;
            position: absolute;
            background: #ccd0d4;
            margin-left: -48.16px;
            margin-top: -48.16px;
            display: block;
            height: 96.32px;
            width: 96.32px;
            left: 50%;
            top: 50%;
        }

        .toggle .label {
            transition: color 300ms ease-out;
            text-shadow: 1px 1px 3px #97b0cb, 0 0 0 rgba(0, 0, 0, 0.8), 1px 1px 4px #fff;
            line-height: 139px;
            text-align: center;
            position: absolute;
            font-weight: 700;
            font-size: 42px;
            display: block;
            opacity: 0.9;
            height: 100%;
            width: 100%;
            color: rgba(0, 0, 0, 0.4);
        }

        .toggle input {
            opacity: 0;
            position: absolute;
            cursor: pointer;
            z-index: 1;
            height: 100%;
            width: 100%;
            left: 0;
            top: 0;
        }

        .toggle input:active~.button {
            box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 30px 1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 25px 0 rgba(0, 0, 0, 0.4), inset 0 0 10px 1px rgba(255, 255, 255, 0.6);
        }

        .toggle input:active~.label {
            font-size: 40px;
            color: rgba(0, 0, 0, 0.45);
        }

        .toggle input:checked~.button {
            box-shadow: 0 15px 25px -4px rgba(0, 0, 0, 0.4), inset 0 -8px 25px -1px rgba(255, 255, 255, 0.9), 0 -10px 15px -1px rgba(255, 255, 255, 0.6), inset 0 8px 20px 0 rgba(0, 0, 0, 0.2), inset 0 0 5px 1px rgba(255, 255, 255, 0.6);
        }

        .toggle input:checked~.label {
            font-size: 40px;
            color: rgba(0, 0, 0, 0.4);
        }
    </style>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want. Enjoy it.

Out Put

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button