Skip to content

Technique SCR37:Creating Custom Dialogs


HTML used with script.

This technique relates to 2.4.3: Focus Order (Sufficient when used with Changing a Web page dynamically using one of the following techniques:).


Site designers often want to create dialogs that do not use the pop-up windows supplied by the browser. This is typically accomplished by enclosing the dialog contents in a div and placing the div above the page content using z-index and positioning in CSS.

To be accessible, these dialogs must follow a few simple rules.

  1. Trigger the script that launches the dialog from the onclick event of a link or button.
  2. Place the dialog div into the Document Object Model (DOM) immediately after the element that triggered it. The triggering element will maintain focus, and inserting the dialog content after that element will make the content inside the dialog next in the screen-reader reading order and next in the tab order. The dialog can still be absolutely positioned to be elsewhere on the page visually. This can be done either by creating the dialog in the HTML and hiding it with CSS, as in the example below, or by inserting it immediately after the triggering element with script.
  3. Ensure that the HTML inside the dialog div meets the same accessibility standard as other content.

It is also nice, but not always necessary, to make the launching link toggle the dialog open and closed, and to close the dialog when the keyboard focus leaves it.


Example 1: An options button that opens a dialog

The HTML for this example includes a triggering element, in this case a button, and a div that acts as the frame for the dialog.

The triggering element is a button and the script is triggered from the onclick event. This sends the appropriate events to the operating system so that assistive technology is aware of the change in the DOM.

In this example, the Submit and Reset buttons inside the dialog simply hide the div.


<button onclick="TogglePopup(event,true)" name="pop0001">Options</button>

<div class="popover" id="pop0001">
  <h3>Edit Sort Information</h3>
  <form action="default.htm" onsubmit="'none';
   return false;" onreset="'none'; return false;">
      <legend>Sort Order</legend> 
      <input type="radio" name="order" id="order_alpha">
      <label for="order_alpha">Alphabetical</label>
      <input type="radio" name="order" id="order_default" checked="true">
      <label for="order_default">Default</label>
    <div class="buttons">
      <input type="submit" value="OK">
      <input type="reset" value="Cancel">


The div, heading and form elements are styled with CSS to look like a dialog.

a {

a.clickPopup img {
  border:none; width:0;
div.popover {
  border:1px outset;

div.popover h3 {
  padding:0.1em 0.5em;

#pop0001 {

#pop0001 form {

#pop0001 fieldset {

#pop0001 input, #pop0001 label {

#pop0001 div.buttons {

#pop0001 div.buttons input {

The JavaScript

The script toggles the display of the popup div, showing it and hiding it.

function TogglePopup(evt,show) {
  var src =;
  if ("click" == evt.type) {
    evt.returnValue = false;
  var popID = src.getAttribute("name");
  if (popID) {
    var popup = document.getElementById(popID);
    if (popup) {
      if (true == show) { = "block";
      else if (false == show) { = "none";
      else { = "block" == ? "none" : "block";
      if ("block" == { = ((document.documentElement.offsetHeight - popup.offsetHeight) / 2 ) + 'px'; = ((document.documentElement.offsetWidth - popup.offsetWidth) / 2) + 'px';

function SubmitForm(elem) {'none'; 
  return false;
function ResetForm(elem) {'none'; 
  return false;

A working example, an options button that opens a dialog, is available.

Other sources

No endorsement implied.



  1. Find all areas of the page that trigger dialogs that are not pop-up windows.
  2. Check that the dialogs can be opened by tabbing to the area and hitting enter.
  3. Check that, once opened, the dialog is next in the tab order.
  4. Check that the dialogs are triggered from the click event of a button or a link.
  5. Using a tool that allows you to inspect the DOM generated by script, check that the dialog is next in the DOM.

Expected Results

  • Checks #2, #3, #4 and #5 are true.
Back to Top