Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <details>
  <summary class="btn">Open modal</summary>
  <div class="modal">
    <div class="modal-header">
      Modal header
      <button type="button" data-dismiss>
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">
          <path fill-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z"/>
          <path fill-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z"/>
        </svg>
      </button>
    </div>
    <div class="modal-body">
      Something small enough to escape casual notice.
    </div>
  </div>
  <backdrop></backdrop>
</details>

<details>
  <summary class="btn">Open dropdown</summary>
  <dropdown role="menu" aria-labelledby="dropdown-toggle">
    <button type="button" disabled>Cut</button>
    <button type="button" disabled>Copy</button>
    <button type="button">Paste</button>
    <hr>
    <button type="button">Spelling and Grammar...</button>
    <hr>
    <button type="button">Inspect Element</button>
  </dropdown>
  <backdrop></backdrop>
</details>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html {
  font-size: 14px;
}

body {
  min-height: 100vh;
  padding: 1.5rem;
  margin: 0;
  font: 1rem/1.5 sans-serif;
}

hr {
  margin: 2rem 0;
  border: 0;
  border-bottom: .0625rem solid #eee;
}

.btn,
button {
  position: relative;
  display: inline-block;
  padding: .375rem 1rem;
  margin: 0;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  background: none;
  border: .0625rem solid rgba(0,0,0,.15);
  border-radius: .25rem;
  cursor: pointer;

  &::-webkit-details-marker { display: none; }
  
  &:not(:disabled) {
    &:hover,
    &:focus,
    &:active,
    &[active] {
      color: #fff;
      background-color: rgba(0,0,255,.65);
      border-color: rgba(0,0,255,.65);
    }
  }
}

details {
  margin-bottom: .5rem;
}

[open] {
  position: relative;
  
  backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: block;
    content: "";
    background-color: rgba(0,0,0,.5);
  }
  
  .modal {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    left: 1.5rem;
    z-index: 101;
    max-width: 480px;
    margin-inline: auto;
    background-color: #fff;
    border-radius: .5rem;
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.5);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid rgba(0,0,0,.1);
  
  [data-dismiss] {
    margin-right: -.25rem;
  }
}

.modal-body {
  padding: 1.25rem;
}

[data-dismiss] {
  display: inline-flex;
  padding: .25rem;
  background-color: transparent;
  border: 0;
  border-radius: .25rem;
}

dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 101;
  display: flex;
  flex-direction: column;
  max-width: 14rem;
  padding-top: .25rem;
  padding-bottom: .25rem;
  margin-top: .25rem;
  background-color: #fff;
  background-clip: padding-box;
  border: .0625rem solid rgba(0,0,0,.2);
  border-radius: .5rem;
  box-shadow: 0 .5rem 1rem rgba(0,0,0,.5);

  > button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    border-radius: 0;

    &:not(:disabled) {
      &:hover,
      &:focus,
      &:active {
        color: #fff;
        background-color: rgba(0,0,255,.65);
      }
    }
  }

  > hr {
    margin: .25rem 0;
  }

  > form {
    padding-right: .25rem;
    padding-left: .25rem;
  }
}

              
            
!

JS

              
                let details = document.querySelectorAll('details')

if (details) {
  details.forEach(function (element) {
    let dismissBtn = element.querySelector('[data-dismiss]')
    let backdrop = element.querySelector('backdrop')
    let detailsToggles = [ dismissBtn, backdrop ]
    
    detailsToggles.forEach(function (toggle) {
      console.log('toggle: ' + toggle)
      
      if (toggle) {
        toggle.addEventListener("click", event => {
          toggle.closest('details[open]')
            .removeAttribute("open")
        })
      }
    })
  })
}

              
            
!
999px

Console