Top Related Projects
⭕ Tiny javascript library for creating accessible modal dialogs
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
No longer actively maintained.
✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦🇪🇺
Elegant, responsive, flexible and lightweight modal plugin with jQuery.
Quick Overview
Micromodal is a lightweight, accessible, and customizable modal library written in pure JavaScript. It allows developers to create modal dialogs that are keyboard-friendly and follow WAI-ARIA guidelines for accessibility. The library is designed to be easy to use and integrate into existing projects.
Pros
- Lightweight and dependency-free
- Fully accessible, following WAI-ARIA guidelines
- Customizable with CSS and JavaScript hooks
- Easy to integrate with existing projects
Cons
- Limited built-in styling options
- May require additional work for complex modal scenarios
- Documentation could be more comprehensive
Code Examples
Creating a basic modal:
<div id="modal-1" aria-hidden="true">
<div tabindex="-1" data-micromodal-close>
<div role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
<header>
<h2 id="modal-1-title">Modal Title</h2>
<button aria-label="Close modal" data-micromodal-close></button>
</header>
<div id="modal-1-content">
Modal content goes here
</div>
</div>
</div>
</div>
Initializing and showing a modal:
import MicroModal from 'micromodal';
// Initialize all modals
MicroModal.init();
// Show a specific modal
MicroModal.show('modal-1');
Customizing modal behavior:
MicroModal.init({
onShow: modal => console.log(`${modal.id} is shown`),
onClose: modal => console.log(`${modal.id} is hidden`),
openTrigger: 'data-custom-open',
closeTrigger: 'data-custom-close',
disableScroll: true,
disableFocus: false,
awaitOpenAnimation: false,
awaitCloseAnimation: false,
debugMode: true
});
Getting Started
-
Install Micromodal:
npm install micromodal --save
-
Import and initialize in your JavaScript file:
import MicroModal from 'micromodal'; MicroModal.init();
-
Create your modal HTML structure (see the first code example above).
-
Trigger the modal:
<button data-micromodal-trigger="modal-1">Open Modal</button>
-
Style your modal using CSS as needed.
Competitor Comparisons
⭕ Tiny javascript library for creating accessible modal dialogs
Pros of Micromodal
- Lightweight and minimal JavaScript library for creating accessible modal dialogs
- Easy to use with a simple API and customizable options
- Supports keyboard navigation and focus management for improved accessibility
Cons of Micromodal
- Limited built-in styling options, requiring more custom CSS
- May not be suitable for complex modal requirements without additional customization
- Lacks advanced features like nested modals or dynamic content loading
Code Comparison
Micromodal:
MicroModal.init();
MicroModal.show('modal-1');
MicroModal.close('modal-1');
As the comparison is between the same repository (Micromodal), there is no different code to compare. The usage and implementation would be identical for both cases.
Summary
Micromodal is a popular lightweight modal library that offers a simple API for creating accessible modal dialogs. Its main advantages include ease of use and accessibility features. However, it may require additional customization for more complex use cases or advanced styling. The library is well-suited for projects that need basic modal functionality with a focus on accessibility and minimal overhead.
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
Pros of Tingle
- More customizable with additional options for positioning and transitions
- Supports multiple instances and nested modals
- Includes built-in CSS styles for quicker implementation
Cons of Tingle
- Larger file size (11.5KB vs 3.5KB for Micromodal)
- Less focus on accessibility features
- May require more setup for basic use cases
Code Comparison
Tingle:
var modal = new tingle.modal({
footer: true,
stickyFooter: false,
closeMethods: ['overlay', 'button', 'escape'],
closeLabel: "Close",
cssClass: ['custom-class-1', 'custom-class-2'],
});
modal.setContent('<h1>Here\'s some content</h1>');
modal.open();
Micromodal:
MicroModal.init();
MicroModal.show('modal-1');
Both Tingle and Micromodal are lightweight JavaScript modal libraries, but they differ in their approach and features. Tingle offers more built-in customization options and styling, making it suitable for complex modal requirements. Micromodal, on the other hand, focuses on simplicity and accessibility, with a smaller footprint and easier integration for basic use cases. The code comparison demonstrates that Tingle requires more setup but provides more control, while Micromodal aims for a more straightforward implementation.
No longer actively maintained.
Pros of Remodal
- More customizable with various animation options and styles
- Supports multiple instances and chaining of modals
- Includes built-in responsive design features
Cons of Remodal
- Larger file size and potentially heavier on resources
- Less frequently updated (last update in 2017)
- More complex setup and configuration required
Code Comparison
Remodal:
$(document).ready(function () {
$('[data-remodal-id=modal]').remodal();
});
Micromodal:
MicroModal.init({
onShow: modal => console.info(`${modal.id} is shown`),
onClose: modal => console.info(`${modal.id} is hidden`),
openTrigger: 'data-custom-open',
closeTrigger: 'data-custom-close',
disableScroll: true,
disableFocus: false,
awaitCloseAnimation: false,
debugMode: true
});
Remodal offers a simpler initialization but requires jQuery, while Micromodal provides more configuration options out of the box and is vanilla JavaScript. Micromodal's approach allows for easier customization of triggers and behaviors, making it more flexible for complex use cases. However, Remodal's simplicity might be preferable for quick implementations or projects already using jQuery.
✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦 🇪🇺
Pros of SweetAlert2
- More feature-rich with a wide range of customization options
- Built-in themes and animations for visually appealing alerts
- Supports promise-based async operations
Cons of SweetAlert2
- Larger file size and potentially heavier on resources
- May be overkill for simple modal requirements
- Steeper learning curve due to more complex API
Code Comparison
SweetAlert2:
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!'
})
Micromodal:
MicroModal.show('modal-1');
// HTML
<div id="modal-1" aria-hidden="true">
<div tabindex="-1" data-micromodal-close>
<div role="dialog" aria-modal="true">
<!-- Modal content -->
</div>
</div>
</div>
SweetAlert2 offers a more comprehensive solution with built-in styling and functionality, while Micromodal provides a lightweight, flexible foundation for custom modal implementations. SweetAlert2 is ideal for projects requiring rich, interactive alerts, whereas Micromodal is better suited for developers who prefer granular control over modal behavior and appearance.
Elegant, responsive, flexible and lightweight modal plugin with jQuery.
Pros of iziModal
- More customization options for modal appearance and behavior
- Built-in support for AJAX content loading
- Smaller file size, potentially leading to faster load times
Cons of iziModal
- Less actively maintained (last update was in 2019)
- Documentation is not as comprehensive as Micromodal
- May have compatibility issues with newer browser versions
Code Comparison
Micromodal:
MicroModal.init();
MicroModal.show('modal-1');
iziModal:
$("#modal").iziModal();
$("#modal").iziModal('open');
Both libraries offer simple initialization and opening of modals, but iziModal uses jQuery syntax while Micromodal uses vanilla JavaScript. iziModal provides more options for customization during initialization, while Micromodal focuses on simplicity and ease of use.
Overall, Micromodal is better suited for projects requiring a lightweight, modern modal solution with minimal setup, while iziModal offers more features and customization options at the cost of being slightly more complex and less actively maintained.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Micromodal.js
Tiny, dependency-free javascript library for creating accessible modal dialogs

The aim of this library is to make modal dialogs accessible and easy to include in your project with minimum configuration. It's only ~1.8kb minified and gzipped - A tiny library for big change.
Features
â Toggles relevant aria attributes on open and close
â Closes modal on overlay click
â Closes modal on pressing the esc
key
â Traps tab focus within the modal
â Focuses on the first focusable element within the modal
â Retains the focused element state after closing the modal
Installation
via npm
npm install micromodal --save
via yarn
yarn add micromodal
via CDN direct link
<script src="https://cdn.jsdelivr.net/npm/micromodal/dist/micromodal.min.js"></script>
<!-- or -->
<script src="https://unpkg.com/micromodal/dist/micromodal.min.js"></script>
direct download
curl -O -L https://unpkg.com/micromodal/dist/micromodal.min.js
IE 11 and below
Please use this pollyfill suggested here.
Changelog
Find the latest changelog here.
Contributing
We are always open and invite developers to contribute to Micromodal. We have kept the guidelines and process dead simple, so you invest more time in making modals accessible to all.
Micromodal follows the standardjs coding standard and is part of our package.json
file. It will help us to maintain consistency in the code base.
Development setup
- Clone Github repo
$ git clone https://github.com/ghosh/micromodal.git
- Install
yarn
package manager (Read installation guide) - Run
yarn install
in the root folder to install all dependencies - Run
yarn dev
to start a dev server. This serves the example directory and live reloads when any files are changed - [Optional] Run
yarn build
to build the files for distribution. This is run automatically as a pre-commit hook as well. - Send us pull request and chill
Pushing a new version
First, you must be authorized on npmjs.com. Then:
- Update the npm package:
- Update the version in
lib/package.json
yarn deploy:npm
-
Update the changelog.
-
Commit and push changes
-
Tag the version in git:
git tag -a X.Y.Z
- Add the same text as the changelog to the tag description
git push origin X.Y.Z
- Create a new release in Github: https://github.com/micromodal/micromodal/releases
Want to be a core maintainer?
We are looking for more maintainers for Micromodal. If you are interested, and you have at least some free time to spend on this, reach out to @dkniffin.
Licensing
This project is licensed under MIT license.
Related
- Microtip - Modern, lightweight, accessible css tooltip library. Just 1kb.
Created and maintained by
Derek Kniffin â @dkniffin ðºð¸
Indrashish Ghosh â @_ighosh ð®ð³
Kalpesh Singh - @knowkalpesh ð®ð³
Darpan Kakadia - @kakadiadarpan ð©ðª
Contributors - list ð
You? - Open a PR to get started!
Top Related Projects
⭕ Tiny javascript library for creating accessible modal dialogs
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
No longer actively maintained.
✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦🇪🇺
Elegant, responsive, flexible and lightweight modal plugin with jQuery.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot