How to create alert messages with CSS?

To create alert messages with CSS, the code is as follows −


 Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   .alertMessage {
      padding: 20px;
      background-color: #f44336;
      color: white;
      font-size: 20px;
      margin-left: 15px;
      color: white;
      font-weight: bold;
      float: right;
      font-size: 22px;
      line-height: 20px;
      cursor: pointer;
      transition: 0.3s;
   .close:hover {
      color: black;
<h1>Alert Message Example</h1>
<div class="alertMessage">
<span class="close" onclick="'none';">×</span>
<strong>This cannot be revered!</strong> You account will be deleted.


The above code will produce the following output −