Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>Important Document Renewal Form</h1>

  <p>
    It is important you fill out all steps at once. This form will not save your progress, so be certain you have all the information you need in advance.
  </p>

  <form>
    <h2>Step 14 of 72</h2>
    <p>
      All fields are required.
    </p>
    <div>
      <label for="Fname">First Name:</label>
      <input type="text" id="Fname" value="Adrian">
    </div>
    <div>
      <label for="Lname">Last Name:</label>
      <input type="text" id="Lname" value="Roselli">
      <button type="button" id="PopoverTip01" onclick="OpenFakeDialog(this.id,'DialogClose');" popovertarget="LnameTip" aria-describedby="LnameTip">!</button>
      <p id="LnameTip" popover="manual">
  If your last name is more than one word, please hyphenate it because our developers are unwilling to strip space characters and claim it can "break the database".
</p>
    </div>
    <div>
      <label for="GovID">Government ID type:</label>
      <select id="GovID" aria-describedby="GovIDScare">
        <option value="GovID01">Choose...</option>
        <option value="GovID02">State Driver License</option>
        <option value="GovID03">Passport</option>
        <option value="GovID04">Global Entry</option>
        <option value="GovID05" selected>NEXUS</option>
      </select>
      <button type="button" id="PopoverTip" onclick="openDialog('Dialog01');" popovertarget="GovIDTip" aria-describedby="GovIDTip">!</button>
      <p id="GovIDTip" popover="">
  The document you provide must be scanned at 600dpi full color and stored as a lossless JPG image. Other formats will be deleted.
</p>
      <p id="GovIDScare">
        It is imperative you choose the right document, as doing so could result in your application being denied and probably lost.
      </p>
    </div>
    <div>
      <label for="Reason">Reason for Travel:</label>
      <input type="text" id="Reason" value="">
    </div>
    <div>
      <label for="MName">Maiden Name:</label>
      <input type="text" id="MName" value="">
    </div>
    <div>
      <label for="Alias01">Previous Alias:</label>
      <input type="text" id="Alias01" value="">
    </div>
    <div>
      <label for="Alias02">Preferred Alias:</label>
      <input type="text" id="Alias02" value="">
    </div>
    <div>
      <label for="Alias03">What your mother calls you:</label>
      <input type="text" id="Alias03" value="">
    </div>

  </form>



</main>

<dialog id="Dialog01">
  <form method="dialog">
    <header>
      <button onclick="closeDialog('Dialog01');">Close</button>
      <h2>Running out of time!</h2>
    </header>
    <p>
      You have under one minute before the system logs you out due to inactivity. If you would like to stay logged in, then either start being active or press the button.
    </p>
    <p>
      <button value="Chosen" formmethod="dialog">Extenderize</button>
    </p>
  </form>
</dialog>


<div id="Dialog" aria-labelledby="DialogName" role="dialog" tabindex="-1" hidden>
  <div role="document">
    <!-- For VO bug -->
    <h2 id="DialogName" tabindex="-1">Running out of time!</h2>
    <button type="button" id="DialogClose">Close</button>
    <!-- Need a region role becase this has a tabindex so keyboard users can scroll the box -->
    <!-- Ref: https://adrianroselli.com/2016/02/keyboard-and-overflow.html -->
    <div id="ElementDetail" tabindex="0" role="region" aria-labelledby="DialogName">
    <p>
      You have under one minute before the system logs you out due to inactivity. If you would like to stay logged in, then either start being active or press the button.
    </p>
    <p>
      <button value="Chosen" formmethod="dialog">Extenderize</button>
    </p>
    </div>
  </div>
</div>

<div id="Overlay"></div>
              
            
!

CSS

              
                body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
}

main {
  max-width: 56em;
  margin: 0 auto;
}

h1,
h2,
h3 {
  line-height: 1.1;
}

pre {
  white-space: pre-wrap;
}

:focus {
  outline: .2em solid #00f;
  outline-offset: .1em;
}

/* Dialog styles */

dialog {
  width: 80vw;
  max-width: 50em;
/*   height: 80vh; */
  box-shadow: 0 0 .5em rgba(0,0,0,.75);
/*   border: .1em solid #000; */
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

dialog header > button {
  float: right;
}

dialog header > h2 {
  margin-top: 0;
}

dialog p > button, *[role=dialog] p > button {
  display: block;
  margin: 0 auto;
}

textarea,
input,
select {
  font: inherit;
  letter-spacing: inherit;
  word-spacing: inherit;
}

form label {
  display: block;
  margin: .25em;
}

button[popovertarget] {
  border: .1em solid #00f;
  background-color: #00f;
  font-weight: bold;
  font-size: 125%;
  line-height: 0;
  color: #fff;
  border-radius: 50%;
  display: inline-block;
  width: 1.25em;
  height: 1.25em;
/*   padding: .25em .5em; */
  margin: 0;
}

button[popovertarget]:focus, button[popovertarget]:hover {
  color: #00f;
  background-color: #ff0;
}

*[popover] {
  background: #ff9;
  color: #000;
  padding: .5em 1em;
  max-width: 10em;
  position: absolute;
  border: .1em solid #cc0;
  border-radius: .25em;
  box-shadow: 0 0 .5em #333;
/*   top: 1rem; */
/*   left: 0; */
/*   right: 0; */
/*   margin: 0 auto; */
  left: 3em;
  top: 10em;
}

#LnameTip[popover] {
  top: 0;
  left: 6.25em
}

div:has(*[popover]) {
  position: relative;
}




/*  */


/* Dialog */

#Overlay {
  position: absolute;
  z-index: 150;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0,0,0,.75);
  display: none;
  backdrop-filter: blur(.1em); /* Maybe no */
}

[role="dialog"] {
  position: absolute;
  z-index: 200;
  top: 10vh;
/*   bottom: 10vh; */
  left: 10vw;
  right: 10vw;
/*   max-width: 36rem; */
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
  box-shadow: 0 0 2em rgba(0,0,0,.5);
  background: #fefefe;
  padding: 0;
  visibility: visible;
  width: 80vw;
  max-width: 50em;
  top: 30vh;
}

@media (prefers-reduced-motion: no-preference) {
  [role="dialog"] {
    transition: transform .1s ease-in, opacity .2s ease-in;
  }  
}

[role="dialog"][hidden] {
  display: block;
  visibility: hidden;
  transform: scale(.5);
  opacity: .6;
}

[role="dialog"] h2 {
  margin: .2em;
  padding: .5rem 1.25rem;
  background: #333;
  color: #fefefe;
}

[role="dialog"] h2 + button {
  float: right;
  margin: -2.5rem 1.25rem 0 0;
  padding: 0;
  text-indent: 5em;
  line-height: 0;
  font: inherit;
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 1.5em;
  height: 1.5em;
  overflow: hidden;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 0a50 50 0 1 0 0 100A50 50 0 0 0 50 0zm26.6 76.6a37.5 37.5 0 0 1-53.2 0 37.5 37.5 0 0 1 0-53.2 37.5 37.5 0 0 1 53.2 0 37.5 37.5 0 0 1 0 53.2zm-7.3-45.9a6.6 6.6 0 0 0-9.3 0l-10 10-10-10a6.6 6.6 0 0 0-9.3 9.3l10 10-10 10a6.6 6.6 0 1 0 9.3 9.3l10-10 10 10a6.6 6.6 0 0 0 9.3 0 6.6 6.6 0 0 0 0-9.3l-10-10 10-10a6.6 6.6 0 0 0 0-9.3z' fill='%23fff'/%3E%3C/svg%3E");
  background-size: 100%;
  background-repeat: no-repeat;
  background-position: 50%;
}

[role="dialog"] button:focus, [role="dialog"] button:hover {
/*   outline: .2em solid transparent; */
  background: #fff;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 0a50 50 0 1 0 0 100A50 50 0 0 0 50 0zm26.6 76.6a37.5 37.5 0 0 1-53.2 0 37.5 37.5 0 0 1 0-53.2 37.5 37.5 0 0 1 53.2 0 37.5 37.5 0 0 1 0 53.2zm-7.3-45.9a6.6 6.6 0 0 0-9.3 0l-10 10-10-10a6.6 6.6 0 0 0-9.3 9.3l10 10-10 10a6.6 6.6 0 1 0 9.3 9.3l10-10 10 10a6.6 6.6 0 0 0 9.3 0 6.6 6.6 0 0 0 0-9.3l-10-10 10-10a6.6 6.6 0 0 0 0-9.3z' fill='%23000'/%3E%3C/svg%3E");
  box-shadow: -.1em -.1em 0 rgba(255,255,255,1), .1em -.1em 0 rgba(255,255,255,1), -.1em .1em 0 rgba(255,255,255,1), .1em .1em 0 rgba(255,255,255,1);
}

[role="dialog"] div[role=document] {
  /*  Need this because of a VoiceOver bug  */
  display: inline;
}

[role="dialog"] div[role=document] div {
  box-sizing: border-box;
  height: calc(100% - 3rem);
  overflow: auto;
  padding: .5rem 1.25rem;
}
              
            
!

JS

              
                function openDialog(dlgID) {
  // Get the dialog it controls
  var theDialog = document.getElementById(dlgID);
  // Open the modal
  // theDialog.showModal();
  setTimeout(function () {
    theDialog.showModal();
  }, 2000);
}

function closeDialog(dlgID) {
  // Get the dialog it controls
  var theDialog = document.getElementById(dlgID);
  // Close the modal
  theDialog.close();
}


// 

// Inert polyfill https://github.com/GoogleChrome/inert-polyfill

window.addEventListener("load",function(){function h(a,b,c){if(0>b){if(a.previousElementSibling){for(a=a.previousElementSibling;a.lastElementChild;)a=a.lastElementChild;return a}return a.parentElement}if(a!=c&&a.firstElementChild)return a.firstElementChild;for(;null!=a;){if(a.nextElementSibling)return a.nextElementSibling;a=a.parentElement}return null}function g(a){for(;a&&a!==document.documentElement;){if(a.hasAttribute("inert"))return a;a=a.parentElement}return null}(function(a){var b=document.createElement("style");
b.type="text/css";b.styleSheet?b.styleSheet.cssText=a:b.appendChild(document.createTextNode(a));document.body.appendChild(b)})("/*[inert]*/[inert]{position:relative!important;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;pointer-events:none}[inert]::before{content:'';display:block;position:absolute;top:0;left:0;right:0;bottom:0}");var c=0;document.addEventListener("keydown",function(a){c=9===a.keyCode?a.shiftKey?-1:1:0});document.addEventListener("mousedown",
function(){c=0});document.body.addEventListener("focus",function(a){var b=a.target,f=g(b);if(f){if(document.hasFocus()&&0!==c){var d=document.activeElement,e=new KeyboardEvent("keydown",{keyCode:9,which:9,key:"Tab",code:"Tab",keyIdentifier:"U+0009",shiftKey:!!(0>c),bubbles:!0});Object.defineProperty(e,"keyCode",{value:9});document.activeElement.dispatchEvent(e);if(d!=document.activeElement)return;for(d=f;;){d=h(d,c,f);if(!d)break;a:{e=b;if(!(0>d.tabIndex)&&(d.focus(),document.activeElement!==e)){e=
!0;break a}e=!1}if(e)return}}b.blur();a.preventDefault();a.stopPropagation()}},!0);document.addEventListener("click",function(a){g(a.target)&&(a.preventDefault(),a.stopPropagation())},!0)});

document.onkeydown = function(evt) {
  evt = evt || window.event;
  var isEscape = false;
  if ("key" in evt) {
    isEscape = evt.key == "Escape" || evt.key == "Esc";
  } else {
    isEscape = evt.keyCode == 27;
  }
  if (isEscape) {
    CloseDialog(DialogTrigger);
  }
};

function OpenFakeDialog(btnID,focusID) {
  try {
    setTimeout(function () {
      DialogTrigger = btnID;
      // Get all the elements to manipulate
      var body = document.getElementsByTagName("body");
      var landmarks = document.querySelectorAll("header, main, footer");
      var overlay = document.getElementById("Overlay");  
      var dialog = document.getElementById("Dialog");  
      var closeBtn = document.getElementById("DialogClose");
      var focusElm = document.getElementById(focusID);
      // Hide the content regions from AT
      for (var i = 0; i < landmarks.length; i++) {
        landmarks[i].setAttribute("aria-hidden","true");
        landmarks[i].setAttribute("inert","");
      }
      // Hide the content behind the overlay
      overlay.style.display = "block";
      // Add click handler to overlay
      overlay.setAttribute("onclick","CloseDialog('" + btnID + "');");
      // Kill the page scroll
      body[0].style.overflow = "hidden";
      // Set the dialog to modal
      dialog.setAttribute("aria-modal","true");
      // dialog.setAttribute("data-id",eID);
      dialog.removeAttribute("hidden"); 
      // Put focus on the close button
      // Normally I would put it on the modal, but this fits
      closeBtn.setAttribute("onclick","CloseDialog('" + btnID + "');");
      focusElm.focus();
   }, 2000);
  } catch (e) {
    console.log("OpenDialog(): " + e);
  }
}

function CloseDialog(eID) {
  try {
    // Get all the elements to manipulate
    var body = document.getElementsByTagName("body");
    var landmarks = document.querySelectorAll("header, main, footer");
    var overlay = document.getElementById("Overlay");
    var dialog = document.getElementById("Dialog");
    var triggerBtn = document.getElementById(eID);
    // Make the regions available to AT
    for (var i = 0; i < landmarks.length; i++) {
      landmarks[i].removeAttribute("aria-hidden");
      landmarks[i].removeAttribute("inert");
    }
    // Remove the overlay
    overlay.style.display = "none";
    // Return the scrollbar
    body[0].style.overflow = "auto";
    // Kill the dialog
    dialog.removeAttribute("aria-modal");
    dialog.removeAttribute("data-id");
    dialog.setAttribute("hidden","");
    // Return focus to trigger
    triggerBtn.focus();
  } catch (e) {
    console.log("CloseDialog(): " + e);
  }
}
              
            
!
999px

Console