To create the X that closes the alert, add a <span> element with classw3-buttonand anonclickevent: Example <spanonclick="this.parentElement.style.display='none'" class="w3-button w3-display-topright">×</span> Try It Yourself » ...