Top Related Projects
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
An accessible dialog window library for all humans.
No longer actively maintained.
✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦
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, with a small file size
- Fully accessible, following WAI-ARIA guidelines
- Customizable with various configuration options
- Easy to integrate with existing projects
Cons
- Limited built-in styling options, requiring custom CSS for advanced designs
- No built-in support for nested modals
- May require additional work to make it compatible with older browsers
Code Examples
- Basic usage:
MicroModal.init();
// Open modal
MicroModal.show('modal-1');
// Close modal
MicroModal.close('modal-1');
- Custom configuration:
MicroModal.init({
openTrigger: 'data-custom-open',
closeTrigger: 'data-custom-close',
disableScroll: true,
awaitCloseAnimation: true,
onShow: modal => console.log(`${modal.id} is shown`),
onClose: modal => console.log(`${modal.id} is hidden`)
});
- Programmatically control modals:
const modal = document.getElementById('modal-1');
// Open modal
MicroModal.show('modal-1', {
onShow: modal => console.log(`${modal.id} is shown`)
});
// Close modal
MicroModal.close('modal-1', {
onClose: modal => console.log(`${modal.id} is hidden`)
});
Getting Started
- Install Micromodal:
npm install micromodal --save
- Import and initialize in your JavaScript file:
import MicroModal from 'micromodal';
MicroModal.init();
- Add HTML markup for your 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>
- Trigger the modal:
<button data-micromodal-trigger="modal-1">Open Modal</button>
Competitor Comparisons
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
Pros of Tingle
- More customizable with additional options for positioning, transitions, and callbacks
- Supports multiple instances on a single page
- 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
- Requires more setup code for basic functionality
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 libraries offer lightweight solutions for creating modal dialogs, but they cater to different needs. Tingle provides more out-of-the-box features and customization options, making it suitable for complex use cases. Micromodal, on the other hand, focuses on simplicity and accessibility, with a smaller footprint and easier implementation for basic modal functionality. The choice between the two depends on the specific requirements of your project, balancing features against file size and ease of use.
An accessible dialog window library for all humans.
Pros of Modaal
- More customizable appearance with built-in themes and styling options
- Supports image galleries and iframes out of the box
- Includes accessibility features like ARIA attributes and keyboard navigation
Cons of Modaal
- Larger file size (around 23KB minified) compared to Micromodal's lightweight approach
- Requires jQuery as a dependency
- Less focus on performance optimization
Code Comparison
Micromodal:
MicroModal.show('modal-id');
Modaal:
$('.modal-trigger').modaal({
type: 'inline',
content_source: '#modal-content'
});
Summary
Modaal offers more built-in features and customization options, making it suitable for projects requiring complex modal functionality. However, it comes at the cost of a larger file size and jQuery dependency. Micromodal, on the other hand, focuses on simplicity and performance, with a smaller footprint and no dependencies. The choice between the two depends on project requirements, with Modaal being better for feature-rich modals and Micromodal for lightweight, performant implementations.
No longer actively maintained.
Pros of Remodal
- More customizable with various animation options and styles
- Supports multiple instances on a single page
- Includes built-in close button functionality
Cons of Remodal
- Larger file size and potentially heavier performance impact
- Less focus on accessibility features
- Requires jQuery as a dependency
Code Comparison
Remodal:
$(document).on('opening', '.remodal', function () {
console.log('Modal is opening');
});
$('[data-remodal-id=modal]').remodal();
Micromodal:
MicroModal.init({
onShow: modal => console.log(`${modal.id} is shown`)
});
MicroModal.show('modal-1');
Key Differences
- Remodal uses jQuery syntax and relies on the library, while Micromodal is vanilla JavaScript
- Micromodal has a more straightforward API with a focus on simplicity
- Remodal offers more built-in customization options, but Micromodal provides better accessibility out of the box
- Micromodal has a smaller footprint and potentially better performance, especially for simpler use cases
- Remodal may be easier to implement for developers already familiar with jQuery, while Micromodal aligns better with modern JavaScript practices
✨ 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
- Larger community and more frequent updates
- Built-in themes and animations
Cons of SweetAlert2
- Larger file size, which may impact page load times
- More complex API, potentially steeper learning curve
- Dependency on CSS for styling
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', {
onShow: modal => console.info(`${modal.id} is shown`),
onClose: modal => console.info(`${modal.id} is hidden`),
openTrigger: 'data-custom-open',
closeTrigger: 'data-custom-close'
});
SweetAlert2 offers a more declarative approach with built-in options for common use cases, while Micromodal provides a simpler API focused on modal functionality. SweetAlert2 is better suited for complex alert scenarios, whereas Micromodal excels in lightweight, customizable modal implementations.
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
Licensing
This project is licensed under MIT license.
Related
- Microtip - Modern, lightweight, accessible css tooltip library. Just 1kb.
Contact
You can mention us on Twitter for any questions, suggestions or just send us funny GIF. We â¥ï¸ GIFs.
Tweet some love
Tweet about Micromodal and help us to spread the message about the importance of Web accessibility and Inclusive design.
Created and maintained by
Indrashish Ghosh â @_ighosh ð®ð³
Kalpesh Singh - @knowkalpesh ð®ð³
Darpan Kakadia - @kakadiadarpan ð©ðª
Contributors - list ð
Top Related Projects
⚡ 2kB vanilla modal plugin, no dependencies and easy-to-use
An accessible dialog window library for all humans.
No longer actively maintained.
✨ A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies. 🇺🇦
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