Reveal Modal

Modal dialogs, or pop-up windows, are handy for prototyping and production. Foundation includes Reveal our jQuery modal plugin, to make this easy for you.


You can create a reveal modal using minimal markup. The anchor tag with the reveal-modal-id is what triggers the Reveal.


<a href="#" data-reveal-id="myModal">Click Me For A Modal</a> <div id="myModal" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog"> <h2 id="modalTitle">Awesome. I have it.</h2> <p class="lead">Your couch. It is mine.</p> <p>I'm a cool paragraph that lives inside of an even cooler modal. Wins!</p> <a class="close-reveal-modal" aria-label="Close">&#215;</a> </div>

Rendered HTML

Click Me For A Modal


You can create a reveal modal with another inside it. Setting reveal.multiple_opened to true will not close previously opened reveal modals. You can even put a video into a reveal.


<!-- Triggers the modals --> <a href="#" data-reveal-id="firstModal" class="radius button">Modal in a modal&hellip;</a> <a href="#" data-reveal-id="videoModal" class="radius button">Example Modal with Video&hellip;</a> <!-- Reveal Modals begin --> <div id="firstModal" class="reveal-modal" data-reveal aria-labelledby="firstModalTitle" aria-hidden="true" role="dialog"> <h2 id="firstModalTitle">This is a modal.</h2> <p>Reveal makes these very easy to summon and dismiss. The close button is simply an anchor with a unicode character icon and a class of <code>close-reveal-modal</code>. Clicking anywhere outside the modal will also dismiss it.</p> <p>Finally, if your modal summons another Reveal modal, the plugin will handle that for you gracefully.</p> <p><a href="#" data-reveal-id="secondModal" class="secondary button">Second Modal...</a></p> <a class="close-reveal-modal" aria-label="Close">&#215;</a> </div> <div id="secondModal" class="reveal-modal" data-reveal aria-labelledby="secondModalTitle" aria-hidden="true" role="dialog"> <h2 id="secondModalTitle">This is a second modal.</h2> <p>See? It just slides into place after the other first modal. Very handy when you need subsequent dialogs, or when a modal option impacts or requires another decision.</p> <a class="close-reveal-modal" aria-label="Close">&#215;</a> </div> <div id="videoModal" class="reveal-modal large" data-reveal aria-labelledby="videoModalTitle" aria-hidden="true" role="dialog"> <h2 id="videoModalTitle">This modal has video</h2> <div class="flex-video widescreen vimeo"> <iframe width="1280" height="720" src="//" frameborder="0" allowfullscreen></iframe> </div> <a class="close-reveal-modal" aria-label="Close">&#215;</a> </div> <!-- Reveal Modals end -->

Rendered HTML

Modal in a modal… Example Modal with Video…


Additional classes can be added to your reveal modal to change its appearance.

The class options:

  • tiny: Set the width to 30%.
  • small: Set the width to 40%.
  • medium: Set the width to 60%.
  • large: Set the width to 70%.
  • xlarge: Set the width to 95%.
  • full: Set the width and height to 100%.

Note: Default on small is 100% (full) width.

Removing the Background


<div class="reveal-modal-bg" style="display: none"></div>
Firing a Reveal Modal

To launch a modal, just add a data-reveal-id to the object which you want to fire the modal when clicked. The data-reveal-id needs to match the id of your reveal.


<a href="#" data-reveal-id="myModal">Click Me For A Modal</a>

You can also open and close Reveal via Javascript:

// trigger by event $('a.reveal-link').trigger('click'); $('a.close-reveal-modal').trigger('click'); // or directly on the modal $('#myModal').foundation('reveal', 'open'); $('#myModal').foundation('reveal', 'close');

Or you can call one right after the other:

<div class='reveal-modal' id='first-modal' data-reveal> I'm the firstborn! <a class='open-second'>Click me!</a> </div> <div class='reveal-modal' id='second-modal' data-reveal> I'm the secondborn! <a class='close'>Close modal</a> </div> <a class='open-first'>Click me!</a>
// There's no need to close a previous modal before you // open another one. $('').on('click', function() { $('#first-modal').foundation('reveal','open'); }); $('').on('click', function() { $('#second-modal').foundation('reveal', 'open'); }); $('a.close').on('click', function() { $('#second-modal').foundation('reveal', 'close'); });
Firing a Reveal Modal with Ajax Content
To launch a modal with content from another page, just add a data-reveal-ajax attribute pointing to the url of that page. When clicked, the Reveal modal will be opened with a content from that page. Beware: content of the object from data-reveal-id attribute will be overwritten as a result. To use an url from href attribute just add data-reveal-ajax="true" instead.


<button data-reveal-id="myModal" data-reveal-ajax="http://some-url"> Click Me For A Modal </button> <a href="http://some-url" data-reveal-id="myModal" data-reveal-ajax="true"> Click Me For A Modal </a>
Ajax-based Reveal modals can also be opened via Javascript:


// just an url $('#myModal').foundation('reveal', 'open', 'http://some-url'); // url with extra parameters $('#myModal').foundation('reveal', 'open', { url: 'http://some-url', data: {param1: 'value1', param2: 'value2'} }); // url with custom callbacks $('#myModal').foundation('reveal', 'open', { url: 'http://some-url', success: function(data) { alert('modal data loaded'); }, error: function() { alert('failed loading modal'); } });

Please refer to for a complete list of possible parameters.

Event Bindings

There are a series of events that you can bind to for triggering callbacks:

Deprecation Notice

Previous versions of the reveal plugin emitted un-namespaced open, opened, close and closed events, however, these have been replaced by the namespaced open.fndtn.reveal, opened.fndtn.reveal, close.fndtn.reveal and closed.fndtn.reveal events. The un-namespaced events have been fully deprecated.

$(document).on('open.fndtn.reveal', '[data-reveal]', function () { var modal = $(this); }); $(document).on('opened.fndtn.reveal', '[data-reveal]', function () { var modal = $(this); }); $(document).on('close.fndtn.reveal', '[data-reveal]', function () { var modal = $(this); }); $(document).on('closed.fndtn.reveal', '[data-reveal]', function () { var modal = $(this); });


This component is not yet fully accessible. While it is usable via the keyboard, it has to be checked if additional ARIA attributes can enhance the components accessibility.

Customize with Sass

Reveal modals can be easily customized using our Sass variables.


$include-html-reveal-classes: $include-html-classes; // We use these to control the style of the reveal overlay. $reveal-overlay-bg: rgba($black, .45); $reveal-overlay-bg-old: $black; // We use these to control the style of the modal itself. $reveal-modal-bg: $white; $reveal-position-top: rem-calc(100); $reveal-default-width: 80%; $reveal-max-width: $row-width; $reveal-modal-padding: rem-calc(20); $reveal-box-shadow: 0 0 10px rgba($black,.4); // We use these to style the reveal close button $reveal-close-font-size: rem-calc(40); $reveal-close-top: rem-calc(8); $reveal-close-side: rem-calc(11); $reveal-close-color: $base; $reveal-close-weight: $font-weight-bold; // We use this to set the default radius used throughout the core. $reveal-radius: $global-radius; $reveal-round: $global-rounded; // We use these to control the modal border $reveal-border-style: solid; $reveal-border-width: 1px; $reveal-border-color: $steel; $reveal-modal-class: "reveal-modal"; $close-reveal-modal-class: "close-reveal-modal";

Semantic Markup With Sass

You can create your own reveal modals using our Sass mixins.

Setting the background

You can use the reveal-bg() mixin to create your own reveal modal, like so:

.custom-reveal-class { @include reveal-bg(); }

Creating the base structure

You can use this mixin to create the structure of a reveal modal

.custom-reveal-class { @include reveal-modal-base( // Provides reveal base styles, can be set to false to override. $base-style:true, // Sets reveal width Default: $reveal-default-width or 80% $width:$reveal-default-width ); }

Set Reveal Base Styles

You can use this mixin to style the reveal modal defaults

.custom-reveal-class { @include reveal-modal-style( // Sets background color of reveal modal. Default: $reveal-modal-bg or #fff $bg:$reveal-modal-bg, // Set reveal border style. Default: $reveal-border-style or solid $border:true, // Width of border (i.e. 1px). Default: $reveal-border-width. $border-style:$reveal-border-style, // Color of border. Default: $reveal-border-color. $border-width:$reveal-border-width, // Color of border. Default: $reveal-border-color. $border-color:$reveal-border-color, // Choose whether or not to include the default box-shadow. Default: true, Options: false $box-shadow:true, // Default: $reveal-position-top or 50px $top-offset:$reveal-position-top ); }

Add a close button

You can use this mixin to create a close button for the reveal modal

.custom-reveal-class { @include reveal-close( $color:$reveal-close-color ); }

Note: rem-calc(); is a function we wrote to convert px to rem. It is included in _variables.scss.

Using the Javascript

Before you can use Reveal you'll want to verify that jQuery and foundation.min.js are available on your page. You can refer to the Javascript documentation on setting that up.

If you are not using foundation.min.js and individually adding plugins, include foundation.reveal.js AFTER the foundation.js file. Your markup should look something like this:

<body> ... <script src="js/vendor/jquery.js"></script> <script src="js/foundation/foundation.js"></script> <script src="js/foundation/foundation.reveal.js"></script> <!-- Other JS plugins can be included here --> <script> $(document).foundation(); </script> </body>

Required Foundation Library: foundation.reveal.js

Optional Javascript Configuration

Reveal options can only be passed in during initialization at this time. However, you can bind to the open, opened, close, and closed events.

You can also specify an AJAX error callback with the option on_ajax_error.
{ animation: 'fadeAndPop', animation_speed: 250, close_on_background_click: true, dismiss_modal_class: 'close-reveal-modal', multiple_opened: false, bg_class: 'reveal-modal-bg', root_element: 'body', on_ajax_error: $.noop, bg : $('.reveal-modal-bg'), css : { open : { 'opacity': 0, 'visibility': 'visible', 'display' : 'block' }, close : { 'opacity': 1, 'visibility': 'hidden', 'display': 'none' } } }

### Adding New Reveal Content After Page Load If you add new content after the page has been loaded, you will need to reinitialize the Foundation JavaScript by running the following:
Reflow will make Foundation check the DOM for any elements and re-apply any listeners to them.
$(document).foundation('reveal', 'reflow');
Sass Errors?

If the default "foundation" import was commented out, then make sure you import this file:


@import "foundation/components/reveal";

Building Blocks Using Reveal Modal

Want more? Check out all the hot Building Blocks ⇨

Stay on top of what’s happening in responsive design.

Sign up to receive monthly Responsive Reading highlights. Read Last Month's Edition »