css modal box overlay

How we can create a dialog or modal box using HTML CSS & JS? Solution: CSS Modal Box With Overlay, HTML CSS jQuery Modal or Dailog Box.

Maybe you have seen many types of the modal box in many places, Some peoples call is Dialog box also. For example, when we log out from facebook there a confirmation appears to are you sure, that’s called dialog modal box. Like that there some other major modal box like datepicker, alert to users, etc are called modal.

Today you will learn to create a dialog or modal box using HTML CSS & jQuery. Basically, I used the jQuery for the button, the modal box appears on button click that’s function handled by jQuery. If you want to create this without jQuery or JavaScript, then see my one of the previous post for creating Popup With Pure CSS.

So, Today I am sharing CSS Modal Box With Overlay. In other words, A modal box with the overlay features using HTML, CSS, & JQuery. I am using a basic login form in the modal box, you can change this section as you want. As I told this has an overlay feature, after opening the modal box there will a color appears with low opacity that’s called overlay. If you don’t know about overlay, then check out my this post:  CSS Overlay Menu.

If you are thinking now how this dialog or modal box actually is, then see the preview given here below.

Preview Of jQuery Modal Dialogs With Overlay

See this video preview to getting an idea of how this modal box looks like.

Now you can see this visually. If you like this, then get the source code of its.

You May Also Like:

How I created This Login Dialog Box

Before sharing source code, let’s talk about it. As I told you, I am using a Login Form with the modal box.  For creating the modal box, I created a Div with class name “modal“. Inside the box, I placed two inputs for Username & Password field, a heading & a login button. I added a code on the main div called “modal” after the class name aria-hidden="true" (get info). Basically, this code is for hiding the modal box, it will appear on button click using jQuery.

Inside the modal box, I have created a close button to close the element and placed it on the right top position. Also in this element, I add the aria-hidden="true" command.  After hiding the modal box, I created a button to show it. Using hyperlink tag I have created the button with heading “Open Modal Box“. In this button, I have added the class name “openmodal” and in the close button on box, I added the class named “closemodal”.

In the jQuery section, we handling the close & open feature of the modal box. When we click on the button named “Open Modal Box” then jQuery add a class “opened” on the main div with replacing  aria-hidden="true" . The same way when we click on the close button then jQuery removes the “opened” class.

Most of the works are in CSS, that’s why I am calling it CSS Modal Box. In the CSS section, I have put all the styles, position, etc. For creating the close button icon I placed an HTML symbol code × that’s creating a cross icon. Using CSS I have also styled this and place it in the perfect position. For creating the overlay feature, I have put a background color with low opacity when our modal box is active or opened.

CSS Modal Box With Overlay Source Code

That is the whole concept there is nothing left to explain, Left other things you will understand after getting the codes. For creating this Dialog Box, You have to create 3 files. First for HTML, second for CSS, & the last for JavaScript or jQuery. Follow the steps to creating this without any error.

index.html

Create an HTML file named ‘index.html’ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ & put these codes.

function.js

The last step, Create a JS file for jQuery function named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created a CSS Modal Box With Overlay. In other words, A modal or dialog box with overlay screen using HTML CSS & jQuery. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

16 COMMENTS

  1. How to make a popup modal box , but only first time

    example , i visit some web , and the web showing popup subscribe button

    then when i visit it again , the subscribe button isn’t showing again

  2. This can be made without js. Using input radio buttons with same ‘name’ inside label elements as close and open buttons. Then use, say, input.modalopen:checked > div for expanding the box and input.modalopen:not(:checked) > div for closing the box.

  3. Informative, thanks for posting. I’d like to know how to extract and respond to the inputs that the user provides in such a modal dialog. It doesn’t have to be complicated or realistic, for example just show how one page is opened if the user enters “abc” as the username and another if the user enters “def” as the username.

LEAVE A REPLY

Please enter your comment!
Please enter your name here