Create modal dialogs with different styles and transitions.


Create modal dialogs with different styles and transitions.


The Modal component consists of an overlay, a dialog and an optional close button. You can use any element to toggle a modal dialog. To enable the necessary JavaScript, add the uk-toggle attribute. An <a> element needs to be linked to the modal’s id. If you are using another element, like a button, just add the uk-toggle="target: #ID" attribute to target the id of the modal container.

Add the uk-modal attribute to a <div> element to create the modal container and an overlay that blanks out the page. It is important to add an id to indicate the element for toggling. Use the following classes to define the modal’s sections.

.uk-modal-dialogAdd this class to a child <div> element to create the dialog
.uk-modal-bodyAdd this class to create padding between the modal and its content.
.uk-modal-titleAdd this class to a heading element to create the modal title.
.uk-modal-closeAdd this class to an <a> or <button> element to create a close button and enable its functionality.
<!-- This is a button toggling the modal -->
<button uk-toggle="target: #my-id" type="button"></button>

<!-- This is the modal -->
<div id="my-id" uk-modal>
    <div class="uk-modal-dialog uk-modal-body">
        <h2 class="uk-modal-title"></h2>
        <button class="uk-modal-close" type="button"></button>

Close button

To create a close button, enable its functionality and add proper styling and positioning, add the .uk-modal-close-default class to an <a> or <button> element. To place the close button outside the modal, add the .uk-modal-close-outside class.

Add the uk-close attribute from the Close component, to apply a close icon.

    <div class="uk-modal-dialog">
        <button class="uk-modal-close-default" type="button" uk-close></button>

    <div class="uk-modal-dialog">
        <button class="uk-modal-close-outside" type="button" uk-close></button>

Center modal

To vertically center the modal dialog, you can use the .uk-margin-auto-vertical class from the Margin component.

<div class="uk-flex-top" uk-modal>
    <div class="uk-modal-dialog uk-margin-auto-vertical"></div>

Note .uk-flex-top on the modal container is needed to support IE 11.

To divide the modal into different content sections, use the following classes.

.uk-modal-headerAdd this class to a <div> element to create the modal header.
.uk-modal-footerAdd this class to a <div> element to create the modal footer.
<div uk-modal>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-default" type="button" uk-close></button>
        <div class="uk-modal-header">
            <h2 class="uk-modal-title"></h2>
        <div class="uk-modal-body"></div>
        <div class="uk-modal-footer"></div>

Container modifier

Add the .uk-modal-container class to expand the modal dialog to the default Container width.

<div class="uk-modal-container" uk-modal></div>

Full modifier

To create a modal, that fills the entire page, add the .uk-modal-full class. It is also recommended adding the .uk-modal-close-full class to the close button, so that it adapts its styling.

<div class="uk-modal-full" uk-modal>
    <div class="uk-modal-dialog">
        <button class="uk-modal-close-full uk-close-large" type="button" uk-close></button>

Using the grid and width classes, you can create a nice, split fullscreen modal.


By default, the page will scroll with the modal, if its content exceeds the window height. To apply a scrollbar inside the modal, add the uk-overflow-auto attribute from the Utility component to the modal body.

<div uk-modal>
    <div class="uk-modal-dialog" uk-overflow-auto></div>


If you want to display media, you should first check, if the Lightbox component doesn’t already offer everything you need. However, you can also use the modal to have more control over the markup to wrap your media in.

Note Use the uk-video attribute from the Video component to make sure videos are stopped when the modal is closed.

<div uk-modal>
    <div class="uk-modal-dialog uk-width-auto">
        <iframe src="" uk-video></iframe>


You can group multiple modals by linking from one to the other and back. Use this to create multistep wizards inside your modals.

<div id="modal-group-1" uk-modal>
    <div class="uk-modal-dialog">
        <a href="#modal-group-2" uk-toggle>Next</a>

<div id="modal-group-2" uk-modal>
    <div class="uk-modal-dialog">
        <a href="#modal-group-1" uk-toggle>Previous</a>

Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

esc-closeBooleantrueClose the modal when the Esc key is pressed.
bg-closeBooleantrueClose the modal when the background is clicked.
stackBooleanfalseStack modals, when more than one is open. By default, the previous modal will be hidden.
containerStringtrueDefine a target container via a selector to specify where the modal should be appended in the DOM. Setting it to false will prevent this behavior.
cls-pageString'uk-modal-page'Class to add to <html> when modal is active
cls-panelString'uk-modal-dialog'Class of the element to be considered the panel of the modal
sel-closeString'.uk-modal-close, .uk-modal-close-default, .uk-modal-close-outside, .uk-modal-close-full'CSS selector for all elements that should trigger the closing of the modal


Learn more about JavaScript components.


UIkit.modal(element, options);


The following events will be triggered on elements with this component attached:

beforeshowFires before an item is shown.
showFires after an item is shown.
shownFires after the item’s show animation has completed.
beforehideFires before an item is hidden.
hideFires after an item’s hide animation has started.
hiddenFires after an item is hidden.


The following methods are available for the component:



Shows the Modal.



Hides the Modal.

The component comes with a number of prepared modal dialogs that you can use for user interaction. You can call the dialog directly from JavaScript and use callback functions to process the user input.

UIkit.modal.alert('UIkit alert!')Show an alert box with one button.
UIkit.modal.confirm('UIkit confirm!')Show a confirm dialog with your message and two buttons.
UIkit.modal.prompt('Name:', 'Your name')Show a dialog asking for a text input.
UIkit.modal.dialog('<p>UIkit dialog!</p>');Show dialog with any HTML content.

To process the user input, the modal uses a promise based interface which provides a then() function to register your callback functions. The UIkit.modal.dialog function however will return the modal itself.

UIkit.modal.confirm('UIkit confirm!').then(function() {
}, function () {

The returned promise has a property dialog, which holds a reference to the modal itself. This lets you manipulate e.g. the markup of the modal’s element.

const modal = UIkit.modal.confirm('UIkit confirm!').dialog; // The modal component
const el = modal.$el; // The modal element