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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<header>
<input type="checkbox" id="json-toggle" class="toggle">
<label for="json-toggle">JSON Mode</label>
</header>
<main>
<div class="form">
<div class="fieldset fieldset__options">
<label>Select a transition</label>
<label><input type="radio" name="transition" value="1" checked="checked"><code>linear 500ms</code></label>
<label><input type="radio" name="transition" value="2"><code>linear 200ms</code></label>
<label><input type="radio" name="transition" value="3"><code>ease 300ms</code></label>
<label><input type="radio" name="transition" value="4"><code>ease-in 300ms</code></label>
<label><input type="radio" name="transition" value="5"><code>ease-out 300ms</code></label>
<label><input type="radio" name="transition" value="6"><code>cubic-bezier(.05, .69, .14, 1) 500ms</code></label>
<label><input type="radio" name="transition" value="custom">Custom</label>
</div>
<div class="fieldset">
<label for="id">Custom transition (timing speed)</label>
<input type="text" placeholder="e.g. cubic-bezier(.03,.43,.95,.66) 500ms" name="custom-transition" value="cubic-bezier(.03,.43,.95,.66) 500ms">
</div>
<div class="fieldset">
<label for="id">Some other field</label>
<input type="text">
</div>
<div class="fieldset">
<label for="id">Some other field</label>
<input type="text">
</div>
<h3>What is this?</h3>
<p>Experimenting with different transition speeds and methods for toggling in JSON configuration mode for a form. Prototype for <a href="http://mesosphere.com">Mesosphere</a> where we have a JSON option in DC/OS to configure and launch Docker containers.</p>
<p>Some good reading:
<ul>
<li><a href="http://valhead.com/2016/05/05/how-fast-should-your-ui-animations-be/">How fast should your UI animations be?</a></li>
<li><a href="https://www.smashingmagazine.com/2016/08/css-animations-motion-curves/">CSS Animation with motion curves</a></li>
<li><a href="https://blog.alexmaccaw.com/css-transitions">All you need to know about CSS transitions</a></li>
<li><a href="http://cubic-bezier.com/#.17,.67,.83,.67">Cubic Bezier tool</a></li>
</ul>
</p>
</div>
<div class="json">
Hi I'm JSON mode
</div>
</main>
// Transitions
$transitions:
linear 500ms,
linear 200ms,
ease 300ms,
ease-in 300ms,
ease-out 300ms,
cubic-bezier(.05, .69, .14, 1) 500ms;
@for $i from 1 through length($transitions) {
.transition-#{$i} {
transition: nth($transitions, $i);
}
}
// Other variables
$header: 20px;
$json-width: 50%;
$padding: 20px;
// JSON mode styles
.json {
background: #252b3a;
box-sizing: border-box;
color: #fff;
flex: 0 0 $json-width;
font-family: monospace;
font-size: 120%;
margin-right: -$json-width;
padding: $padding;
transition-property: all;
}
.json--on {
margin-right: 0;
}
// Form styles
.form {
flex: 1;
overflow: scroll;
padding: $padding;
.fieldset {
clear: both;
margin: 0 0 $padding*2;
}
.fieldset__options label {
margin-right: 10px;
input {
margin-right:5px;
width: auto;
}
}
label {
display: block;
font-size: .8em;
margin-bottom: $padding/2;
text-transform: uppercase;
}
input {
background: #f2f2f2;
border: 2px solid transparent;
border-radius: 5px;
box-sizing: border-box;
padding: $padding/2;
width: 100%;
&:focus {
border: 2px solid #9351e5;
outline: none;
}
}
}
// General styles
body {
color: #333;
font-family: -apple-system, "Helvetica Neue";
height: 100%;
line-height: 1.4;
}
h3 {
margin-bottom: 0;
}
p,
ul,
ol {
color: #555;
font-size: 14px;
}
code {
background-color: #f9f2f4;
border-radius: 4px;
color: #c7254e;
font-size: 90%;
padding: 2px 4px;
}
header {
background: #f9f9f9;
border-bottom: 1px solid #eaebed;
height: $header;
position: fixed;
padding: $padding;
text-align: right;
width: 100%;
}
main {
display: flex;
flex-direction: row;
flex: 1;
overflow: hidden;
padding-top: 60px;
}
// Toggle styles
.toggle {
margin-left: -999px;
visibility: hidden;
}
.toggle + label {
border-radius: 60px;
cursor: pointer;
float: left;
font-size: 12px;
height: 10px;
outline: none;
padding: 6px;
position: relative;
text-indent: 40px;
user-select: none;
}
.toggle + label:before,
.toggle + label:after {
content: "";
bottom: 1px;
display: block;
left: 1px;
position: absolute;
top: 1px;
width: 40px;
}
.toggle + label:before {
background-color: #f1f1f1;
border: 1px solid #eaebed;
border-radius: 60px;
right: 1px;
transition: background 0.4s;
}
.toggle + label:after {
background-color: #fff;
border-radius: 100%;
box-shadow: 0 2px 5px rgba(0, 0, 0, .3);
transition: margin 0.4s;
width: 20px;
}
.toggle:checked + label:before {
background-color: #8ce196;
}
.toggle:checked + label:after {
margin-left: 20px;
}
$('.toggle').on('click', function(e) {
$('.json').removeClass (function (index, css) {
return (css.match (/(^|\s)transition-\S+/g) || []).join(' ');
});
$('.json').removeAttr('style');
var transition = $("input[name='transition']:checked").val();
if (transition == "custom") {
var customTransition = $("input[name='custom-transition']").val();
$('.json').attr('style','transition: ' + customTransition);
} else {
$('.json').addClass('transition-'+transition);
}
$('.json').toggleClass('json--on');
});
Also see: Tab Triggers