Nifty Modal Window Effects

A set of experimental modal window appearance effects with CSS transitions and animations.

From our sponsor: Ship fast and never break a thing with Shortcut (formerly

Today we want to share some ideas for modal window effects with you. There are infinite possibilities for transitioning the appearance of a dialog box and we wanted to provide some ideas of how to show dialog boxes and provide some inspiration.

The idea is to have a trigger button (or any element) which will make a modal window appear on click using a simple transition (or animation).

Please note: this only works as intended in browsers that support the respective CSS
properties. Modern browsers only!

There are some knows issue with using visibility/opacity for iOS < 6 Mobile Safari, so this probably won't work on older devices.

The structure of the modal window consists of a main wrapper and a content division:

<div class="md-modal md-effect-1" id="modal-1">
	<div class="md-content">
		<h3>Modal Dialog</h3>
			<p>This is a modal window. You can do the following things with it:</p>
				<li><strong>Read:</strong> Modal windows will probably tell you something important so don't forget to read what it says.</li>
				<li><strong>Look:</strong> modal windows enjoy a certain kind of attention; just look at it and appreciate its presence.</li>
				<li><strong>Close:</strong> click on the button below to close the modal.</li>
			<button class="md-close">Close me!</button>


<div class="md-overlay"></div>

The main wrapper is used as a container that will simply be shown or hidden (with visibility, using the class “md-show”) and the inner content will have the transition. The overlay is placed after the modal(s), so we can control the appearance using the adjacent sibling selector:

.md-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	width: 50%;
	max-width: 630px;
	min-width: 320px;
	height: auto;
	z-index: 2000;
	visibility: hidden;
	backface-visibility: hidden;
	transform: translateX(-50%) translateY(-50%);

.md-show {
	visibility: visible;

.md-overlay {
	position: fixed;
	width: 100%;
	height: 100%;
	visibility: hidden;
	top: 0;
	left: 0;
	z-index: 1000;
	opacity: 0;
	background: rgba(143,27,15,0.8);
	transition: all 0.3s;

.md-show ~ .md-overlay {
	opacity: 1;
	visibility: visible;

For some effects we will also add a class to the html element. We want this for creating some 3D effects on the body and the content. Note that we are assuming that all the content of the page (except the modal and the overlay) are wrapped in a container:

.md-perspective body {
	height: 100%;
	overflow: hidden;

.md-perspective body  {
	background: #222;
	perspective: 600px;

.container {
	background: #e74c3c;
	min-height: 100%;

To be able to control each effect, we use an additional effect class to define what kind of transition we want for that specific modal window. An example for an individual effect is the following:

/* Effect 5: newspaper */ ~ .md-overlay {
	background: rgba(0,127,108,0.8);

.md-effect-5 .md-content {
	transform: scale(0) rotate(720deg);
	opacity: 0;
	transition: all 0.5s;
} .md-content {
	transform: scale(1) rotate(0deg);
	opacity: 1;

The trigger buttons will have a data-attribute that holds the reference to the modal box that we want to show:

<button class="md-trigger" data-modal="modal-5">Newspaper</button>

For the special perspective cases, we’ll also add the class “md-setperspective” to the trigger button.

With JavaScript we’ll simple add the class “md-show” to the respective modal when we click on a button, and, if indicated, the “md-perspective” class to the html element.

To experiment with new effects, add a new button and a new modal with an effect class and an ID, referencing to that ID in the button’s data-attribute “data-modal”. Then you can add another set of styles for that specific effect.

If you only want the effect/transition to happen when the modal window appears, but not when it disappears, just add the transition to the “ .md-content” declaration (like we did for some of the examples).

For the background blur effect we are using Polyfilter by Christian Schaefer to support older browsers.

I hope you enjoyed these little effect ideas and find them inspiring!

Tagged with:

Mary Lou

ML is a freelance web designer and developer with a passion for interaction design. She studied Cognitive Science and Computational Logic and has a weakness for the smell of freshly ground peppercorns.

Stay up to date with the latest web design and development news and relevant updates from Codrops.

Feedback 228

Comments are closed.
  1. How does validation work with this? I want it to work where the modal only comes up if an email is in a field.

  2. Hi, great tutorial. I am planning to use one of the effects for a mobile app using PhoneGap. It seems however that the effects do not work on android browsers apart from the Google Chrome browser. Has anyone come accross this and does anyone have a fix?


  3. Hey great job Mary Lou i love this and have implemented this into a site. But the problem is if you’re not on the homepage it redirects to the homepage before it will open. Any idea how to fix this?

  4. I want to use this, but want to load in the model, fields to edit that come from a database. I don’t suppose it matters, but I am using terascript as the middleware between the web page and the database. So do I need to use an ajax function in order to do this?

  5. This effect’s are awsome.
    Thanks MARY LOU.
    i will use it on my landing page 🙂

  6. Can you use this or other pop-up modal windows without JavaScript, just HTML5 and CSS3 ?

    Im doing a school project and need a disclaimer on every page, but instead of showing the disclaimer and disrupting the design a want to put a disclaimer link in the footer that triggers a modal window with the required disclaimer when triggered.

    NOT ALLOWED TO USE JavaScript.

    Thanks, 🙂

    • Nope. To bind something to a click event you’ve gotta use javascript. You can do it with very little javascript, and/or an inline `onclick=””` js call but this is not really good practice and not advised.

  7. Awesome Effects … I like it very much … Will try to implement in my site.

  8. Very cool, but the fact that it won’t work in IE8 is still a deal-breaker in my world. What a bummer.

  9. Why do/does the graphics and text in modal view appear blurry?? is there a way to make them more crisp like boot straps modal clarity/quality??

  10. I’m a novice trying to get this to work on a mobile device and want to add content that exceeds the viewing area. Is there a way to make a nice scrolling affect to the modal?

  11. When I`m trying to trigger the modal window, I`m geting an error:
    Method not allowed…

  12. not working with multiple modal

    I have a Login modal and a Cart modal but .md-overlay not work. So i can’t close modal with out click

    If add after login modal => only login modal is work.

    And if add after Cart modal => only Cart modal is work.

    And i need 1 button can trigger 2 modal . because, i using php with modal Cart empty and Cart added items

    Give me some solutions?

    Sorry my bad English

    • You can wrap a view in a ModalView like this:
      _buildModal: function(subview) { var modal = new ModalView({ subView: subview }); subview.on('accept', function() { modal.close(); }); subview.on('cancel', function() { modal.close(); }); return modal; }

      I had this same issue and this was my solution.

  13. i made html page, inside of it i put icons and when i press on them the modal window is open.
    so far so good, but when i put the html page (include) inside of a header.php in wordpress the function doesn’t work.
    need some help!

  14. HIII

    this can be use for multiple different windows???
    contact me by email, please?? :)))

    Very nice and beautiful, congrats! 🙂