Popup Notification using HTML, CSS & JavaScript

Popup Notification using HTML, CSS & JavaScript

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

A Popup Notification box, sometimes also called a message box. A popup notification is a message that appears on the user's browser or the desktop. These notifications are designed to grab your audience's attention and engage them in some way.

In this blog (Popup Notification) on the webpage, there are four buttons at the center of the webpage. When you click on the button, the notification will pop up from the top of the webpage. Those four buttons were Info, Warning, Error, and Success buttons. These buttons will pop up with their respective information, which gives the notification to the users. There is a cross button to close the notification. During the popup, the notification will hide the buttons. While moving the mouse over the buttons, the buttons will fade out and this is made by using the CSS hover effect.

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

Popup 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> <head> <title>Popup Notification</title> <link rel="stylesheet" type="text/css" href="style.css"> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css'><link rel="stylesheet" href="style.css"> </head> <body> <div class="wrapper"> <div class="btn_grp"> <div class="btn btn_info">Info</div> <div class="btn btn_warning">Warning</div> <div class="btn btn_error">Error</div> <div class="btn btn_success">Success</div> </div> </div> <div class="alert_wrapper"> <div class="alert_backdrop"></div> <div class="alert_inner"> <div class="alert_item alert_info"> <div class="icon data_icon"> <i class="fas fa-info-circle"></i> </div> <div class="data"> <span>Information:</span> <p class="sub">Lorem ipsum dolor sit amet.</p> </div> <div class="icon close"> <i class="fas fa-times"></i> </div> </div> <div class="alert_item alert_warning"> <div class="icon data_icon"> <i class="fas fa-exclamation-triangle"></i> </div> <div class="data"> <span>Warning:</span> <p class="sub">Lorem ipsum dolor sit amet.</p> </div> <div class="icon close"> <i class="fas fa-times"></i> </div> </div> <div class="alert_item alert_error"> <div class="icon data_icon"> <i class="fas fa-bomb"></i> </div> <div class="data"> <span>Error:</span> <p class="sub">Lorem ipsum dolor sit amet.</p> </div> <div class="icon close"> <i class="fas fa-times"></i> </div> </div> <div class="alert_item alert_success"> <div class="icon data_icon"> <i class="fas fa-check-circle"></i> </div> <div class="data"> <span>Success:</span> <p class="sub">Lorem ipsum dolor sit amet.</p> </div> <div class="icon close"> <i class="fas fa-times"></i> </div> </div> </div> </div> <div class="credit">Made with <span style="color:#f8f3d6">❤</span> by <a href="https://www.learningrobo.com/">Learning Robo</a></div> <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=Open+Sans|Roboto:400,700&display=swap");

*{
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

body{
	background: #2d333f;
}

.wrapper{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
}

.btn_grp{
	display: flex;
}

.btn_grp .btn{
	width: 225px;
	height: 50px;
	line-height: 50px;
	text-align: center;
	background: #fff;
	margin: 0 10px;
	border-radius: 3px;
	cursor: pointer;
	text-transform: uppercase;
	letter-spacing: 2px;
	font-size: 14px;
}

.btn_grp .btn.btn_info,
.alert_item.alert_info{
	/*background: #cde8f5;*/
	background-color: #4480ae;
	color: #fff;
}

.btn_grp .btn.btn_warning,
.alert_item.alert_warning{
	/*background: #f8f3d6;*/
	background-color: #967132;
	color: #fff;
}

.btn_grp .btn.btn_error,
.alert_item.alert_error{
	/*background: #ecc8c5;*/
	background-color: #b32f2d;
	color: #fff;
}

.btn_grp .btn.btn_success,
.alert_item.alert_success{
	/*background: #def2d6;*/
	background-color: #5a7052;
	color: #fff;
}

.btn_grp .btn.btn_info:hover{
	/*background: #a5c7d8;*/
	background: #cde8f5;
	color: #000;
}

.btn_grp .btn.btn_warning:hover{
	/*background: #dcd4a2;*/
	background: #f8f3d6;
	color: #000;
}

.btn_grp .btn.btn_error:hover{
	/*background: #c79995;*/
	background: #ecc8c5;
	color: #000;
}

.btn_grp .btn.btn_success:hover{
	/*background: #adc5a5;*/
	background: #def2d6;
	color: #000;
}

.alert_wrapper{
	position: relative;
	width: 100%;
	height: 100%;
	z-index: 999;
	visibility: hidden;
}

.alert_backdrop{
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: #2d333f;
	opacity: 0.9;
	z-index: 2;
}

.alert_wrapper .alert_item{
	z-index: 3;	
	position: fixed;
	top: -100%;
	left: 50%;
	transform: translate(-50%,-50%);
	display: flex;
	align-items: center;
	padding: 25px 50px;
	border-radius: 3px;
	transition: all 0.2s ease;
}

.alert_wrapper .alert_item .data{
	margin: 0 50px;
}

.alert_wrapper .alert_item .data span{
	font-weight: 900;
	letter-spacing: 1px;
}
.alert_wrapper .alert_item .data .sub{
	padding-top: 5px;
	font-size: 14px;
	font-weight: 100;
}
.alert_wrapper .alert_item .icon{
	font-size: 32px;
}
.alert_wrapper .alert_item .close{
	cursor: pointer;
}

.alert_item.alert_info .close:hover{
	color: #a5c7d8;
}

.alert_item.alert_warning .close:hover{
	color: #dcd4a2;
}

.alert_item.alert_error .close:hover{
	color: #c79995;
}

.alert_item.alert_success .close:hover{
	color: #adc5a5;
}

.alert_wrapper.active{
	visibility: visible;
}
.alert_wrapper.active .alert_item{
	top: 50%;
}
.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.


var alert_items = document.querySelectorAll(".alert_item");
	var btns = document.querySelectorAll(".btn");
	var alert_wrapper = document.querySelector(".alert_wrapper");
	var close_btns = document.querySelectorAll(".close");

	btns.forEach(function(btn, btn_index){
		btn.addEventListener("click", function(){
			alert_wrapper.classList.add("active");

			alert_items.forEach(function(alert_item, alert_index){
				if(btn_index == alert_index){
					alert_item.style.top = "50%";
				}
				else{
					alert_item.style.top = "-100%";
				}
			})
		})
	})

	close_btns.forEach(function(close, close_index){
		close.addEventListener("click", function(){
			alert_wrapper.classList.remove("active");

			alert_items.forEach(function(alert_item, alert_index){
				alert_item.style.top = "-100%";
			})
		})
	})
We hope you will like this Popup Notification using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem creating this Popup 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