Skip to content
Versions v4 v3 v2 v1

Modal

A modal displays important information to a user without requiring them to navigate to a new page.

Installation

We recommend loading elements via a CDN such as JSPM and using an import map to manage your dependencies.

For more information on import maps and how to use them, see the import map reference on MDN Web Docs.

If you are using node and NPM, you can install this component using npm:

npm install @patternfly/elements

Then import this component into your project by using a bare module specifier:

import '@patternfly/elements/pf-modal/pf-modal.js';

Please Note You should either load elements via a CDN or install them locally through NPM. Do not do both.

Overview

Modal with a header

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Learn more
Open modal

Installation

npm install @patternfly/elements

Usage

Modal with a header

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Learn more
Open modal
View HTML Source
<pf-modal trigger="usage-trigger">
  <h2 slot="header">Modal with a header</h2>
  <p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <a href="#bar">Learn more</a>
</pf-modal>
<pf-button id="usage-trigger">Open modal</pf-button>

Slots

Default Slot

The default slot can contain any type of content. When the header is not present this unnamed slot appear at the top of the modal window (to the left of the close button). Otherwise it will appear beneath the header.

header

The header is an optional slot that appears at the top of the modal window. It should be a header tag (h2-h6).

footer

Optional footer content. Good place to put action buttons.

Attributes

Small modal with a header

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Learn more
Open a small modal
View HTML Source
<pf-modal variant="small" trigger="rendered-slot-small">
  <h2 slot="header">Small modal with a header</h2>
  <p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <a href="#bar">Learn more</a>
</pf-modal>
<pf-button id="rendered-slot-small"> Open a small modal </pf-button>

Medium modal with a header

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Learn more
Open a medium modal
View HTML Source
<pf-modal variant="medium" trigger="rendered-slot-medium">
  <h2 slot="header">Medium modal with a header</h2>
  <p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <a href="#bar">Learn more</a>
</pf-modal>
<pf-button id="rendered-slot-medium"> Open a medium modal </pf-button>

Large modal with a header

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Learn more
Open a large modal
View HTML Source
<pf-modal variant="large" trigger="rendered-slot-large">
  <h2 slot="header">Large modal with a header</h2>
  <p>Lorem ipsum dolor sit amet, <a href="#foo">consectetur adipisicing</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <a href="#bar">Learn more</a>
</pf-modal>
<pf-button id="rendered-slot-large"> Open a large modal </pf-button>
variant

The variant controls the width of the modal. There are three options: small, medium and large. The default is large.

DOM Property
variant
Type
'small' | 'medium' | 'large' | undefined
Default
unknown
position

position="top" aligns the dialog with the top of the page

DOM Property
position
Type
'top' | undefined
Default
unknown
open
DOM Property
open
Type
boolean
Default
false
trigger

Optional ID of the trigger element

DOM Property
trigger
Type
string | undefined
Default
unknown

DOM Properties

returnValue
Type
string
Default
''

Methods

setTrigger(element: HTMLElement)
toggle()

Manually toggles the modal.

modal.toggle();
show()

Manually opens the modal.

modal.open();
showModal()
close(returnValue: string)

Manually closes the modal.

modal.close();

Events

open

Fires when a user clicks on the trigger or manually opens a modal.

Event Type:
ModalOpenEvent
close

Fires when either a user clicks on either the close button or the overlay or manually closes a modal.

Event Type:
ModalCloseEvent

CSS Custom Properties

CSS Property Description Default
--pf-c-modal-box--ZIndex 500
--pf-c-modal-box--Width

Width of the modal

calc(100 - 2rem)
--pf-c-modal-box--MaxWidth

Max width of the modal

calc(100 - 2rem)
--pf-c-modal-box--m-sm--sm--MaxWidth

Max width of the small variant modal

35rem
--pf-c-modal-box--m-md--MaxWidth

Max width of the small variant modal

52.5rem
--pf-c-modal-box--m-lg--lg--MaxWidth

Max width of the large variant modal

70rem
--pf-c-modal-box--MaxHeight

Max height of the modal

calc(100 - 3rem)
--pf-c-modal-box--BoxShadow
var(--pf-global--BoxShadow--xl)
--pf-c-modal-box__title--FontSize
1.5rem
--pf-c-modal-box--m-align-top--MarginTop
2rem
--pf-c-modal-box--m-align-top--MaxWidth
--pf-c-modal-box--m-align-top--MaxHeight
--pf-c-modal-box--BackgroundColor
#fff
--pf-c-modal-box__title--FontFamily

default font family for header-slotted headings

CSS Shadow Parts

overlay

The modal overlay which lies under the dialog and above the page body

dialog

The dialog element

content

The container for the dialog content

header

The container for the optional dialog header

description

The container for the optional dialog description in the header

close-button

The modal's close button

footer

Actions footer container

© 2018-2024 Red Hat, Inc. Deploys by Netlify