badge() html()

A coloured badge or label with escaped text.

html()->badge($text = '', $extra = [])

Options

OptionMeaning
typeprimary, secondary, success, danger, warning, info, light, dark.
pillRounded.
class_add, id, title, style, no_escape, data-*, attrAttributes; no_escape prints HTML.

Example

primary secondary success danger warning info light dark 12 <b>escaped</b> {braces}

Code

$out = '';
foreach (['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'] as $type) {
    $out .= html()->badge($type, ['type' => $type]) . ' ';
}
return $out . html()->badge('12', ['type' => 'danger', 'pill' => 1]) . ' ' . html()->badge('<b>escaped</b> {braces}', ['type' => 'info']);

Bootstrap 3 and 5

Bootstrap 5 badge text-bg-<type>, Bootstrap 4 badge badge-<type>, Bootstrap 3 label label-<type> (a pill keeps the colour, not the round corners).

See also: html/button, table/text