Use Grayshift’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.

How it works

Before getting started with Grayshift’s modal component, be sure to read the following as our menu options have recently changed.

  • Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead.
  • Clicking on the modal “backdrop” will automatically close the modal.
  • Grayshift only supports one modal window at a time. Nested modals aren’t supported as we believe them to be poor user experiences.
  • Modals use position: fixed, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting a .modal within another fixed element.


Live demo

Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.

<button class="btn btn-primary mb-5" data-toggle="modal" data-target="#exampleModal" type="button">Launch live modal</button>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="fs-2" id="exampleModalLabel">Modal</h1>
        <button class="btn btn-auto d-inline-flex flex-shrink-0 align-items-center justify-content-center p-0 rounded-circle" data-dismiss="modal" style="width: 2.5rem; height: 2.5rem;" type="button" aria-label="Close">
          <svg class="gi gi-x fs-3" width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor" xmlns="">
            <path d="M7.613 6.2l.094.083L12 10.585l4.293-4.292.094-.083a1 1 0 0 1 1.403 1.403l-.083.094L13.415 12l4.292 4.293a1 1 0 0 1-1.32 1.497l-.094-.083L12 13.415l-4.293 4.292-.094.083a1 1 0 0 1-1.403-1.403l.083-.094L10.585 12 6.293 7.707a1 1 0 0 1 1.32-1.497z"/>
      <div class="modal-body">
        <p>Woohoo, you're reading this text in a modal!</p>
      <div class="modal-footer">
        <button class="btn btn-lg btn-primary w-100" type="button">Save changes</button>

Vertically centered

Add .modal-dialog-centered to .modal-dialog to vertically center the modal.

<div class="modal-dialog modal-dialog-centered"></div>

Scrolling long content

You can also create a scrollable modal that allows scroll the modal body by adding .modal-dialog-scrollable to .modal-dialog.

<div class="modal-dialog modal-dialog-scrollable"></div>

Remove animation

For modals that simply appear rather than fade in to view, remove the .fade class from your modal markup.

<div class="modal" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"></div>


Be sure to add aria-labelledby, referencing the modal title, to .modal. Additionally, you may give a description of your modal dialog with aria-describedby on .modal. Note that you don’t need to add role="dialog" since we already add it via JavaScript.

Optional sizes

Modals have three optional sizes, available via modifier classes to be placed on a .modal-dialog. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.

Our default modal without modifier class constitutes the “medium” size modal.

<div class="modal-dialog modal-xl"></div>
<div class="modal-dialog modal-lg"></div>
<div class="modal-dialog modal-sm"></div>