Skip to content
doubtly

1 answer

Best answer

Answer: Create an alert with a div that has the class alert plus a colour class such as alert-success, alert-danger or alert-warning.

<div class="alert alert-success" role="alert">
  Your form was submitted successfully!
</div>

<div class="alert alert-warning alert-dismissible fade show" role="alert">
  <strong>Warning!</strong> Please check your input.
  <button type="button" class="btn-close" data-bs-dismiss="alert"
          aria-label="Close"></button>
</div>
  • .alert gives the box its padding and border; the contextual class sets the colour: alert-primary, alert-secondary, alert-success, alert-danger, alert-warning, alert-info, alert-light, alert-dark.
  • role="alert" helps screen readers.
  • To let the user close it, add alert-dismissible fade show and a close button. The example uses Bootstrap 5 (btn-close, data-bs-dismiss). In Bootstrap 4 the button is <button type="button" class="close" data-dismiss="alert">&times;</button>. Dismissing needs Bootstrap's JavaScript to be included.
  • Use .alert-link on links inside an alert to match its colour.
Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.