Skip to main content
Components
Alert
pnpm add @winkintel/bootstrap-svelte
GitHub

Alert

Bootstrap's alert component built with Svelte 5. Use alerts to provide contextual feedback messages for typical user actions.


Experiment with the Alert component by adjusting the props below:

Interactive Playground

Controls

Preview

Code

            
            <Alert
  isDismissible={true}>
  This is an alert
</Alert>
        

Event Log

  • No events logged
            
            <Alert colorVariant="primary">
  A simple primary alert—check it out!
</Alert>
        

Bootstrap includes several predefined alert styles for different contexts.

            
            <Alert colorVariant="primary">A simple primary alert—check it out!</Alert>
<Alert colorVariant="secondary">A simple secondary alert—check it out!</Alert>
<Alert colorVariant="success">A simple success alert—check it out!</Alert>
<Alert colorVariant="danger">A simple danger alert—check it out!</Alert>
<Alert colorVariant="warning">A simple warning alert—check it out!</Alert>
<Alert colorVariant="info">A simple info alert—check it out!</Alert>
<Alert colorVariant="light">A simple light alert—check it out!</Alert>
<Alert colorVariant="dark">A simple dark alert—check it out!</Alert>
        

Make alerts dismissible by adding the isDismissible prop. This adds a close button to the alert and allows it to be closed by users.

            
            <Alert colorVariant="warning" isDismissible={true}>
  <strong>Holy guacamole!</strong> You should check in on some of those fields below.
</Alert>
        

Alerts can contain additional HTML elements like headings, paragraphs and dividers.

            
            <Alert colorVariant="success">
  <h4 class="alert-heading">Well done!</h4>
  <p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
  <hr>
  <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</Alert>
        

Add icons to your alerts to enhance visual appearance. You can use any icon library like Bootstrap Icons.

            
            <Alert colorVariant="primary">
  <i class="bi bi-info-circle-fill me-2"></i>
  An example alert with an icon
</Alert>
        

Props

NameTypeDefaultDescription
colorVariantstring'primary'Sets the alert's background color. Values: 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'.
isDismissiblebooleanfalseAdds a close button that allows users to dismiss the alert.
isAnimatedbooleantrueEnables the fade animation when the alert is shown or hidden.
isOpenbooleantrueControls the visibility of the alert. Can be bound using bind:isOpen.
elementRefHTMLElement | nullnullReference to the DOM element

Events

NameTypeDescription
onCloseEventListenerFired when the alert is about to Close (at the start of the transition).
onClosedEventListenerFired when the alert has been fully Closed (after the transition is complete).

CSS Classes

The component applies Bootstrap's alert classes based on the provided props:

  • alert - Always applied as the base class
  • {variant} - Applied based on the variant prop
  • alert-dismissible - Applied when isDismissible is true
  • fade - Applied when isAnimated is true
  • show - Applied when isOpen is true and isAnimated is true