Tutorials References Menu

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 »