Contextual feedback messages for typical user actions.

alert( string $text [, string $color = 'default', array $options = [] ] ) : string


$text string Required Alert text.

$color string Optional Alert color. Possible value: default|success|warning|error|info

$options array Optional Additional options.

Available options

Name Type Default Description
id string '' Alert ID.
class string '' Alert class.
attributes array [] Array of custom attributes.
dismiss bool false Make alert dismissable.

Basic Usage

echo alert('Default');

HTML Output

<div class="alert alert-primary" role="alert">Default</div>


echo alert('Default');

echo alert('Success', 'success');

echo alert('Warning', 'warning');

echo alert('Error', 'error');

echo alert('Info', 'info');

HTML Output

<div class="alert alert-primary" role="alert">Default</div>
<div class="alert alert-success" role="alert">Success</div>
<div class="alert alert-warning" role="alert">Warning</div>
<div class="alert alert-danger" role="alert">Error</div>
<div class="alert alert-info" role="alert">Info</div>


By setting dismiss to true user can hide the alert.

echo alert('Dismissible', 'default', [
    'dismiss' => true,

HTML Output

<div class="alert alert-primary alert-dismissible" role="alert">
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>