Snippets Modal

Bootstrap 5 Error Modal for Failed Upload

An upload card whose failed attempt opens a centred error modal with a clear message and try-again or cancel actions.

Bootstrap 5 No jQuery Nov 2019 2.1K views

<section class="wdw-stage position-relative overflow-hidden">
  <div class="container" style="max-width: 760px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow">File upload</span>
      <h1 class="wdw-heading display-5 mt-1 mb-0">Upload your files</h1>
    </div>
    <div class="wdw-card p-4 p-md-5">
      <div class="em-drop border border-2 text-center rounded-4 p-4 p-md-5 mb-4">
        <span class="wdw-icon mb-2">
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 16V4M7 9l5-5 5 5M4 16v3a1 1 0 001 1h14a1 1 0 001-1v-3"/></svg>
        </span>
        <div class="fw-semibold fs-5">Drag and drop to upload</div>
        <div class="small wdw-muted">PDF, PNG or JPG up to 10 MB</div>
      </div>
      <div class="d-flex align-items-center gap-3 p-3 rounded-3 bg-body-tertiary mb-4">
        <span class="wdw-icon rounded-3" style="width:2.5rem;height:2.5rem">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H7a2 2 0 00-2 2v14a2 2 0 002 2h10a2 2 0 002-2V8zM14 3v5h5"/></svg>
        </span>
        <div class="me-auto flex-grow-1" style="min-width:0">
          <div class="fw-semibold small text-truncate">brand-guidelines-v3.pdf</div>
          <div class="small wdw-muted" id="emMeta">4.2 MB</div>
          <div class="progress mt-2 d-none" id="emProgress" style="height:6px" role="progressbar" aria-label="Upload progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar" id="emBar" style="width:0"></div></div>
        </div>
        <span class="d-flex align-items-center gap-2" id="emStatus">
          <span class="badge bg-danger-subtle text-danger border border-danger-subtle rounded-pill">Failed</span>
          <button type="button" class="btn btn-link btn-sm p-0 px-1" data-em-retry>Retry</button>
        </span>
      </div>
      <button type="button" class="btn btn-primary rounded-pill w-100" id="emUpload" data-em-retry>Upload file</button>
    </div>
  </div>

  <div class="em-scrim d-flex align-items-center justify-content-center p-3" id="emInline">
    <div class="em-modal-content bg-body text-center p-4 p-md-5 position-relative" role="alert">
      <span class="em-badge bg-danger-subtle text-danger mx-auto mb-4"><svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></span>
        <h2 class="h3 fw-bold" >Upload failed</h2>
        <p class="wdw-muted mb-4">Something went wrong and brand-guidelines-v3.pdf was not uploaded. Check your connection and try again.</p>
        <div class="d-flex flex-column flex-sm-row gap-2 justify-content-center">
          <button type="button" class="btn btn-primary rounded-pill px-4" data-em-retry>Try again</button>
          <button type="button" class="btn btn-outline-secondary rounded-pill px-4" data-em-cancel>Cancel</button>
        </div>
    </div>
  </div>

  <div class="modal fade em-modal" id="errorModal" tabindex="-1" aria-labelledby="errorModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" style="max-width: 440px">
      <div class="modal-content border-0 text-center p-4 p-md-5">
        <button type="button" class="btn-close position-absolute top-0 end-0 m-3" data-bs-dismiss="modal" aria-label="Close"></button>
        <span class="em-badge bg-danger-subtle text-danger mx-auto mb-4"><svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></span>
        <h2 class="h3 fw-bold" id="errorModalLabel">Upload failed</h2>
        <p class="wdw-muted mb-4">Something went wrong and brand-guidelines-v3.pdf was not uploaded. Check your connection and try again.</p>
        <div class="d-flex flex-column flex-sm-row gap-2 justify-content-center">
          <button type="button" class="btn btn-primary rounded-pill px-4" data-em-retry data-bs-dismiss="modal">Try again</button>
          <button type="button" class="btn btn-outline-secondary rounded-pill px-4" data-em-cancel data-bs-dismiss="modal">Cancel</button>
        </div>
      </div>
    </div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.