W3.CSS Alerts

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

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> 

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> 

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> 

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> 

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> 

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>

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">

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">