Lightweight and flexible JavaScript modal library


Lightweight and flexible JavaScript modal library


  • The size is 3 kB (gzip), doesn’t need any dependencies. HystModal is written in pure JavaScript, does not require jQuery or other libraries to work
  • Carefully designed UX for ease of use. Prevent scrolling of the background, three ways to close the window, scroll bar tracking, centering the modal.
  • Full customizable by CSS. Styles of the modal window and background is completely determined in CSS. Based on Flexbox, modals can have any CSS transitions.
  • Without changing the DOM of page Modal opening is performed only by CSS. All custom event listeners on elements inside the modal will not stop working.
  • A11y and capture the focus. Designed with accessibility in mind and WAI-ARIA recommendations. When you opened the modal focus is captures inside.
  • Works in Internet Explorer 11. Works without problems in IE11 and all modern browsers. Don’t need any polyfills or transpiler.


  1. Download and unpack the latest version of hystModal

  2. Connect hystmodal.min.js and hystmodal.min.css from “dist” folder to the page:

    <link rel="stylesheet" href="hystmodal.min.css">
    <script src="hystmodal.min.js"></script>
  3. Put the following markup in your HTML document:

    <div class="hystmodal" id="myModal" aria-hidden="true">
        <div class="hystmodal__wrap">
            <div class="hystmodal__window" role="dialog" aria-modal="true">
                <button data-hystclose class="hystmodal__close">Close</button>  
                <!-- You modal HTML markup -->

.hystmodal - Main selector of the modal. It must have a unique id attribure. This selector don’t get focus when modal is closed, due CSS rules visbility:hidden. Attribute aria-hidden is switches automatically.

.hystmodal__wrap - scrolled area under the modal window. Due of settings, it can close modal window on click/tap. This selecor don’t have background by default. Selector .hystmodal__shadow, which obscures the page content is added automatically directly before closing tag, when the script is loaded.

.hystmodal__window - Modal box. WAI-ARIA recommends adding attribute aria-labelledby with descriptions of the modal for better accessibility.

[data-hystclose] - selector with data-hystclose attribute is closing current modal window on mouse click, if this set on in configuration. This selector may contains in any place inside .hystmodal__window

  1. Place following JS code for activating functionality of modals:

    const myModal = new HystModal({
        linkAttributeName: "data-hystmodal",
        //settings (optional). see Configuration
  2. Add attribute data-hystmodal on element that will be opening the modal window. Value of the attribute must be CSS selector (id or class name of the window). For example:

    <a href="#" data-hystmodal="#myModal">Open modal with id=myModal</a>

Title of data-attribute, which opening the modals, is defined by value of the property linkAttributeName of the configurations object.

  1. If necessary, change the сonfiguration.


Parameter Type Default Description
linkAttributeName String Empty string Define data-attribute of selector, which will be opening modal window on mouse click. Value of this attribute in HTML tag must be equal of CSS selector (id or class) of the modal window selector, which need to be open. If the property is not defined, event handlers will not be activated.
closeOnOverlay Boolean true Allow/disallow closing windows by click or tap on overlay (selector with class .hystmodal__wrap )
closeOnEsc Boolean true Allow/disallow closing windows by pressing ESC on the keyboard
closeOnButton Boolean true Allow/disallow closing windows by click on element with attribute data-hystclose. If there are multiple selectors with this attribute, modal window will closed by click on any of this
waitTransitions Boolean false If true – modal window will be closed after ending of CSS-transition of elements .hystmodal__window. If false – modal window will be closed instantly. So that the opening also took place instantly – delete CSS property transition of .hystmodal__window and set the option waitTransitions:false.
catchFocus Boolean true If true – when modal window is opened, focus will looped on active elements inside modal. When modal window closing, focus returning on previous selector.
fixedSelectors string “*[data-hystfixed]” Contains a css selector that adds an margin-right equal to the width of the scroll bar when opening a modal window. Useful for fixed elements on a page to avoid shifting them when opening a window. Works only if the property backscroll:true
backscroll boolean true If true - the scrolling will be blocked when the window is opened. If false, scrolling is not blocked (if the modal window is high, double scrolling may occur)
beforeOpen function Empty function Callback function. Run before opening of the modal. A modal window object (see API) is passed to the function as argument.
afterClose function Empty function Callback function. Run after closing of the modal. A modal window object (see API) of the closed window is passed to the function as argument.

Configuration example

const myModal = new HystModal({
    linkAttributeName: 'data-hystmodal',
    catchFocus: true,
    waitTransitions: true,
    closeOnEsc: false,
    beforeOpen: function(modal){
        console.log('Message before opening the modal');
        console.log(modal); //modal window object
    afterClose: function(modal){
        console.log('Message after modal has closed');
        console.log(modal); //modal window object


When creating an instance of a class HystModal by code new HystModal({ … }), variable myModal will contain object, which contain properties and methods.


Title Type Description
isOpened Boolean Modal open indicator. True - modal window is open in this moment. False - by default. Many private methods of the library are guided by the value of this property.
openedWindow DOM node Selector of current opened modal window. If window is closed - contain selector of last opened window.
starter DOM node Selector from which the modal window was opened. Used to return focus to an element.
config object Configuration object. See Configuration.


Title Description
init() Initializes the modal window functionality and enables event handling on the page. If the linkAttributeName property is specified, init runs automatically when an instance of the HystModal is created. You can specify the linkAttributeName:false when creating instance of the HystModal, and add property later (for example: myModal.config.linkAttributeName = ‘data-othermodal’). Then you must manually call the myModal.init(). Initialization can only do once.
open(selector) Open modal window. selector – a CSS selector of modal window as a string, for example:“#modal-1”). If «selector» is not specified – will open last opened window, or there will be no action. If opening new window while the old one is not closed, the previous window is closed first, and then a new window is opened.
close() Closes the currently open modal window.

Download Details:

Author: AddMoreScripts


Source Code:


What is GEEK

Buddha Community

Lightweight and flexible JavaScript modal library
Raja Tamil

Raja Tamil


Make Pop-Up Modal Window In Vanilla JavaScript [2022]

Make Pop-Up Modal Window In Vanilla JavaScript

Learn how to create a simple responsive pop-up modal window using Vanilla JavaScript along with HTML and CSS with a bit of Flexbox.

Create A Button That Opens Pop Up Modal Window

Declare a <button> HTML element with an id open-modal.

<button id="open-modal">Open Modal Window</button>

The goal is when a user presses this button, the pop-up modal window will open.

Style the button using CSS Flexbox and centre it on the screen.

* {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    box-sizing: border-box;

body {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;

button {
    padding: 10px;
    font-size: 1.1em;
    background: #32bacf;
    color: white;
    border: none;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    cursor: pointer;

button:hover {
    background: rgba(0, 0, 0, 0.7);

Create Pop-Up Modal Overlay

Normally, pop-up modal windows have overlays with a transparent darker background that covers the entire browser screen.

Define a div with an id model-overlay which will cover the entire screen.

<div id="modal-overlay">

Then, make it to full screen using height:100vh CSS property.

Bring it in front of the button by using position:absolute with a transparent background colour.

#modal-overlay {
    width: 100%;
    height: 100vh;
    position: absolute;
    background: rgba(0, 0, 0, 0.7);

I just added the border to see the boundaries of the modal-overlay element.

Center Pop-Up Modal Window To The Modal Overlay

Create a div with an id modal inside the modal-overlay element, which will be an actually pop-up modal window that user interacts with.

<div id="modal-overlay">
  <div id="modal">

Add CSS style to make it visible on the screen.

Adding width:100% and max-width:650px will make sure the width of the pop-up modal window won’t exceed when the browser width is more than 650px.

If the browser width is less than 650px, the pop-up modal window will stretch the width to fill the screen which is normally for mobile viewports.

#modal-overlay #modal {
    max-width: 650px;
    width: 100%;
    background: white;
    height: 400px;

Centre the pop-up modal window to the screen using Flexbox.

To do that, just add the three lines of Flexbox code to the modal-overlay which are

  • display:flex → Convert an HTML element to Flexbox
  • align-items:center → centre the pop-up modal window vertically to the viewport
  • justify-content:center → centre the pop-up modal window horizontally to the viewport
#modal-overlay {
   display: flex;
   align-items: center;
   justify-content: center;

Open Up Pop-Up Modal Window On Button Click

Now we have the basic pop-up modal window designed using CSS.

Make it visible when a user presses the open modal button.

To do that,

First, hide the modal overlay by default by changing its display property from flex to none.

#modal-overlay {
   display: none; // Changed from flex to none
   align-items: center;
   justify-content: center;

Create a DOM reference to the open-modal button as well as the modal-overlay elements.

const openModalButton = document.getElementById("open-modal");
const modalWindowOverlay = document.getElementById("modal-overlay");

Attach a click event to the openModalButton with the callback arrow function showModalWindow.

const showModalWindow = () => { = 'flex';

openModalButton.addEventListener("click", showModalWindow);

Set the display property of the modalWindowOverlay to flex inside showModalWindow() function which will open up the modal window.

As you can see, there is no way we can close/hide the pop-up modalwindow after its became visible on the screen.

Let’s fix it!

Close/Hide Pop-Up Modal Window On Button Click

Typically, there will be a close button on the top or bottom right side of the pop-up modal window.

Let’s add a close button on the bottom left side of the modal window.

Define header, content and footer HTML elements inside the pop-up modal window.

<div id="modal">

    <div class="modal-header">
        <h2>Modal Pop Up Window</h2>

    <div class="modal-content">
        <p>Modal Content</p>
    <div class="modal-footer">
        <button id="close-modal">Close</button>


Generally, you’ll have two buttons on the footer of the pop-up modal window, which may be save and close.

Let’s push the buttons to the bottom using Flexbox.

Turn the display property of the pop-up modal window to flex and set the flex direction to column.

Continue Reading…

#JavaScript #programming #webdev #softauthor 

CodingNepal .

CodingNepal .


Popup Share Modal UI Design using HTML CSS & JavaScript

#css share modal #modal dialog box #popup share modal #share modal #share modal in javascript

Reid  Rohan

Reid Rohan


Keukenhof: Lightweight and Easy to Use The Library for Modals


The lightweight library for modal windows


Table of Contents


Keukenhof.js visualized


Package Manager

Keukenhof.js page on npm

# With npm
npm i keukenhof

# With Yarn
yarn add keukenhof


<script src=""></script>


Part of the preparation of the library work is hidden, you just need to create a layout. There are no restrictions on the layout of your modal window, you just need to add data-keukenhof-open to the value of which you need to specify the selector of the window that should open on click and data-keukenhof-close for the element that should close the currently active modal

<!DOCTYPE html>
<title>Keukenhof.js modal example</title>

    #modal {
        display: none;

    #modal.isOpen {
        display: block;

<button data-keukenhof-open="#modal">Open modal</button>

<!-- Main modal wrapper with required id -->
<div id="modal" role="dialog" aria-hidden="true" aria-labelledby="title" aria-describedby="desc">
    <!-- Element for handling a click outside the modal window -->
    <div class="overlay" tabindex="-1" data-keukenhof-close></div>

        <!-- Button to close the modal window -->
        <button class="close" aria-label="Close modal" data-keukenhof-close>Close</button>

    <!-- Body used to improve a11y by describing the purpose of the modal -->
        <h2 id="title">Keukenhof.js modal</h2>
        <p id="desc">Lightweight and easy to use the library for modals</p>

<script src=""></script>


Module bundlers

An alternative connection option is to use import Keukenhof.js

import {Keukenhof} from 'keukenhof';

// Initializing modal windows based on markup
    // options

// Configure and open modal by selector'#modal', {
    // options

// Close active modal window


The documentation can also be found on the Keukenhof.js website

openAttributeStringThe attribute containing the selector of the modal window that should be opened by clicking on the element
closeAttributeStringThe attribute marking elements inside the modal window, clicking on which will close this modal window
openClassStringThe class name added for the open modal window
openingClassStringThe class name added for the modal window that is in the process of opening (required for modals using CSS animations)
closingClassStringThe class name added for the modal window that is in the process of closing (required for modals using CSS animations)
hasAnimationBooleanIndicates the need to wait for the completion of the CSS animation of opening/closing the modal window
isAssignFocusBooleanIndicates the need to focus on an interactive element inside the modal after opening
isFocusInsideBooleanIndicates the need to restrict focusable interactive elements using the keyboard inside the active modal
scrollBehaviorObjectSpecify the need to block the scroll after opening a modal window. The scroll is blocked with overflow: hidden; if after closing the modal the overflow value should be defined just specify this as defaultValue
onOpenFunctionDefines a function that will be called when the modal is open (if hasAnimation: true; is called after the animation has finished)
onCloseFunctionDefines a function that will be called when the modal is close (if hasAnimation: true; is called after the animation has finished)
beforeOpenFunctionDefines a function to be called before the modal opens. If the function returns false the modal won't open
beforeCloseFunctionDefines a function to be called before the modal closes. If the function returns false the modal won't close



Initializes all modals based on markup. Accepts one optional parameter for configuration

    selector: '#modal-1',
    openAttribute: 'data-modal-open',
    closeAttribute: 'data-modal-close',
    openClass: 'is-open',
    openingClass: 'is-opening',
    closingClass: 'is-closing',
    hasAnimation: true,
    isAssignFocus: false,
    isFocusInside: false,
    scrollBehavior: {
        isDisabled: true,
    onOpen: () => console.log('The modal window is open'),
    onClose: () => console.log('The modal window is close'),


Opens a modal window with the given selector. The open() method has a second optional parameter for configuration

// With config'#modal', {
    openAttribute: 'data-modal-open',
    closeAttribute: 'data-modal-close',
    openClass: 'is-open',
    openingClass: 'is-opening',
    closingClass: 'is-closing',
    hasAnimation: true,

// Without config'#modal');


Closes the modal with the given selector. If no parameters are passed to the close() method, the currently open window will be closed

// With selector

// Without selector


  1. Clone the repository
  2. Go to the project directory cd keukenhof
  3. Install dependencies yarn
  4. Run dev build with auto rebuild after any changes yarn build:dev
  5. Complete your improvements, commit changes and submit your pull request for review code

Author: Alexandrshy
Source Code: 
License: MIT License

#javascript #typescript 

Rahul Jangid


What is JavaScript - Stackfindover - Blog

Who invented JavaScript, how it works, as we have given information about Programming language in our previous article ( What is PHP ), but today we will talk about what is JavaScript, why JavaScript is used The Answers to all such questions and much other information about JavaScript, you are going to get here today. Hope this information will work for you.

Who invented JavaScript?

JavaScript language was invented by Brendan Eich in 1995. JavaScript is inspired by Java Programming Language. The first name of JavaScript was Mocha which was named by Marc Andreessen, Marc Andreessen is the founder of Netscape and in the same year Mocha was renamed LiveScript, and later in December 1995, it was renamed JavaScript which is still in trend.

What is JavaScript?

JavaScript is a client-side scripting language used with HTML (Hypertext Markup Language). JavaScript is an Interpreted / Oriented language called JS in programming language JavaScript code can be run on any normal web browser. To run the code of JavaScript, we have to enable JavaScript of Web Browser. But some web browsers already have JavaScript enabled.

Today almost all websites are using it as web technology, mind is that there is maximum scope in JavaScript in the coming time, so if you want to become a programmer, then you can be very beneficial to learn JavaScript.

JavaScript Hello World Program

In JavaScript, ‘document.write‘ is used to represent a string on a browser.

<script type="text/javascript">
	document.write("Hello World!");

How to comment JavaScript code?

  • For single line comment in JavaScript we have to use // (double slashes)
  • For multiple line comments we have to use / * – – * /
<script type="text/javascript">

//single line comment

/* document.write("Hello"); */


Advantages and Disadvantages of JavaScript

#javascript #javascript code #javascript hello world #what is javascript #who invented javascript

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

It is said that a digital resource a business has must be interactive in nature, so the website or the business app should be interactive. How do you make the app interactive? With the use of JavaScript.

Does your business need an interactive website or app?

Hire Dedicated JavaScript Developer from WebClues Infotech as the developer we offer is highly skilled and expert in what they do. Our developers are collaborative in nature and work with complete transparency with the customers.

The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.

Get your business app with JavaScript

For more inquiry click here

Book Free Interview:

#hire dedicated javascript developers #hire javascript developers #top javascript developers for hire #hire javascript developer #hire a freelancer for javascript developer #hire the best javascript developers