Popup Warning Notification using HTML, CSS & JavaScript

Popup Warning Notification using HTML, CSS & JavaScript

Hello developers, today in this blog, you'll learn to create a Popup Warning Notification using HTML, CSS & JavaScript.

A Warning Notification box, sometimes also called a message box. It is a small window that pops up on your screen to warn you that your system is about to perform some operation with potentially damaging consequences.

In this blog (Popup Warning Notification) on the webpage, there is a button at the center of the webpage. When you hover the button the background color of the button changes, this hover effect is made by using the CSS hover effect. When you click on the button, the warning notification will pop at the right top corner of the webpage. This notification hides automatically after a few seconds and there is also a cross sign button to hide that notification.

The source code of this Popup Warning Notification is given below, if you want the source code of this program, you can copy it. You can use this Popup Warning Notification with your creativity and take this project to the next level.

Popup Warning Notification [Source Code]

To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>Popup Warning Notification || Learningrobo</title> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css'><link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <button>Show Alert</button> <div class="alert hide"> <span class="fas fa-exclamation-triangle"></span> <span class="msg">Warning: This is a warning alert!</span> <div class="close-btn"> <span class="fas fa-times"></span> </div> </div> <div class="credit">Made with <span style="color:#f8f3d6">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> </div> <script src='https://code.jquery.com/jquery-3.4.1.js'></script> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive, create a CSS file with the name style.css, and remember that you have to make a file with a .css extension.


@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');
*{
  margin: 0;
  padding: 0;
  user-select: none;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}
html,body{
  height: 100%;
  background-color: #2d333f;
}
body{
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}
button{
  padding: 8px 16px;
  font-size: 25px;
  font-weight: 500;
  border-radius: 4px;
  border: none;
  outline: none;
  background: #f8f3d6;
  color: #967132;
  letter-spacing: 1px;
  cursor: pointer;
}
button:hover{
  background: #dcd4a2;
}
.alert{
  background: #f8f3d6;
  color: #967132;
  padding: 25px 50px;
  min-width: 420px;
  position: absolute;
  right: 0;
  top: 10px;
  border-radius: 5px;
  border-left: 8px solid #967132;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
.alert.showAlert{
  opacity: 1;
  pointer-events: auto;
}
.alert.show{
  animation: show_slide 1s ease forwards;
}
@keyframes show_slide {
  0%{
    transform: translateX(100%);
  }
  40%{
    transform: translateX(-10%);
  }
  80%{
    transform: translateX(0%);
  }
  100%{
    transform: translateX(-10px);
  }
}
.alert.hide{
  animation: hide_slide 1s ease forwards;
}
@keyframes hide_slide {
  0%{
    transform: translateX(-10px);
  }
  40%{
    transform: translateX(0%);
  }
  80%{
    transform: translateX(-10%);
  }
  100%{
    transform: translateX(100%);
  }
}
.alert .fa-exclamation-triangle{
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: #967132;
  font-size: 30px;
}
.alert .msg{
  padding: 0 20px;
  font-size: 18px;
  color: #967132;
}
.alert .close-btn{
  position: absolute;
  right: 0px;
  top: 50%;
  transform: translateY(-50%);
  background: #967132;
  padding: 20px 18px;
  cursor: pointer;
}
.alert .close-btn:hover{
  background: #dcd4a2;
}
.alert .close-btn .fas{
  color: #dcd4a2;
  font-size: 22px;
  line-height: 40px;
}
.credit{
    text-align: center;
    color: #fff;
    margin-top: 30px;
    font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.credit a{
    text-decoration: none;
    color: #f8f3d6;
    font-weight: bold;
} 
JavaScript makes the page work functionally. At last, create a JavaScript file with the name of script.js, and remember that you've got to make a file with a .js extension.


$('button').click(function(){
  $('.alert').addClass("show");
  $('.alert').removeClass("hide");
  $('.alert').addClass("showAlert");
  setTimeout(function(){
    $('.alert').removeClass("show");
    $('.alert').addClass("hide");
  },5000);
});
$('.close-btn').click(function(){
  $('.alert').removeClass("show");
  $('.alert').addClass("hide");
});
We hope you will like this Popup Warning Notification using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem creating this Popup Warning Notification using HTML, CSS & JavaScript, then contact us or comment us. We'll try to provide a solution to your problem as soon as possible.

Thank you
Learning robo team

Post a Comment

Thank you
Learning robo team

Post a Comment (0)

Previous Post Next Post
Learning Robo says...
code copied
Welcome