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

              
                <button class="btn" data-toggle="#dialog">Open modal</button>

<button class="btn" data-toggle="#dialog-tall">Open tall modal</button>

<dialog id="dialog">
  <header>
    Example modal
    <button class="btn btn-close" data-close>
      <svg width="16" height="16"><use xlink:href="#x"/></svg>
    </button>
  </header>
  Some basic text inside the modal to demonstrate how it all looks and works.
</dialog>

<dialog id="dialog-tall">
  <header>
    Super tall modal
    <button class="btn btn-close" data-close>
      <svg width="16" height="16"><use xlink:href="#x"/></svg>
    </button>
  </header>
  <p>Line breaks to push the height out.</p>
  <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  <button type="button" class="btn" data-close>Close</button>
</dialog>

<!-- Close button -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="x" viewBox="0 0 16 16">
    <path d="m1 1 14 14m0-14-14 14" stroke="currentColor" stroke-width="2"/>
  </symbol>    
</svg>

              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

:root {
  --body-color: #333;
  --body-bg: #fff;
  --emphasis-color: #111;
  --accent-color: dodgerblue;
  --secondary-bg: #f5f5f5;
  --border-color: rgba(0,0,0,.15);
  --modal-padding-x: 1.25rem;
  --modal-padding-y: .75rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --body-color: #888;
    --body-bg: #222;
    --emphasis-color: #fff;
    --secondary-bg: #252525;
    --border-color: rgba(255,255,255,.15);
  }
}

html {
  font-size: 16px;
}

body {
  padding: 1.5rem;
  margin: 0;
  font: 1rem/1.5 sans-serif;
  color: var(--body-color);
  background-color: var(--body-bg);
}

.btn {
  display: inline-flex;
  padding: .5rem 1rem;
  margin: 0;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--emphasis-color);
  background: none;
  border: 1px solid var(--border-color);
  border-radius: .375rem;
  box-shadow: 0 .125rem .25rem rgba(0,0,0,.075);
  cursor: pointer;

  &:not(:disabled) {
    &:hover,
    &:focus,
    &:active,
    &[active] {
      color: #fff;
      background-color: var(--accent-color);
      border-color: var(--accent-color);
    }
  }
}

.btn-close {
  padding: .25rem;
  line-height: 1;
  background-color: transparent;
  border: 0;
  border-radius: .25rem;
  box-shadow: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
  } to {
    opacity: 1;
  }
}

dialog {
  position: relative;
  z-index: 100;
  width: 420px;
  max-width: 100%;
  padding: var(--modal-padding-y) var(--modal-padding-x);
  color: var(--body-color);
  background-color: var(--secondary-bg);
  background-clip: padding-box;
  border: 1px solid var(--border-color);
  border-radius: .5rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.5);
  
  &::backdrop {
    background-color: rgba(0,0,0,.5);
    animation: .5s fade-in;
  }
  
  > header {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--modal-padding-y) * -1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--modal-padding-y) var(--modal-padding-x);
    margin: calc(var(--modal-padding-y) * -1) calc(var(--modal-padding-x) * -1) var(--modal-padding-y);
    font-weight: 600;
    color: var(--emphasis-color);
    background-color: inherit;
    border-bottom: 1px solid var(--border-color);

    [data-close] {
      margin-right: -.25rem;
    }
  }
}

[open] + .backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(255,0,0,.25);
}

              
            
!

JS

              
                let toggler = document.querySelectorAll('[data-toggle]')
let closers = document.querySelectorAll('[data-close]')

if (toggler) {
  toggler.forEach(function (element) {
    let target = element.getAttribute("data-toggle")
    let targets = document.querySelectorAll(target)

    element.addEventListener("click", (event) => {
      targets.forEach(function (e) {
        e.showModal()
      })
    })
  })
  
  closers.forEach(function (element) {
    element.addEventListener("click", (event) => {
      let dialog = element.closest('dialog')
      dialog.close()
    })
  })
}

              
            
!
999px

Console