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

              
                <h1>dialog focus test</h2>

<h2>Dialog with no interactive element</h2>

<button>demo 1</button>

<dialog>
  <h1>Demo 1</h2>
</dialog>

<h2>Dialog with interactive elements</h2>

<button>demo 2</button>

<dialog>
  <h1>Demo 2</h2>
  
  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>

<h2>Dialog with interactive elements and close button</h2>

<button>demo 3</button>

<dialog>
  <form method="dialog">
    <button>close</button>
  </form>
  
  <h1>Demo 3</h2>
  
  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>

<h2>Dialog with interactive elements and close button</h2>

<button>demo 4</button>

<dialog>
  <h1>Demo 4</h2>
  
  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
  
  <form method="dialog">
    <button>close</button>
  </form>
</dialog>

<h2>Dialog without interactive elements and autofocus on dialog</h2>

<button>demo 5</button>

<dialog autofocus>
  <h1>Demo 5</h2>
</dialog>


<h2>Dialog with interactive elements and autofocus on dialog</h2>

<button>demo 6</button>

<dialog autofocus>
  <h1>Demo 6</h2>
 
  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>

<h2>Dialog with autofocus on last interactive element</h2>

<button>demo 7</button>

<dialog>
  <h1>Demo 7</h2>
 
  <button>First focusable element</button>
  <a href="#" autofocus>Last focusable element</a>
</dialog>

<h2>Dialog with tabindex and no interactive element</h2>

<button>demo 8</button>

<dialog tabindex="-1">
  <h1>Demo 8</h2>
</dialog>

<h2>Dialog with tabindex and interactive elements</h2>

<button>demo 9</button>

<dialog tabindex="-1">
  <h1>Demo 9</h2>

  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>


<h2>Dialog with tabindex, autofocus, and interactive elements</h2>

<button>demo 10</button>

<dialog tabindex="-1" autofocus>
  <h1>Demo 10</h2>

  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>

<h2>Dialog with tabindex, focus(), and interactive elements</h2>

<button class="focus">demo 11</button>

<dialog tabindex="-1">
  <h1>Demo 11</h2>

  <button>First focusable element</button>
  <a href="#">Last focusable element</a>
</dialog>
              
            
!

CSS

              
                :focus {
  outline: 5px solid hotpink;
}
              
            
!

JS

              
                document.addEventListener('click', e => {
  const button = e.target;
  if (button.closest('button')) {
    const dialog = button.nextElementSibling;
    dialog.showModal()
    
    if (button.classList.contains('focus')) {
      dialog.focus()
    }
  }
})
              
            
!
999px

Console