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="folds">
<div class="fold fold1">
<div class="shadow"></div>
<div class="content header">Public<br/>spaces</div>
<div class="fold fold2">
<div class="shadow"></div>
<div class="content foldcontent">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>
</div>
</div>
</div>
<div class="mover">
I am so attached to the element above...
</div>
<div class="container">
<h3>Some more Text</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, cum. Rem quaerat iusto assumenda voluptates dolores nulla, pariatur suscipit sapiente voluptate consequatur error. Ducimus inventore esse numquam, tempore vel aliquid.</p>
</div>
<div class="controls">
<input type="range" min="0" max="1" step="0.001" value="0" />
<label><input type="checkbox" checked /> GPU</label>
<button>Toggle</button>
</div>
*{
box-sizing: border-box;
}
html{
font: 16px / 1.54 'Helvetica', sans-serif;
background: #333;
}
body{
margin: 50px auto 0;
max-width: 700px;
}
.folds{
position: relative;
perspective: 2000px;
perspective-origin: 50% 50%;
}
.fold{
position: relative;
transform-origin: 50% 0;
transform-style: preserve-3d;
}
.shadow{
position: absolute;
top: 0;
left: 0;
right: 0;
background-image: linear-gradient(top, black, transparent);
height: 50%;
}
.content{
height: 200px;
}
.container{
padding: 20px;
background: #fff;
}
.mover{
background: #f0f0f0;
color: #333;
padding: 20px;
}
.fold1{
>.shadow{
background: linear-gradient(bottom, black, transparent);
}
.content{
background: url(https://farm3.staticflickr.com/2937/14371160993_186df4a083_c.jpg) 50% 50% no-repeat;
}
}
.fold2{
transform-origin: 50% 0;
.content{
background: #fff;
}
}
.controls{
position: absolute;
top: 20px;
left: 20px;
width: 500px;
color: #fff;
input[type=range]{
width: 300px;
}
}
.header{
text-transform: uppercase;
text-align: left;
padding: 20px;
line-height: 1;
font-size: 2em;
color: #fff;
}
.foldcontent{
padding: 20px;
}
// dom stuff
var d = document;
var control = d.querySelector('.controls input[type=range]');
var gpuEl = d.querySelector('.controls input[type=checkbox]');
var toggleEl = d.querySelector('.controls button');
var folds = d.querySelector('.folds');
var fold1 = d.querySelector('.fold1');
var fold2 = d.querySelector('.fold2');
var mover = d.querySelector('.mover');
var shadows = d.querySelectorAll('.shadow');
var ease = function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
};
// settings
var foldHeight = fold2.offsetHeight;
var transform = Modernizr.prefixed('transform');
var percent = 0;
var isOpen = true;
var gpu = true;
// event listener for value changes on slider
control.addEventListener('input', function() {
percent = Number(control.value);
});
// event listener for GPU change
gpuEl.addEventListener('change', function() {
gpu = gpuEl.checked;
fold(percent);
});
//event listener for toggle
toggleEl.addEventListener('click', function() {
animate(percent, percent === 0 ? 1 : 0, 500);
});
function animate(from, to, duration) {
var start = Date.now();
var now, process, step;
var anim = function() {
now = Date.now();
process = now - start;
step = ease(process, from, (to-from), duration);
if (process < duration) {
fold(step);
control.value = step;
percent = step;
requestAnimationFrame(anim);
} else{
fold(to);
control.value = to;
percent = to;
}
}
anim();
}
// set the fold to a certain percentage
function fold(percent) {
fold1.style[transform] = 'rotate3d(1,0,0,' + (percent * -90) + 'deg)';
fold2.style[transform] = 'rotate3d(1,0,0,' + (percent * 180) + 'deg)';
shadows[0].style.opacity = percent * 0.6;
shadows[1].style.opacity = percent * 0.6;
var visualFoldHeight = Math.cos(percent * Math.PI / 2) * foldHeight;
folds.style['-webkit-perspective-origin'] =
folds.style['-moz-perspective-origin'] =
folds.style['perspective-origin'] = '50% ' + visualFoldHeight + 'px';
if (gpu) {
// transform results in better performance
mover.style[transform] = 'translate3d(0,' + (Math.floor((visualFoldHeight - foldHeight) * 2)) + 'px,0)';
folds.style.height = 'auto';
} else {
// height is for better attachment of following elements
folds.style.height = Math.floor(visualFoldHeight * 2) + 'px';
mover.style[transform] = '';
}};
// request animation frame synced loop that checks if the percent has changed
var lastPercent = -1;
var loop = function() {
requestAnimationFrame(loop);
if (lastPercent === percent) { return; }
lastPercent = percent;
fold(percent);
};
// start loop
loop();
Also see: Tab Triggers