Skip to content

Modals

JS Optional

Modals are flexible dialog prompts.

Open Modal

Add a container element with the modal class. And add a real container modal-container and overlay modal-overlay inside it. You can add child elements with the modal-header, modal-body and modal-footer - any or all of them.

html
<!-- button trigger -->
<a class="btn btn-primary" href="#modal-1">Open Modal</a>

<!-- modal container -->
<div class="modal" id="modal-1">
  <a href="#close" class="modal-overlay" aria-label="Close"></a>
  <div class="modal-container">
    <div class="modal-header">
      <a href="#close" class="btn btn-clear float-right" aria-label="Close"></a>
      <div class="modal-title h5">Modal title</div>
    </div>
    <div class="modal-body">
      <div class="content">
        <!-- content here -->
      </div>
    </div>
    <div class="modal-footer">
      ...
    </div>
  </div>
</div>

The CSS-only version works by leveraging the CSS pseudo-property :target which works in conjunction with the location hash; clicking on a link with href #modal-1 changes the URL and displays the HTML element with the id modal-1. To close, you can change the location hash to something like #close or just #.

In JavaScript, you can toggle modal container visibility by adding the active class.

Sizes

Open small size Modal

Use the modal-sm class for a smaller modal dialog. The container max width is 320px.

Open large size Modal

Use the modal-lg class for a full size modal. The container max width is 960px.

html
<div class="modal modal-sm">
  <a href="#close" class="modal-overlay" aria-label="Close"></a>
  <div class="modal-container">
    <!-- modal structure here -->
  </div>
</div>