Benny Sutton is 4 hire - just click here

Snackbars with CSS and JavaScript

Pure CSS Snackbars

Snackbars are often used as a tooltips/popups to show a message at the bottom of the screen.

Click on the button to show the snackbar. It will disappear after 3 seconds.

See the working demo below.

Demo: How to create Pure CSS Snackbars

JavaScript

Pretty much the standard JavaScript you'll paste into your page script block - or in a .js file if you prefer.

         
        function myFunction() {
          var x = document.getElementById("snackbar");
          x.className = "show";
          setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
        }
        
    

CSS

Edit as necessary.

          
        body{
              font-size: 2em;
            }

            #snackbar {
              visibility: hidden;
              min-width: 250px;
              margin-left: -125px;
              background-color: #333;
              color: #fff;
              text-align: center;
              border-radius: 2px;
              padding: 16px;
              position: fixed;
              z-index: 1;
              left: 50%;
              bottom: 30px;
              font-size: 17px;
            }

            #snackbar.show {
              visibility: visible;
              -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
              animation: fadein 0.5s, fadeout 0.5s 2.5s;
            }

            @-webkit-keyframes fadein {
              from {bottom: 0; opacity: 0;} 
              to {bottom: 30px; opacity: 1;}
            }

            @keyframes fadein {
              from {bottom: 0; opacity: 0;}
              to {bottom: 30px; opacity: 1;}
            }

            @-webkit-keyframes fadeout {
              from {bottom: 30px; opacity: 1;} 
              to {bottom: 0; opacity: 0;}
            }

            @keyframes fadeout {
              from {bottom: 30px; opacity: 1;}
              to {bottom: 0; opacity: 0;}
            }
        
    

Conclusion

A few lines of code is all you need to snackbars with css and javascript