Hey friends, today let's see how to make custom cool alert notifications like in the photo above. Do check my YouTube video for the tutorial.



In this project, I cover 4 types of alert notifications. These are danger (red), success (green), warning (yellow), info (blue). Here's the project source code below:

Paste this CODE in a index.html file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!-- Created by CodingPorium,2021. Visit https://youtube.com/c/CodingPorium for more tutorials with free source code -->
<!DOCTYPE html>
<html>
<head>
<title>Custom Alert Notifications using HTML,CSS & JS | CodingPorium</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
   @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');
.alert {
  font-family:poppins;
  padding: 20px;
  color: white;
  border-radius:10px;
  opacity: 1;
  transition: opacity 0.6s;
  margin-bottom: 15px;
}
.alert.danger{ background-color: #f44336;}
.alert.success {background-color: #04AA6D;}
.alert.info {background-color: #2196F3;}
.alert.warning {background-color: #ff9800;}

.closebtn {
  margin-left: 15px;
  color: white;
  font-weight: bold;
  float: right;
  font-size: 22px;
  line-height: 20px;
  cursor: pointer;
  transition: 0.3s;
}

.closebtn:hover {
  color: black;
}
</style>
</head>
<body>
<div  style="font-family:poppins;text-align:center;">
<h2>Alert Messages</h2>
<p>Made by CodingPorium using HTML,CSS & Javascript</p>
</div>
<div class="alert danger">
  <span class="closebtn">&times;</span>  
  <strong>ALERT!</strong> Your account is lorem ipsum dolor..
</div>

<div class="alert success">
  <span class="closebtn">&times;</span>  
  <strong>SUCCESS!</strong> We have received your lorem ipsum dolor..
</div>

<div class="alert warning">
  <span class="closebtn">&times;</span>  
  <strong>WARNING!</strong> Once you click submit, your lorem ipsum dolor..
</div>

<div class="alert info">
  <span class="closebtn">&times;</span>  
  <strong>NOTE!</strong> We will be moving to a new lorem ipsum dolor..
</div>

<script>
var close = document.getElementsByClassName("closebtn");
var i;

for (i = 0; i < close.length; i++) {
  close[i].onclick = function(){
    var div = this.parentElement;
    div.style.opacity = "0";
    setTimeout(function(){ div.style.display = "none"; }, 600);
  }
}
</script>

</body>
</html>
 

That's all for this project friends. I hope you enjoyed this post and do subscribe to our YT channel for more posts like this. Till the next one, goodbye!

Post a Comment

Previous Post Next Post