Bootstrap modals made easy.

Bootbox.js is a small JavaScript library which allows you to create programmatic dialog boxes using Bootstrap modals, without having to worry about creating, managing or removing any of the required DOM elements or JS event handlers. Here’s the simplest possible example:

Run example

Compare that to the code you’d have to write without Bootbox:

Bootbox is proudly sponsored by Finch. Test local websites across multiple devices, share them with your team and get feedback from clients through a secure, public URL.

The library exposes three methods designed to mimic their native JavaScript equivalents. Their exact method signatures are flexible as each can take various parameters to customise labels and specify defaults, but they are most commonly called like so:

The only required argument for alert calls is message; callback is required for confirm and prompt calls in order to determine what the user’s response was. Even when calling alert a callback is useful to determine when the user dismissed the dialog since our wrapper methods can’t & don’t block like their native counterparts: they are asynchronous rather than synchronous.

Each of these three methods calls a fourth public method which you too can use to create your own custom dialogs:

More API documentation »

Documentation for older versions of Bootbox is also available: v3.x, v2.x.

Please note: the ‘Example’ object used in the following examples simply displays a notification to help illustrate when each callback is invoked. It is nothing to do with Bootbox itself, but you may view its source if you’re interested in how it works.




Prompt with default value

Custom Dialog

More examples »

The latest stable version of Bootbox is 4.4.0. You can download the minified library bootbox.min.js for use in production, or the uncompressed bootbox.js for use in development. I wouldn’t recommend hotlinking to either file as Github does not serve the correct mime type which may cause security warnings to be triggered based on your browser’s settings.

If you wish you may also see a full list of releases or download the latest copy of the entire repository (including build files and tests) in zip or tarball format. Realistically the only reason you should be using anything other than the 4.x.x series is if you are restricted by the version of Bootstrap you’re using—see the following section for full details.

Install via npm

Bootbox is also available as an npm package and can be installed in the usual way:

npm install bootbox

All versions of Bootbox stand on the shoulders of two great giants: Bootstrap and jQuery. The exact version of Bootstrap depends on the version of Bootbox you’re using. This has become slightly more complex than I’d like but hopefully this handy table will clear things up (if it doesn’t then please tell me!):

Bootbox version Min. Bootstrap version Max. Bootstrap Min. jQuery
4.x.x Latest 3.0.0 3.0.0 1.9.1
3.x.x 2.2.2 2.3.2 1.8.3
2.x.x 2.0.0 2.0.4 1.7.1
1.x.x 1.3.0 1.4.0 1.7.1

Once you’ve got your dependencies sorted, usage is fairly straightforward and much like any other JavaScript library you’ve ever used. The library creates a single global instance of a bootbox object:

Bootbox was originally created in 2011 with the sole purpose of wrapping JavaScript’s low level dialog methods with Bootstrap’s high level modal functionality. As such it is a small library focussed on providing basic programmatic dialogs with minimal fuss and overhead.

Bootbox is authored and maintained by Nick Payne (@makeusabrew). Thanks are also due to the contributors!

When you’re up and running check out some examples or the documentation.

Bootbox is a free, open source project. As such you can help out in a number of ways from simply raising an issue to forking the project and submitting a pull request.

I’m particularly keen to improve the examples and make a proper start on the API docs, so pull requests contributing towards the gh-pages branch (which you’re looking at!) are extremely welcome.

Lastly—please just help spread the word!

© 2011-2015 Nick Payne. Proudly sponsored by—Share your local websites.