Nifty Modal Window Effects

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

From our sponsor: Market smarter with Mailchimp's automated messaging tools.

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>
		<div>
			<p>This is a modal window. You can do the following things with it:</p>
			<ul>
				<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>
			</ul>
			<button class="md-close">Close me!</button>
		</div>
	</div>
</div>

...

<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,
.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-show.md-effect-5 ~ .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-show.md-effect-5 .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-show.md-effect-x .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.

http://www.codrops.com

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

CSS Reference

Learn about all important CSS properties from the basics with our extensive and easy-to-read CSS Reference.

It doesn't matter if you are a beginner or intermediate, start learning CSS now.

Feedback 228

Comments are closed.
  1. Awesome effects. I get weird rendering on my Chrome though… The box does not completly look solid, looks like a break or something. I am using 27 inch iMac with the latest version of Chrome: http://imgur.com/E4Xqzgj

    • Hey Roman, that looks weird indeed. I have a strange feeling that this has to do with using ems. A pixel-based approach should avoid something like that I believe. Thanks for your feedback! Cheers, ML

    • I’m getting the same thing. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
      Works fine in FF 22.
      In Safari 6.0.5, it looks like the scaling doesn’t finish correctly because the modal contents are blurry (but there’s no line like in Chrome). See http://cl.ly/image/3G2c0S2x3H30
      Weirdly, Opera Next 15 looks fine.
      And Chrome Canary is looking fine. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.3 Safari/537.36
      Maybe it’s just Chrome 27?

  2. Thanks Once Again, for the inspiration!
    Codrops has become my go to for design inspiration.
    Your contributors and staff have excellent realistic approaches to the design dilemma
    keeping it original and unique. nothing more nothing less.
    Keep up the great work.
    The more things change, the more they stay the same.

  3. Greetings!
    Excellent showcase.
    Too bad the Blurred effect cant still be executed on IE. Tested it on ie10 too

    Thanks
    Love from Portugal
    JD

  4. Great!
    Last week I developed something very similar for one of my clients but didn’t have the chance to experiment with all the transitions and didn’t think about the sibling… cool stuff, thank you.

  5. I am always a big fan! Modals are one of those things I always take for granted until I need them. Then I look to posts like this to spark my creativity. Thanks gain for being…..well who you are! 🙂

  6. Hi Mary Lou,

    Is there anyway or option that can change the code so they window popup upon page load?

  7. It’s really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really cool !

  8. Really impressive, it gives me some useful inspirations and/or ways to do things like that.

    Thanks !

  9. Very cool, but clean effects. Not too gaudy or tacky with a great appreciation for design. Very nicely done. Thanks for sharing! 🙂