Bootstrap.Native Components

5.1.10 · active · verified Sun Apr 19

bootstrap.native is a robust JavaScript library providing native, dependency-free implementations of Bootstrap 5 components. It serves as a lightweight and performant alternative to Bootstrap's official JavaScript, deliberately omitting external dependencies like jQuery and Popper.js. The current stable version is 5.1.10. The project maintains an active release cadence, with frequent updates addressing bugs, performance enhancements, and compatibility with the latest Bootstrap 5.x releases. Its key differentiators include a minimal footprint (approximately 13Kb gZipped), a codebase entirely sourced with TypeScript, and an emphasis on modern browser APIs such as `PositionObserver` and `ResizeObserver` for superior performance. The library supports integration via npm, bun, pnpm, and deno, providing broad compatibility across different development environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and programmatically control a Bootstrap Modal component using `bootstrap.native` after the DOM is fully loaded.

import { Modal } from 'bootstrap.native';

document.addEventListener('DOMContentLoaded', () => {
  const modalElement = document.getElementById('myModal');
  if (modalElement) {
    const myModal = new Modal(modalElement, { keyboard: true, backdrop: true });

    // Example: Show the modal after a short delay
    setTimeout(() => {
      myModal.show();
      console.log('Modal shown!');
    }, 1000);

    // Example: Add an event listener for when the modal is hidden
    modalElement.addEventListener('hidden.bs.modal', () => {
      console.log('Modal hidden!');
    });
  } else {
    console.error('Modal element with ID "myModal" not found.');
  }
});

// Basic HTML structure for the modal (add this to your index.html)
/*
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="myModalLabel">Hello from Bootstrap.Native</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        This is a modal powered by bootstrap.native, without jQuery or Popper.js!
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
*/

view raw JSON →