Skip to main content Home About the Design SystemRoadmap OverviewDesignersDevelopers OverviewColorGridIconographyInteractionsSpacingTypography Overview Global colorBox shadowTypographyBorderOpacitySpaceLengthIconBreakpointsMedia queries All elements Accordion Alert Announcement Audio player Avatar Back to top Badge Blockquote Breadcrumb Button Card Chip Code block Call to action Dialog Disclosure Footer Health index Icon Jump links Menu dropdown Navigation link Navigation (primary) Navigation (secondary) Navigation (vertical) Pagination PopoverPlanned Progress stepper Scheme toggle Site status Skeleton Skip link Spinner Statistic Subnavigation Surface Switch Table Tabs Tag Tile Timestamp Tooltip Video embed OverviewColor PalettesCustomizingDevelopers All PatternsAccordionCall to ActionCardFilterFormLink with iconLogo wallSearch barSticky bannerSticky cardTabsTagTile All Personalization PatternsAnnouncement FundamentalsAccessibility toolsAssistive technologiesCI/CDContentContributorsDesignDevelopmentManual testingResourcesScreen readers Design/code status Release notes Get support

Dialog

OverviewStyleGuidelinesCodeAccessibilityDemos
ImportingUsagerh-dialogUsage guidelinesUsage guidelinesAccessibilityUsage guidelinesAccessibilityImportingUsagerh-dialogUsage guidelinesUsage guidelinesAccessibilityUsage guidelinesAccessibility

Importing

Add rh-dialog to your page with this import statement:

<script type="module">
  import '@rhds/elements/rh-dialog/rh-dialog.js';
</script>
Copy to Clipboard Wrap lines

To learn more about installing RHDS elements on your site using an import map read our getting started docs.

Usage

<rh-button id="first-modal-trigger">Open</rh-button>
<rh-dialog trigger="first-modal-trigger">
  <h2 slot="header">Modal dialog 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>
  <rh-cta slot="footer" href="#bar">Call to Action</rh-cta>
</rh-dialog>

<script type="module">
  import '@rhds/elements/rh-button/rh-button.js';
  import '@rhds/elements/rh-cta/rh-cta.js';
  import '@rhds/elements/rh-dialog/rh-dialog.js';
</script>
Copy to Clipboard Wrap lines

rh-dialog

A dialog displays important information to users without requiring them to navigate away from the page.

Slots 4
Slot Name Summary Description
header

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

description

descriptive text providing additional context about the dialog

Contains supplementary text that provides additional context or instructions for the dialog. Appears below the header and above the main content. This slot is optional and should be used when users need more information to understand the dialog's purpose or required actions.

Usage guidelines:

  • Keep description text concise and informative
  • Use to clarify the dialog's purpose or provide instructions
  • Should complement, not duplicate, the dialog header
  • Consider accessibility - description adds context for all users
[default]

The default slot can contain any type of content. When the header is not present this unnamed slot appear at the top of the dialog window (to the left of the close button). Otherwise it will appear beneath the header.
Note: [default] unnamed slots do not have a slot="name" attribute.

footer

Optional footer content. Good place to put action buttons.

Attributes 6
Attribute DOM Property Description Type Default
variant variant

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

'small' | 'medium' | 'large'
unknown
position position

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

'top'
unknown
accessible-label accessibleLabel

Use accessible-label="My custom label" to specify the dialog's accessible name. Defaults to the name of the dialog trigger if no attribute is set and no headings exist in the modal. See Dialog's Accessibility page for more info.

string
unknown
open open

open / open="open" declaratively opens the dialog

boolean
false
trigger trigger

Optional ID of the trigger element

string
unknown
type type

Use type="video" to embed a video player into a dialog.

'video'
unknown
Methods 6
Method Name Description
cancel(returnValue: string)

Cancels and closes the dialog, typically in response to user actions like clicking outside the dialog or pressing ESC.

This method fires a cancelable cancel event before closing. The dialog will only close if the event is not prevented. After canceling, the dialog fires a close event.

Usage guidelines

  • Called automatically when user presses ESC or clicks outside the dialog
  • Can be called programmatically to cancel dialog programmatically
  • Fires cancel event (cancelable) before closing
  • Use close() instead for explicit user actions (like clicking a button)
const dialog = document.querySelector('rh-dialog');
dialog.cancel(); // Cancels with no return value
dialog.cancel('user-cancelled'); // Cancels with return value
setTrigger(element: HTMLElement)

Programmatically sets the trigger element for the dialog.

This method assigns an element as the dialog's trigger and attaches click event listeners. When the trigger is clicked, the dialog opens. Use this when you need to dynamically change the trigger element or set a trigger that isn't specified via the trigger attribute.

Usage guidelines

  • Use when trigger element is dynamically created or changed
  • Automatically adds click listener to open dialog
  • Replaces any previously set trigger element
  • Useful for programmatic trigger management in dynamic UIs

Accessibility

  • Ensure trigger element has appropriate accessible name
  • Trigger should clearly indicate it will open a dialog
const dialog = document.querySelector('rh-dialog');
const button = document.querySelector('#my-button');
dialog.setTrigger(button);
toggle()

Manually toggles the dialog.

dialog.toggle();
show()

Manually opens the dialog.

dialog.show();
showModal()

Opens the dialog in modal mode.

This method opens the dialog as a modal, which means it appears on top of other content and prevents interaction with the rest of the page until closed. This is the standard way to open a dialog.

Usage guidelines

  • Use for important dialogs requiring user action before continuing
  • Modal dialogs block interaction with underlying content
  • Automatically manages focus and prevents background scrolling
  • Fires an open event when the dialog opens

Accessibility

  • Focus automatically moves to the dialog when opened
  • Background content becomes inert (non-interactive)
  • Users can close with ESC key or by clicking outside (if not prevented)
const dialog = document.querySelector('rh-dialog');
dialog.showModal();
close(returnValue: string)

Manually closes the dialog.

dialog.close();
Events 3
Event Name Description
open

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

close

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

cancel

Fires when a user clicks outside the dialog or hits ESC on their keyboard.

CSS Shadow Parts 7
Part Name Summary Description
dialog

The dialog element

close-button

The dialog's close button

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

body
footer

Actions footer container

CSS Custom Properties 2
CSS Property Description Default
--rh-dialog-close-button-color

Sets the dialog close button color.

var(--rh-color-surface-lightest, #ffffff)
--rh-dialog-video-aspect-ratio 16/9
Design Tokens 20
Token Summary Copy
--rh-color-surface-darker
Full CSS Variable Permalink to this token
--rh-font-family-body-text
Full CSS Variable Permalink to this token
--rh-box-shadow-xl
Full CSS Variable Permalink to this token
--rh-color-text-primary
Full CSS Variable Permalink to this token
--rh-space-3xl
Full CSS Variable Permalink to this token
--rh-font-family-heading
Full CSS Variable Permalink to this token
--rh-font-size-heading-sm
Full CSS Variable Permalink to this token
--rh-font-weight-body-text-regular
Full CSS Variable Permalink to this token
--rh-space-lg
Full CSS Variable Permalink to this token
--rh-space-xl
Full CSS Variable Permalink to this token
--rh-color-icon-secondary
Full CSS Variable Permalink to this token
--rh-color-surface-dark
Full CSS Variable Permalink to this token
--rh-border-radius-default
Full CSS Variable Permalink to this token
--rh-length-xl
Full CSS Variable Permalink to this token
--rh-space-2xl
Full CSS Variable Permalink to this token
--rh-color-gray-90
Full CSS Variable Permalink to this token
--rh-opacity-60
Full CSS Variable Permalink to this token
--rh-space-md
Full CSS Variable Permalink to this token
--rh-space-sm
Full CSS Variable Permalink to this token
--rh-color-surface-lightest
Full CSS Variable Permalink to this token
© 2025 Red Hat Deploys by Netlify