Modal component

The kit:modal component displays an overlay panel above the main content. It is designed for dialogs, contextual messages, forms or alerts requiring direct interaction.

The modal can be centered, fixed at the top or bottom of the screen, and closes in different ways depending on the options activated (outside click, Escape key, etc.). It is a flexible alternative to kit:dialog when you need more control over the structure, behavior or styling of the modal content, or when you want to manage the backdrop at the application level.

modal.svelte

kit:modal is a div-based overlay positioned fixed over the viewport. Unlike kit:dialog, it does not use the native <dialog> element and has no built-in backdrop a global backdrop is typically managed at the application level. Use contain to embed the modal relative to its parent instead.

open is bindable set it to true to open, false to close, or bind it to react to closes.

Examples of modal

position

Controls the vertical alignment of the content panel.

  • position: 'top' | 'center' | 'bottom' = 'center'
modal.svelte

size

Controls the max-width of the content panel. 'full' renders as a bottom sheet spanning the full viewport width.

  • size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full' = 'md'
modal.svelte

persistent

When persistent is set, pressing Escape does not close the modal. The user must interact with the content to dismiss it.

  • persitent: boolean = false
modal.svelte

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

API Reference

kit:modal

propstypedescriptiondefault
openbooleanControls visibility. Bindable.false
persistentbooleanPrevents closing on Escape.false
containbooleanPositions relative to parent instead of viewport.false
closeWithEscbooleanCloses on Escape key.true
sizeenum'xs''sm''md''lg''xl''full'Max-width of the content panel.'md'
positionenum'top''center''bottom'Vertical alignment on the viewport.'center'
densityenum'compact''default''comfortable'Padding inside the content panel.'default'
roundedenum0'xs''sm''md''lg''xl'Border radius of the content panel.'md'
classContentstring | string[]Class(es) applied to the inner content panel.
colorstringForeground color override (--kit-modal-fg).
backgroundstringBackground color override (--kit-modal-bg).
childrenSnippetModal content.

Complement the use of kit:modal with Dialog for confirmations or Popover for light details.