HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="example-cntr backdrop">
<h1>CSS <code>::backdrop</code> pseudo-element</h1>
<p>The <code>::backdrop</code> pseudo-element is a box that the full screen element has behind it, but at the same time it sits above all other content.</p>
<p>It can be used together with the <code>:fullscreen</code> pseudo-class or the <code><dialog></code> HTML5 element to change the background color of the maximized screen, just in case we don’t want to go with the default black.</p>
<div class="notes">
<h2>A few notes to consider:</h2>
<ol>
<li>It’s mandatory to use double colon with the <code>::backdrop</code> pseudo- element, it doesn’t work with single colon like with other pseudo-elements.</li>
<li>Edge is the only one that shows any styling of the <code>::backdrop</code> pseudo-element in this demo.</li>
<li>Firefox 47 (<a href="https://developer.mozilla.org/en-US/Firefox/Releases/47" target="_blank" title="Links opens in a new tab">release date June 29, 2016</a>) will start supporting the <code>::backdrop</code> pseudo-element.</li>
<li>Also, <a href="http://caniuse.com/#search=dialog" target="_blank"
title="Links opens in a new tab">no current version of Firefox supports the <code><dialog></code></a> HTML5 element.</li>
<li>Chrome doesn’t style the <code>::backdrop</code> pseudo-element when used with the <code>:fullscreen</code> pseudo-class even though <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::backdrop#Browser_compatibility" target="_blank"
title="Links opens in a new tab">MDN states that Chrome does support it </a>if prefixed with <code>-webkit-</code>. This is for Example 1.</li>
<li>Chrome properly styles the <code>::backdrop</code> pseudo-element when used with the <code><dialog></code> HTML5 element. This is for Example 2.</li>
<li><a href="http://caniuse.com/#search=dialog" target="_blank"
title="Links opens in a new tab">Only Chrome supports the <code><dialog></code></a> HTML5 element at the moment.</li>
<li>No mobile device supports the <code>::backdrop</code> pseudo-element.</li>
</ol>
</div>
<div class="example">
<h2>Example 1: Using <code>:fullscreen</code></h2>
<h1 id="element"><span class="hide">The text is injected via CSS</span></h1>
<button onclick="var el = document.getElementById('element'); el.webkitRequestFullscreen();">Trigger Full Screen!</button>
</div>
<div class="example">
<h2>Example 2: Using <code><dialog></code></h2>
<dialog>
<h1>This is a dialog. Good job! :]</h1>
<p>Press <code>ESC</code> or click on Close button.</p>
<hr>
<button id="close">Close</button>
</dialog>
<button id="show">Open Dialog!</button>
</div>
</div>
//Example 1
#element {
border-bottom: none;
background: none;
//Content in "normal" mode.
&:before {
content: 'Normal mode';
}
//Content in fullscreen mode
&:fullscreen:before {
content: 'Fullscreen mode';
}
&:fullscreen::backdrop {
background: $b;
}
//According to MDN we need to prefix, but it doesn't work in my tests.
&:fullscreen::-webkit-backdrop {
background: $b;
}
}
//Example 2
dialog {
width: 350px;
padding: 40px;
border: 1px solid rgba(black,.3);
border-radius: 2px;
box-shadow: 0 5px 20px black;
top: 30%;
}
dialog::backdrop {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(darken($g,25),.8);
}
//Styling stuff not needed for demo
body {
text-align: left;
line-height: 1.5;
}
h1 {
font-size: 22px;
text-transform: none;
border-bottom: #636363 1px dotted;
code {
display: inline-block;
margin-bottom: 10px;
color: $y;
background: none;
box-shadow: none;
}
}
h2 { font-size: 18px; }
code { font-size: 1em; }
.example-cntr {
max-width: 800px;
margin: 0 auto 50px;
padding: 30px;
box-shadow: 0 1px 2px rgba(black,.3);
background: rgba(black,.15);
& > code {
display: block;
margin-bottom: 10px;
font-size: 22px;
color: $y;
background: none;
box-shadow: none;
}
}
.underline { text-decoration: underline; }
//
.hide { display: none; }
#element {
border-bottom: #444 1px solid;
padding-bottom: 20px;
&:before {
display: block;
padding: 5px 0;
background: $g;
}
&:fullscreen:before {
display: block;
padding: 5px 250px;
background: $r;
}
}
button {
padding: 8px 15px;
cursor: pointer;
background: linear-gradient(white, #aaa);
border-radius: 2px;
&:hover { background: white; }
&:active { background: linear-gradient(#aaa, white 20%);}
}
.note {
color: desaturate($y,30);
font-size: 12px;
letter-spacing: .5px;
}
.notes {
margin-bottom: 20px;
padding: 20px 20px 0;
border: #444 1px solid;
border-radius: 3px;
h2 { margin: 0; }
}
.example {
margin: 0 20px;
padding: 20px;
background: rgba(black,.2);
margin-bottom: 20px;
&:last-child { margin-bottom: 0; }
h1 { border: none !important; margin-bottom: 0 !important; }
h2 { margin-top: 0; }
}
dialog {
text-align: center;
p { text-align: left; }
}
//Trigger the dialog box
var dialog = document.querySelector('dialog');
document.querySelector('#show').onclick = function() {
dialog.showModal();
};
document.querySelector('#close').onclick = function() {
dialog.close();
};
/* More information about the <dialog> element here: http://demo.agektmr.com/dialog/ */
Also see: Tab Triggers