Skip to content

Modal

The modal system is built using the native HTML <dialog> element and enhanced with CSS for styling and animations. It’s designed to be highly composable, allowing you to build modals ranging from simple to complex by combining various features.

Default Behavior

The default modal implementation centers in the viewport on desktop and slides up from the bottom on mobile devices. It includes a semi-transparent, blurred backdrop and can be closed with the ESC key. All modals are fully accessible with ARIA attributes and support both mouse and keyboard navigation.

Mobile Implementation

On mobile devices (screens below 640px), modals slide up from the bottom and take full width of the viewport. They feature reduced padding, and hero images adjust to a top-banner layout.

Complete Modal Example

Here’s an example that combines multiple features into a complete modal. This demonstrates how the modal system’s composable nature allows you to build complex interfaces by combining simple components. This example includes a hero image with responsive layout, a close button in the control bar, structured content with title and body, primary and secondary actions, and supports backdrop click-to-close.

Basic Modal

The simplest implementation of a modal includes basic container styling, a backdrop with blur effect, ESC key to close, and default padding and margins.

The styling of the base modal is defined by the following variables. As with all components, they will use these default values, but can be redefined within your main css file.

VariableDefault ValueDescription
--modal-min-width320pxMinimum width of the modal container
--modal-margin2remMargin around the modal on desktop
--modal-padding2remInternal padding of the modal content
--modal-mobile-padding1remInternal padding on mobile devices
--modal-mobile-margin0remMargin around the modal on mobile
--modal-hero-width18remWidth of hero image section on desktop
--modal-scale0.95Initial scale of modal for animation
--modal-mobile-hero-height150pxHeight of hero image on mobile devices
--modal-mobile-max-height90vhMaximum height of modal on mobile
--modal-backdrop-blur4pxBlur effect intensity for the backdrop
--modal-backdrop-colorrgba(0, 0, 0, 0.3)Color and opacity of the modal backdrop
--modal-animation-durationvar(--duration-speed-slow)Duration of modal animations
--modal-radiusvar(--radius-site)Border radius of the modal
--modal-box-shadowvar(--shadow-site)Shadow effect for the modal box
--modal-mobile-shadowvar(--shadow-site)Shadow effect for the modal box on mobile

Disable Backdrop

To remove the backdrop blur and dimming effects, add the modal-disable-backdrop class to the dialog element alongside the modal class.

Backdrop Click Away

To enable closing the modal by clicking the backdrop, add a form element with method="dialog" and the modal-clickaway class after the modal content.

Hero Image

To create a modal with a hero image, add the modal-container--with-hero class to your modal container. Place your image with the modal-hero-image class in a separate div before your content. The layout will automatically adjust between desktop (left-aligned) and mobile (top-aligned).

The hero image is affected by the following variables:

VariableDefault ValueDescription
--modal-hero-width18remWidth of hero image section on desktop
--modal-mobile-hero-height150pxHeight of hero image on mobile devices

Fullscreen Modals

The modal system supports fullscreen layouts for both desktop and mobile views. You can control this behavior using two classes:

  • modal-fullscreen: Makes the modal fill the entire viewport on desktop
  • modal-fullscreen-mobile: Makes the modal fill the entire viewport on mobile devices

These classes can be used independently or together for different responsive behaviors.

Disable Entrance animation

By applying the modal-disable-entrance class, the pop up / slide in animations are disabled for desktop and mobile respectively.

Accessibility

The modal system is built following the WAI-ARIA Modal Dialog Pattern, implementing key accessibility features through semantic HTML and ARIA attributes.

Current Implementation Features

Structure and Labeling

Each modal includes:

  • The role="dialog" attribute to identify it as a modal dialog
  • aria-modal="true" to indicate it’s a modal context
  • aria-label to provide an accessible name for the modal
  • aria-controls on trigger buttons to associate them with their respective modals

Keyboard Support

The native HTML <dialog> element provides:

  • ESC key to close the modal
  • Tab key to navigate through focusable elements
  • Automatic focus management within the modal

Screen Reader Support

Each modal variant includes:

  • Clear labeling of all interactive elements
  • Proper content organization
  • Hidden decorative elements using aria-hidden="true"
  • Descriptive button labels for actions and close buttons

Mobile Accessibility

For mobile devices:

  • Clear close mechanisms (either close button or backdrop)
  • Touch-friendly target sizes
  • Maintained content structure

Required Implementation Steps

When implementing modals in your project, ensure you:

Content Structure

  • Use semantic HTML elements for content structure
  • Include descriptive text for all buttons and interactive elements
  • Maintain proper focus management

Keyboard Navigation & focus

  • Javascript must be used to entirely trap the focus within the modal. In some browsers such as chrome, one the user has reached the end of the modal, tabbing again will move focus to the browsers toolbar. In order to make the modal as accessible as possible, it should ignore the tool bar and go back to the start of the modals index.

ARIA Attributes

  • Add appropriate aria-label value to the dialog element
  • Include aria-controls on trigger buttons
  • Add descriptive aria-label values for action buttons
  • Use aria-hidden="true" for decorative elements