Skip to content

Modal

Last updated 11 Nov 2026

NbModal is a dialog overlay: a surface that sits above the page, takes the whole screen out of play until it is answered, and hands the user back where they were. It uses <Teleport> to render at the body level, so its stacking is correct no matter how deep in the tree it is written.

It is one of exactly two dialogs the library ships. The other is NbConfirm, and it is the only shape a destructive confirmation may take. If you are about to build a confirmation out of NbModal, stop and read When not to use.

Do not assemble a destructive confirmation from NbModal

A hand-built confirmation tends to look like this: variant="primary" on a Confirm button, a title-case "Confirm Action" heading, the body "Are you sure you want to continue?", and an NbPanel with inline padding inside #footer fighting the right-aligned grid Modal.vue already puts there. Every part of that is wrong.

The fix is not a better footer. It is useConfirm(). What this page covers is the footer contract, which every other dialog needs.

vue
<template>
  <NbButton @click="open = true">Rename workspace</NbButton>
  <NbModal :open="open" @close="open = false">
    <template #header>Rename workspace</template>
    <NbTextInput v-model="name" label="Name" />
    <template #footer>
      <NbButton variant="secondary" @click="open = false">Cancel</NbButton>
      <NbButton variant="primary" @click="rename">Rename</NbButton>
    </template>
  </NbModal>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const open = ref(false)
const name = ref('')
</script>

Anatomy ​

Seven parts, and every rule further down this page is about one of them. The class names are the ones Modal.vue actually renders, so they are also what you will find in a screenshot, a DOM inspector or a failing snapshot.

#PartClassComes fromWhat it is for
1Scrim.nb-modal--overlayThe componentFills the viewport with --nb-c-scrim, holds the 20px margin every size keeps, and emits close on a click unless closeOnOverlay is off
2Dialog box.nb-modal--contentThe componentrole="dialog" (or alertdialog), aria-modal="true", tabindex="-1". Also carries .nb-modal--content--{size}, which is where the caps live
3Header.nb-modal--headertitle or #headerRendered only when one of the two is given. Without it the dialog has no accessible name and no close control
4Title.nb-modal--titletitle or #headerCarries the generated id the dialog is aria-labelledby-ed to, unless you override it with labelledBy
5Close control.nb-modal--closeThe componentNbCloseButton at lg, 48px, in the top right corner and last in the tab order. Present when there is a header, disabled by closeDisabled
6Body.nb-modal--bodyThe default slotThe only scrolling region. Becomes a labelled, focusable role="region" while it overflows
7Footer.nb-modal--footer#footerA fluid NbButtonSet of xl buttons, rendered only when the slot has content. It is an action bar already, see below

Two of those are not yours to build. The header lays out its own title and X, and the footer is already a button set, so anything you put inside either one is a child of an existing layout rather than the start of a new one. That is the single most common way this component is misused.

When to use ​

A dialog costs the user everything else on the screen. It is worth that when the task is short, is about the thing behind it, and has an end. Four cases pass that test.

A short edit that belongs to what is behind it ​

Renaming a record, moving it, changing its four settings, inviting one person. The user is looking at the object and wants to change something about it without losing sight of where it sits in the list. Up to four inputs is the working ceiling; past that, see the first row of When not to use.

A choice from a set too large for a menu ​

Picking an icon, a template, a target project, a file from a browser. A menu of eight is a menu. A searchable, filterable, scrollable set of eighty is a task, and a task with a cancel needs a surface with a cancel.

A detail that has to be read against its context ​

A run's log, a diff, a version's contents, side by side comparison. The page behind is the reason the detail makes sense, so a route that replaces it costs more than a dialog that covers it. size="immersive" exists for exactly this (see Sizes).

A step that has to be finished or abandoned before anything else moves ​

A two-factor challenge, a required credential before an import, a mandatory field a bulk action needs. The interruption is the point: the workflow genuinely cannot continue in either direction until this is answered.

The test, in one line

The user opened it, it fits on one screen, and answering it (either way) is the end of it. If any of those three is false, one of the surfaces below is the right one.

The four dialog shapes ​

NbModal has one visual variant and five sizes, so the taxonomy that matters here is not a look, it is a dismissal contract: how the user gets out, and what the footer must contain for that to be honest. Pick the row first, then the size.

ShapeWhat it isWays outFooterBuild it with
ConfirmationAn irreversible or expensive act, answered yes or noEsc, Cancel, scrim, X. All four mean no. None mean yesCancel, then a variant="danger" commituseConfirm(), never NbModal
FormA short edit that ends in a commitSame four, but a dirty form asks before discardingCancel, then a variant="primary" commitNbModal plus the validation rules
DetailSomething to read, compare or copy from, that changes nothingSame four, all identical, all harmlessOne Close, or no footer at allNbModal, usually lg, xl or immersive
Blocking stepThe workflow cannot continue in either direction until this is answeredOnly the footer, and only when abandoning truly is impossibleAn explicit exit and an explicit commitNbModal with :close-on-overlay="false"

Two rules hold across all four.

Every dialog has an exit, and it is visible. A blocking step is the only shape allowed to switch off the scrim and Esc, and the price of switching them off is that the footer must then carry the way out in words ("Sign out", "Cancel import"). A dialog with no Esc, no scrim dismissal and no exit button is a trap, and it is what closeDisabled produces if you set it and forget it, because it silently disables the Esc route too (see Work in flight).

A dialog with nothing to decide is not a dialog. If the user's only possible answer is "fine", the message is news: useToast() for a moment, NbBanner for a condition. An OK-only dialog is an interruption that charges a click for nothing.

Content ​

The words in a dialog carry more weight than anywhere else in the product, because the user cannot look anything up while it is open.

  • The title names the action, in sentence case. "Rename workspace", "Delete environment", "Choose a template". Not "Confirm Action", not "Are you sure?", not "Warning".
  • The body says what will happen and to what. One sentence, present tense, naming the record: "Every entry, release and API key in production is deleted." A body that only restates the title is noise the user learns to skip.
  • The buttons say the verb. The commit repeats the title's verb, the exit is "Cancel". OK, Yes, Done and Dismiss say nothing about what is about to happen, so none of them belong on a commit button.
  • Do not use a dialog to apologise. "Something went wrong" in a dialog is a failure the user must dismiss before they can look at the thing that failed. Put it in place, in an inline banner.

Tone, capitalisation and sentence shape are set library-wide, not by this component: Writing style is the source.