Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

W3.CSS Alerts


The w3-panel class is the perfect class to display all types of alerts:

×

Danger!

Red often indicates a dangerous or negative situation.

Alerts are often displayed using a strong color:

×

Danger!

Red often indicates a dangerous or negative situation.

Example

<div class="w3-panel w3-red">
  <h3>Danger!</h3>
  <p>Red often indicates a dangerous or negative situation.</p>
</div> 
Try It Yourself »

Display Warnings

×

Warning!

Yellow often indicates a warning that might need attention.

×

Warning!

Yellow often indicates a warning that might need attention.

Example

<div class="w3-panel w3-yellow">
  <h3>Warning!</h3>
  <p>Yellow often indicates a warning that might need attention.</p>
</div> 
Try It Yourself »

Display Successs

×

Success!

Green often indicates something successful or positive.

×

Success!

Green often indicates something successful or positive.

Example

<div class="w3-panel w3-green">
  <h3>Success!</h3>
  <p>Green often indicates something successful or positive.</p>
</div> 
Try It Yourself »

Display Information

×

Info!

Blue often indicates a neutral informative change or action.

×

Info!

Blue often indicates a neutral informative change or action.

Example

<div class="w3-panel w3-blue">
  <h3>Information!</h3>
  <p>Blue often indicates a neutral informative change or action.</p>
</div> 
Try It Yourself »

Using a Container

The w3-container class can also be used to display alerts:

Example

<div class="w3-container w3-red">
  <h3>Danger!</h3>
  <p>Red often indicates a dangerous or negative situation.</p>
</div> 
Try It Yourself »


Alerts in All Colors

Alerts are often displayed in special colors, but any color can be used:

Danger!

Red often indicates a dangerous or negative situation.

Danger!

Red often indicates a dangerous or negative situation.

Danger!

Red often indicates a dangerous or negative situation.

Danger!

Red often indicates a dangerous or negative situation.

Danger!

Red often indicates a dangerous or negative situation.

Example

<div class="w3-panel w3-blue-grey">
  <h3>Danger!</h3>
  <p>Red often indicates a dangerous or negative situation.</p>
</div> 
Try It Yourself »

Closing Alerts

To close the alert box, click on the X in the upper right corner:

×

Danger!

Red often indicates a dangerous or negative situation.

To create the X that closes the alert, add a <span> element with class w3-button and an onclick event:

Example

<span onclick="this.parentElement.style.display='none'"
class="w3-button w3-display-topright">&times;</span>
Try It Yourself »

Tip: The HTML &times; entity is the preferred icon for close buttons (rather than the letter "X").


Rounded Alerts

Use the w3-round classes if you want rounded corners:

Success!

Here w3-round is used.

Success!

Here w3-round-large is used.

Success!

Here w3-round-xxlarge is used.

Example

<div class="w3-panel w3-green w3-round">
Try It Yourself »

Alert as a Card

Use a w3-card class if you want the alert to be displayed as a card:

Warning!

Yellow often indicates something that needs attention.

Example

<div class="w3-panel w3-yellow w3-card-4">
Try It Yourself »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.