Modal component is used to display content that temporarily blocks interactions with the main view of an application. Modal should be used sparingly and only when necessary.
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
Open in new window
View RTL
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"size="s"openaria-labelledby="title"><h2slot="header"id="title">Modal title</h2><pclass="n-reset">Modal body text goes here.</p><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandid="cancelButton">Cancel</nord-button><nord-buttonexpandid="confirmButton"variant="primary"autofocus>Save changes</nord-button></nord-button-group></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal()) cancelButton.addEventListener("click",()=> modal.close()) confirmButton.addEventListener("click",()=> modal.close())</script>
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"aria-labelledby="title"size="s"open><h2slot="header"id="title">Delete patient?</h2><formmethod="dialog"id="myForm"><pclass="n-reset">All information you have entered will be deleted.</p></form><nord-stackslot="footer"direction="horizontal"align-items="center"gap="s"><nord-stackstyle="flex: 1"direction="horizontal"gap="s"align-items="center"><nord-iconname="interface-warning"></nord-icon><p>This cannot be undone</p></nord-stack><nord-button-groupvariant="spaced"><nord-buttonform="myForm">Cancel</nord-button><nord-buttonform="myForm"variant="danger"autofocus>Delete</nord-button></nord-button-group></nord-stack></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal())</script>
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"size="s"openaria-labelledby="title"><h2slot="header"id="title">Discard changes?</h2><pclass="n-reset">All information you have entered will be deleted.</p><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandid="cancelButton">Cancel</nord-button><nord-buttonexpandid="confirmButton"variant="danger"autofocus>Discard</nord-button></nord-button-group></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal()) cancelButton.addEventListener("click",()=> modal.close()) confirmButton.addEventListener("click",()=> modal.close())</script>
<nord-buttonid="trigger"variant="primary">Open modal</nord-button><nord-modalid="modal"openaria-labelledby="title"><h2slot="header"id="title">Give us feedback</h2><formmethod="dialog"id="myForm"><nord-stack><nord-selectautofocusexpandname="input-1"label="How would you describe the interface?"placeholder="Pick an option"><optionvalue="1">Something is missing</option><optionvalue="2">I’m confused or surprised</option><optionvalue="3">It’s missing a feature</option><optionvalue="4">It’s broken</option><optionvalue="5">Something else</option></nord-select><nord-textareaexpandlabel="Is there anything else you'd like to add?"hint="(Optional)"placeholder="Ex. I had an idea…"name="input-2"></nord-textarea><p><strong>Note:</strong> some additional information may be included, including your email address. If you’re looking to send feedback unrelated to this interface, email us.</p></nord-stack></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="myForm"value="cancel">Cancel</nord-button><nord-buttonexpandform="myForm"type="submit"value="add"variant="primary">Submit</nord-button></nord-button-group></nord-modal><divclass="n-margin-bs-m"><outputid="output"></output><preid="values"></pre></div><script> trigger.addEventListener("click",e=> modal.showModal()) myForm.addEventListener("submit",e=>{ values.innerText =JSON.stringify(Object.fromEntries(newFormData(e.target)),null,2)}) modal.addEventListener("close",e=>{ output.innerHTML =`Modal <code>returnValue</code>: <code>${modal.returnValue}</code>`})</script>
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"openaria-labelledby="title"><h2slot="header"id="title">Using the "dialog" method for forms</h2><formid="myForm"method="dialog"class="n-reset n-typeset"><p> If you set a form's method to <code>"dialog"</code>, a modal can be dismissed by submitting that form. This is convenient as it requires no additional javascript.</p><p> When the form is submitted, the modal's <code>returnValue</code> is set to the <code>value</code> of the submit button that was clicked.</p><p> A button can be associated with a form, by setting the button's <code>form</code> attribute to the form's<code>id</code>.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonform="myForm"expandvalue="cancel">Cancel</nord-button><nord-buttonform="myForm"expandvalue="yes"variant="primary"autofocus>Save</nord-button></nord-button-group></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal()) modal.addEventListener("close",()=>{ console.log(modal.returnValue)})</script>
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"openaria-labelledby="title"><h2slot="header"id="title">Managing focus in modals</h2><formid="form"method="dialog"class="n-reset n-typeset"><p> Add the <code>autofocus</code> attribute to any interactive element within the modal, to have it automatically focus whenever the modal is opened.</p><p>In this example the attribute has been added to the Submit element</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonform="form"expand>Cancel</nord-button><nord-buttonform="form"expandvariant="primary"autofocus>Submit</nord-button></nord-button-group></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal())</script>
<nord-buttonid="trigger"variant="primary">Open modal</nord-button><nord-modalid="modal"openaria-labelledby="title"><h2slot="header"id="title">Give us feedback</h2><divclass="n-typeset n-margin-be-m"><p> This example demonstrates how to use multiple modals to get confirmation from a user before discarding their work. If you attempt to close this modal via the close button, pressing the <kbd>Esc</kbd> key, or clicking outside the modal, a second modal will be shown asking you to confirm your action.</p><p> The first modal can only be closed by submitting its form or by confirming you want to discard your work in the second modal.</p></div><formmethod="dialog"id="myForm"><nord-textareaexpandlabel="Your message"value="Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti, iure?"></nord-textarea></form><nord-buttonslot="footer"expandform="myForm"type="submit"variant="primary">Submit feedback</nord-button></nord-modal><nord-modalid="confirmModal"size="s"aria-labelledby="confirm-title"><h2slot="header"id="confirm-title">Discard changes?</h2><pclass="n-reset">All information you have entered will be deleted.</p><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandid="cancelButton">Cancel</nord-button><nord-buttonexpandid="confirmButton"variant="danger"autofocus>Discard</nord-button></nord-button-group></nord-modal><script>const modal = document.querySelector("#modal")const confirmModal = document.querySelector("#confirmModal") trigger.addEventListener("click",e=> modal.showModal()) modal.addEventListener("cancel",e=>{ e.preventDefault() confirmModal.showModal()}) cancelButton.addEventListener("click",()=>{ confirmModal.close()}) confirmButton.addEventListener("click",()=>{ confirmModal.close() modal.close()})</script>
<nord-buttonvariant="primary"id="openButton">Open modal</nord-button><nord-modalid="modal"size="s"openaria-labelledby="title"><h2slot="header"id="title">Preventing close</h2><formmethod="dialog"id="myForm"><nord-stack><p> When a user hits Escape key, clicks the close button, or clicks outside, the modal emits a<code>cancel</code> event.</p><p>If <code>preventDefault()</code> is called on the cancel event, then the modal will not close.</p><nord-checkboxautofocusid="checkbox"label="Prevent close?"></nord-checkbox></nord-stack></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="myForm">Cancel</nord-button><nord-buttonexpandform="myForm"variant="primary">Submit</nord-button></nord-button-group></nord-modal><script> openButton.addEventListener("click",e=> modal.showModal()) modal.addEventListener("cancel",e=>{if(checkbox.checked){ console.log("preventing close") e.preventDefault()}}) modal.addEventListener("close",e=>{ console.log("modal closed")})</script>
<nord-button-groupvariant="spaced"wrap><nord-buttonid="outerButton"variant="primary">Scroll externally</nord-button><nord-buttonid="innerButton"variant="primary">Scroll internally</nord-button></nord-button-group><nord-modalid="outerModal"aria-labelledby="outerHeader"><h2slot="header"id="outerHeader">Scroll externally</h2><formmethod="dialog"id="outerForm"class="n-typeset n-margin-be-m"><p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p><divstyle="height: 80vh"></div><p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis tenetur amet temporibus nulla? Quisquam, quaerat sed! Assumenda itaque dolor ratione id voluptatum, excepturi eius voluptas iste facilis ut, quas minus.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonform="outerForm"expandvalue="cancel">Cancel</nord-button><nord-buttonform="outerForm"expandvariant="primary"value="accept">Accept terms</nord-button></nord-button-group></nord-modal><nord-modalid="innerModal"aria-labelledby="innerHeader"scrollable><h2slot="header"id="innerHeader">Scroll internally</h2><formmethod="dialog"id="innerForm"class="n-typeset n-margin-be-m"><p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p><divstyle="height: 80vh"></div><p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis tenetur amet temporibus nulla? Quisquam, quaerat sed! Assumenda itaque dolor ratione id voluptatum, excepturi eius voluptas iste facilis ut, quas minus.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonform="innerForm"expandvalue="cancel">Cancel</nord-button><nord-buttonform="innerForm"expandvariant="primary"value="accept">Accept terms</nord-button></nord-button-group></nord-modal><script> outerButton.addEventListener("click",()=> outerModal.showModal()) innerButton.addEventListener("click",()=> innerModal.showModal())</script>
<nord-button-groupvariant="spaced"wrap><nord-buttonid="buttonSmall"variant="primary">Open small modal</nord-button><nord-buttonid="buttonMedium"variant="primary">Open medium modal</nord-button><nord-buttonid="buttonLarge"variant="primary">Open large modal</nord-button><nord-buttonid="buttonExtraLarge"variant="primary">Open extra large modal</nord-button></nord-button-group><nord-modalid="modalSmall"size="s"aria-labelledby="smallHeader"><h2id="smallHeader"slot="header">Small modal</h2><formmethod="dialog"id="smallForm"class="n-reset"><p>Small modals are best used for confirmation dialogs.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="smallForm">Cancel</nord-button><nord-buttonexpandform="smallForm"variant="primary"autofocus>Save</nord-button></nord-button-group></nord-modal><nord-modalid="modalMedium"size="m"aria-labelledby="mediumHeader"><h2id="mediumHeader"slot="header">Medium modal</h2><formmethod="dialog"id="mediumForm"class="n-reset"><p>Medium is the default size, and is suitable for most use cases.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="mediumForm">Cancel</nord-button><nord-buttonexpandform="mediumForm"variant="primary"autofocus>Save</nord-button></nord-button-group></nord-modal><nord-modalid="modalLarge"size="l"aria-labelledby="largeHeader"><h2id="largeHeader"slot="header">Large modal</h2><formmethod="dialog"id="largeForm"class="n-reset n-typeset"><p>Large modals are best suited for complex forms which require lots of space.</p><p>When using large modals, please ensure the layout continues to work in narrow viewports.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="largeForm">Cancel</nord-button><nord-buttonexpandform="largeForm"variant="primary"autofocus>Save</nord-button></nord-button-group></nord-modal><nord-modalid="modalExtraLarge"size="xl"aria-labelledby="extraLargeHeader"><h2id="extralargeHeader"slot="header">Extra large modal</h2><formmethod="dialog"id="extraLargeForm"class="n-reset n-typeset"><p>Extra large modals are best suited for when you need to fill the full width of the viewport.</p><p>When using extra large modals, please ensure the layout continues to work in narrow viewports.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonexpandform="extraLargeForm">Cancel</nord-button><nord-buttonexpandform="extraLargeForm"variant="primary"autofocus>Save</nord-button></nord-button-group></nord-modal><script> buttonSmall.addEventListener("click",()=> modalSmall.showModal()) buttonMedium.addEventListener("click",()=> modalMedium.showModal()) buttonLarge.addEventListener("click",()=> modalLarge.showModal()) buttonExtraLarge.addEventListener("click",()=> modalExtraLarge.showModal())</script>
<nord-buttonid="trigger"variant="primary">Open modal</nord-button><nord-modalid="modal"aria-labelledby="heading"openclass="n-typeset"scrollable><h2slot="header"id="heading">Terms & agreements</h2><formmethod="dialog"id="termsForm"><h3class="n-typescale-l"style="margin-block-start: 0"> Lorem ipsum dolor, sit amet consectetur adipisicing elit</h3><p> Lorem ipsum dolor sit amet, consectetur adipiscing 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.</p><p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis tenetur amet temporibus nulla? Quisquam, quaerat sed! Assumenda itaque dolor ratione id voluptatum, excepturi eius voluptas iste facilis ut, quas minus.</p><h3class="n-typescale-l">Lorem ipsum dolor sit</h3><p> Lorem ipsum dolor sit amet, consectetur adipiscing 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.</p><h3class="n-typescale-l">Lorem ipsum dolor sit amet consectetur</h3><p> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Aliquid repellat nam dolorum ab? Optio ex facere commodi aspernatur, laboriosam labore dicta totam ab repudiandae ullam quibusdam soluta odio, quis possimus.</p><h3class="n-typescale-l">Consectetur adipiscing elit</h3><p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Deserunt amet eaque corrupti alias sint tempora dolorum, incidunt fugit architecto veritatis, eum id nulla doloribus aut numquam earum natus vero repellat.</p><p> Lorem ipsum dolor sit amet consectetur adipisicing elit. Ratione rem officia hic odit laboriosam sed temporibus amet reprehenderit quod. Natus sit quia veniam accusantium officiis minus, deleniti a ipsam quisquam.</p><p> Lorem ipsum dolor sit amet consectetur, adipisicing elit. Fugit voluptas aperiam sit facilis excepturi hic ad iusto magni vel. Exercitationem iusto dolor placeat quisquam eaque cumque at incidunt, officia doloremque in earum nobis perspiciatis quo mollitia. Debitis eum fuga, excepturi quo dicta, deserunt ea quidem et, perspiciatis necessitatibus veritatis autem.</p></form><nord-button-groupslot="footer"variant="spaced"><nord-buttonform="termsForm"expandvalue="cancel">Cancel</nord-button><nord-buttonform="termsForm"expandvariant="primary"autofocusvalue="accept">Accept terms</nord-button></nord-button-group></nord-modal><script> trigger.addEventListener("click",e=> modal.showModal())</script>
Properties
Property
Attribute
Description
Type
Default
open
open
Controls whether the modal is open or not.
boolean
false
size
size
Controls the max-width of the modal when open.
"s" | "m" | "l" | "xl"
"m"
returnValue
–
The reason why the modal was closed. This typically indicates which button the user pressed to close the modal, though any value can be supplied if the modal is programmatically closed.
string
""
scrollable
scrollable
By default if a modal is too big for the browser window, the entire modal will scroll. This setting changes that behavior so that the body of the modal scrolls instead, with the modal itself remaining fixed.
boolean
false
Events
Event
Description
Type
close
Dispatched when a modal is closed for any reason.
NordEvent
cancel
Dispatched before the modal has closed when a user attempts to dismiss a modal. Call preventDefault() on the event to prevent the modal closing.
NordEvent
Slots
Slot name
Description
Default slot
Default slot
header
Slot which holds the header of the modal, positioned next to the close button.
footer
Slot which is typically used to hold call to action buttons, but can also be used to build custom footers.
Methods
Method name
Parameters
Description
showModal() => void
N/A
Show the modal, automatically moving focus to the modal or a child element with an autofocus attribute.
close(returnValue?: string) => void
returnValue: An optional value to indicate why the modal was closed.
Programmatically close the modal.
focus(options?: FocusOptions) => void
options: An object which controls aspects of the focusing process.
Programmatically focus the modal.
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
Property
Description
Default
--n-modal-padding-inline
Controls the padding on the sides of the modal, using our spacing tokens.
var(--n-space-m)
--n-modal-padding-block
Controls the padding above and below the modal, using our spacing tokens.
var(--n-space-m)
--n-modal-max-inline-size
Controls the width of the modal.
620px
Localization
This component requires localization in a multi-lingual application. The following keys are required when registering a translation:
Modal title should be clear, accurate and predictable. Always lead with a strong verb that encourages action. To provide enough context to user, use the {verb} + {noun} content formula:
Edit patient
Edit the patient called John Doe
Discard changes?
Discard?
Delete patient?
Are you sure you want to delete this patent?
When writing modal titles, always write them in sentence case, not title case. The first word should be capitalized and the rest lowercase (unless a proper noun):
New appointment
New Appointment
Avoid unnecessary words and articles in modal titles, such as “the”, “an” or “a”:
Use the autofocus attribute to set the initial focus to the first location that accepts user input.
If it is a transactional modal without form inputs, then autofocus should be set on the primary button in the modal footer. This is for efficiency since most users will simply dismiss the dialog as soon as they have read the message.
If the modal contains a form, use autofocus in the first form field.
Focus remains trapped inside the modal dialog until it is closed.
For integration guidelines, please see Web Components documentation. This documentation explains how to implement and use Nord Web Components across different technologies such as Vue.js, React, or Vanilla JavaScript.
Integration Guidelines
Troubleshooting
If you experience any issues while using Nord Web Components, please head over to the Support page for more guidelines and ways to contact us.