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>The &lt;dialog&gt; Element</h1>
<h2>Dialogue Boxes with HTML</h2>
<p>The <code>&lt;dialog&gt;</code> Element provides a streamlined and logical way to build dialogue boxes into your web applications.  It can be styled via CSS and controlled via 'vanilla' Javascript.  The <code>.showModal()</code> is used to open the dialogue box and <code>close()</code> to close it.</p>
<p><button id="openDialog">Open Dialog</button></p>
<h2>Background Styling</h2>
<p>Placing the focus on the dialogue box by changing the background colour of the document is a common design pattern.  This can be achieved through the <code>::backdrop</code> pseudo-element.  In addition animation effects can be added via the <code>open</code> attribute.</p>
<p>More details at: <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog">MDN Docs</a></p>
<dialog id="dialogBox">
  <h3>Important News</h3>
  <p>Some information here.</p>
  <div><button id="closeDialog">Close Dialog</button></div>
</dialog>
              
            
!

CSS

              
                ::backdrop {
  background-color: #000;
  opacity: 0.75;
}
dialog{
  border:2px solid #cccccc;
  border-radius:8px;
  box-shadow:8px 8px 4px #000;
}
dialog[open] {
  animation: dialogIn 1s forwards;
}

@keyframes dialogIn{
from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

code{
  font-family: monospace;
  color:#666;
  
}

              
            
!

JS

              
                const openDialog = document.getElementById("openDialog");
const dialogBox = document.getElementById("dialogBox");
openDialog.addEventListener('click',()=>{
  dialogBox.showModal();
})
closeDialog.addEventListener('click',()=>{
  dialogBox.close();
})
              
            
!
999px

Console