jQuery UI Dialog

The jQuery UI dialog() widget turns a plain, hidden <div> into a draggable, resizable popup window - perfect for confirmations, alerts, and small forms - either modal (blocking the rest of the page) or non-modal (a floating window the user can ignore).

1) Basic Dialog


<!-- markup: any hidden div works as the dialog's content -->
<div id="dialog" title="Basic dialog">
  <p>This is the dialog's content.</p>
</div>

$('#dialog').dialog(); // jQuery UI shows it as a floating popup immediately

2) autoOpen: false - open it later on demand


// don't pop up on page load; wait for the widget's .dialog('open') call
$('#dialog').dialog({
  autoOpen: false
});

// show it later, e.g. from a button click
$('#openBtn').on('click', function(){
  $('#dialog').dialog('open');
});
Tip: On a tutorial or landing page, always pair dialog() with autoOpen: false. A popup that appears the instant the page loads is jarring for visitors.

3) modal: true


// a semi-transparent overlay blocks clicks on the rest of the page
// until the dialog is closed
$('#dialog').dialog({
  autoOpen: false,
  modal: true
});

4) The buttons option


$('#dialog').dialog({
  autoOpen: false,
  modal: true,
  buttons: {
    "OK": function(){
      $(this).dialog('close');
    },
    "Cancel": function(){
      $(this).dialog('close');
    }
  }
});

5) Sizing with width / height


$('#dialog').dialog({
  autoOpen: false,
  width: 400,
  height: 250
});

6) open / close events


$('#dialog').dialog({
  autoOpen: false,
  open: function(event, ui){
    console.log('dialog opened');
  },
  close: function(event, ui){
    console.log('dialog closed');
  }
});

Live Demo

Click the button below to open a real, working modal dialog. It won't appear on page load - only when you ask for it, which is the recommended pattern for tutorial and landing pages.

Heads up: A modal dialog's overlay can visually sit behind fixed page chrome (a fixed sidebar, sticky ads) unless you raise its z-index. This page overrides .ui-dialog and .ui-widget-overlay to z-index: 2000 so the demo above always stays on top.