Modal
The <nys-modal> component appears centered on the page and requires the user to interact with it before returning to the main content.
Would you like to install the latest version? Albany ipsum dolor sit Empire, Hudson consectetur Adirondack elit, sed do MetroCard tempor incididunt ut Capitol et Broadway magna Niagara. Ut enim ad Erie veniam, quis nostrud Catskill ullamco Bronx nisi ut LongIsland ex ea consequat.
<nys-button label="Open Modal" onClick="yourOpenModalFunction()"></nys-button>
<nys-modal
id="modal1"
heading="Update Available"
subheading="A new version of this application is ready to install."
>
<p>
Would you like to install the latest version? Albany ipsum dolor sit
Empire, Hudson consectetur Adirondack elit, sed do MetroCard tempor
incididunt ut Capitol et Broadway magna Niagara. Ut enim ad Erie
veniam, quis nostrud Catskill ullamco Bronx nisi ut LongIsland ex ea
consequat.
</p>
<div slot="actions">
<nys-button label="Not now" variant="text" onClick="yourCloseFunction()"></nys-button>
<nys-button label="Update" onClick="yourUpdateFunction()"></nys-button>
</div>
</nys-modal>
Can't use NYS Design System web components in your project? Try using the CSS Variables instead.
Accessibility
The <nys-modal> component includes the following accessibility-focused features:
-
Trap focus inside the modal so keyboard users can’t tab to background content.
-
Return focus to the triggering element when the modal closes.
-
Support keyboard interaction: allow "esc" key to close the modal.
-
Announce the modal to screen readers using role="dialog".
-
Prevent background scroll so users don’t lose context.
Additional accessibility test and build content is coming soon, in a new format.
Options
Slots
The <nys-modal> component provides two slots:
- Default slot -- Body content such as text, forms, or other elements displayed inside the modal.
actions-- Action buttons displayed in the modal footer. Buttons auto-resize on mobile. By convention, place the secondary/cancel button first, followed by the primary/confirm button.
Scrolling Behavior
Avoid content-heavy modals. If the content is too long, consider using a dedicated page or a Stepper.
IMPORTANT: <nys-modal> blocks page scrolling to keep focus within the modal.
Adding basic slots
Use the default slot to add content such as text, links, or other elements inside the modal.
Note: The heading is required for the modal title, while subheading is optional for extra context or instructions.
Please be advised that the system will be unavailable for maintenance from 10 PM Friday to 6 AM Saturday. Ensure you save your work and plan accordingly. For more details, visit the NYS site.
<nys-modal id="modal2" heading="System Maintenance Notice" subheading="Scheduled downtime will occur this weekend.">
<p>
Please be advised that the system will be unavailable for maintenance
from 10 PM Friday to 6 AM Saturday. Ensure you save your work and
plan accordingly. For more details, visit the
<a href="https://www.ny.gov/" target="_blank" rel="noopener noreferrer">NYS site</a>.
</p>
</nys-modal>
Adding action buttons
Control a modal’s visibility with the open (boolean) property on <nys-modal>. Place action buttons (typically <nys-button>) inside the actions slot to close the modal or confirm a task by updating the open property.
Tip: By convention, the secondary/cancel button is usually placed first, followed by the primary/confirm button. This helps maintain consistent UX and accessibility patterns.
<nys-modal id="modal3" heading="Update password?">
<nys-textinput label="Username" name="username" type="text" width="full"></nys-textinput>
<nys-textinput label="Password" name="password" type="password" width="full"></nys-textinput>
<div slot="actions">
<nys-button label="Not now" variant="outline" onClick="yourFunctionHere()"></nys-button>
<nys-button label="Update" onClick="yourFunctionHere()"></nys-button>
</div>
</nys-modal>
Mandatory Action
A forced action modal requires users to make a choice before continuing. Set the mandatory prop, which turns off the dismissible button.
Note: You must provide an action button to allow the user to exit the modal!
<nys-modal
id="modal4"
heading="Your session has expired. 🪡"
subheading="You will need to log in again in order to continue."
mandatory
>
<div slot="actions">
<nys-button label="Login" onClick="yourFunctionHere()"></nys-button>
</div>
</nys-modal>
Usage
Do
- Use to confirm important actions, present focused forms (e.g., login, feedback), or require acknowledgment of alerts without navigating away from the page.
- Keep content short and focused. Use a dedicated page for long or complex content.
- Keep the
subheadingshort and use<p>tags within the modal for longer information. - Use the
mandatoryprop to disable the dismiss button only when the user must make a critical decision or acknowledge essential information.
Don't
- Stack multiple modals.
- Use for trivial information or inline status messages. Use
<nys-alert>instead. - Use for quick hints on form fields. Use
<nys-tooltip>instead. - Force the
mandatoryprop unnecessarily.
Properties
| Property | Type | Default |
|---|---|---|
id |
String | "" |
heading |
String | "" |
subheading |
String | "" |
open |
boolean | false |
mandatory |
boolean | false |
width |
"sm" , "md" , "lg" |
"md" |
Style Overrides
There are no existing CSS variables for this component. Explore existing options, or propose a new one with a Component Proposal.
Events
The <nys-modal> component emits two custom Javascript events:
nys-open– Fired when the modal is opened.nys-close– Fired when the modal is closed.
Event details
The nys-open and nys-close events include a detail object with the following properties:
- id (string): The id of the file input.
You can listen to these events using JavaScript:
Suggest a New Component
Do you have an idea for a new NYS Design System web component? Look through the existing proposals in our GitHub discussions board to see if someone already proposed something similar. If not, feel free to submit one.
Edit this page on GitHub (Permissions required)
Last updated: July 11, 2026