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.
<section><div class="content">
<h1>
<span>Variable</span>
<span>Fonts</span>
</h1>
<p>A talk by <a href="https://scottkellum.com">Scott Kellum</a></p>
</div></section><section><div class="content">
<img src="http://www.alphabettes.org/wp-content/uploads/2017/06/size_ranges_2.png" alt="">
<p class="caption">Benton Modern’s optical sizes</p>
</div></section><section><div class="content">
<ul>
<li>Optical sizes</li>
<li>Weight</li>
<li>Width</li>
<li>Grade</li>
</ul>
</div></section><section><div class="content">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/noordzij%20cube%20white.svg" alt=" ">
<p class="caption">A <a href="http://letterror.com/2014/09/19/mutatormath/">Noordzij cube</a> of the Freight family</p>
</div></section><section><div class="content">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/superpolator.png" alt="">
<p class="caption"><a href="http://superpolator.com/">Superpolator</a></p>
</div></section><section><div class="content skia">
<h1>Skia</h1>
</div></section><section><div class="content">
<pre><code>body {
font-weight: 400;
}</code></pre>
</div></section><section><div class="content decovar">
<h1 id="decovarHead" contenteditable>Decovar</h1>
<form id="decovarForm">
<label>
<span>Inline</span>
<input name="BLDA" type="range" min="0" max="1000" value="0">
</label>
<label>
<span>Skeleton</span>
<input name="SKLA" type="range" min="0" max="1000" value="0">
</label>
<label>
<span>Weight</span>
<input name="WMX2" type="range" min="0" max="1000" value="0">
</label>
<label>
<span>Rounded</span>
<input name="TRMA" type="range" min="0" max="1000" value="0">
</label>
<label>
<span>Slab</span>
<input name="TRMC" type="range" min="0" max="1000" value="0">
</label>
</form>
</div></section><section><div class="content zicon">
<h1>🌝🐈🐕🐢💡🔒🕛🖐🚴🦉🦎</h1>
</div></section><section><div class="content">
<h1><span>cool, but why use them?</span></h1>
</div></section><section><div class="content">
<h2>Implementation</h2>
<pre><code>@font-face {
font-family: 'Tablet Gothic';
src: url('/TabletGothicGX.woff2') format('woff2');
}</code></pre>
<pre><code>body {
font-family: 'Tablet Gothic';
font-weight: 600;
font-variation-settings: 'wght' 600, 'wdth' 2;
}</code></pre>
</div></section><section><div class="content">
<video autoplay loop src="https://dropbox.design/videos/DB_Type_170922_v01.mp4"></video>
<p class="caption">Sharp Grotesk for Dropbox (259 fonts)</p>
</div></section><section><div class="content sbnation">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/sbnation.png" alt="">
</div></section><section><div class="content">
<video autoplay loop src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/andrew-johnson.webm" type="video/webm"></video>
<p class="caption"><a href="https://www.instagram.com/p/BeGDXM0Aehc/">Andrew Johnson on Instagram</a></p>
</div></section><section><div class="content">
<video autoplay loop src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/typetura.webmsd.webm" type="video/webm"></video>
<p class="caption"><a href="https://github.com/scottkellum/typetura.js">Typetura.js</a></p>
</div></section><section><div class="content">
<pre><code>h1 {
--variation-wght:
2 ~ 500,
.2 ~ 1000
;
--variation-wdth:
1.2 ~ 500,
.8 ~ 1000
;
}</code></pre>
</div></section><section><div class="content">
<ul>
<li>Identify custom properties</li>
<li>Create object to store settings</li>
<li>Add CSS variables to the context</li>
<li>Link regular CSS properties to the variables</li>
<li>On resize, only the variables change</li>
</ul>
</div></section><section><div class="content">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/Screen%20Shot%202018-03-28%20at%2012.40.43%20PM.png" alt="">
</div></section><section><div class="content">
<h2>CSS Houdini</h2>
<pre><code>registerPaint('typetura', class {
static get inputProperties() {
return [
'--font-variation-settings'
];
}
}</code></pre>
</div></section><section><div class="content interface">
<form style="font-size: 2em" id="interface">
<label>
<span>Departure</span>
<input type="time" id="formDept" value="08:00"style="width: 8em">
<span class="zicon clock" id="formDeptIcn">🕛</span>
</label>
<label>
<span>Arrival</span>
<input type="time" id="formArr" value="12:00"style="width: 8em">
<span class="zicon clock" id="formArrIcn">🕛</span>
</label>
</form>
</div></section><section><div class="content">
<img src="https://cdn.shopify.com/s/files/1/0155/2821/products/Madita_Anim_3366bd73-0e31-42b4-bbc5-8a953ebbb023.gif?v=1501249504" alt="">
<p class="caption"><a href="https://animography.net/products/madita">Madita</a> Animography by Philip von Borries</p>
</div></section><section><div class="content">
<iframe scrolling='no' title='Animography’s Mobilo Text Editor in SVG' src='//codepen.io/airnan/embed/preview/JbOrbV/?height=265&theme-id=light&default-tab=result&embed-version=2'>See the Pen <a href='https://codepen.io/airnan/pen/JbOrbV/'>Animography's Mobilo Text Editor in SVG</a> by kittons (<a href='https://codepen.io/airnan'>@airnan</a>) on <a href='https://codepen.io'>CodePen</a>.
</iframe>
</div></section><section><div class="content">
<h1><span>Variable fonts are</span> <span>new</span></h1>
</div></section><section><div class="content">
<h2>Variable font resources</h2>
<ul>
<li><a href="https://www.axis-praxis.org/">Axis-Praxis</a></li>
<li><a href="https://medium.com/@tiro/https-medium-com-tiro-introducing-opentype-variable-fonts-12ba6cd2369">Variable font introduction</a></li>
<li><a href="https://github.com/scottkellum/typetura.js">Typetura.js</a></li>
<li><a href="https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts/">Microsoft’s variable font demo</a></li>
</ul>
</div></section>
/// SLIDES
.content.decovar {
h1 {
font-family: decovar;
width: 100%;
animation: none;
}
}
.content.zicon {
h1 {
font-family: zicon;
text-shadow: none;
font-weight: 400;
width: 90vw;
font-size: 23vw;
animation: zicon 1s infinite alternate ease-in-out;
text-align: center;
}
}
@keyframes zicon {
from {
font-variation-settings: 'T1 ' 0, 'T2 ' 0, 'T3 ' 0, 'T4 ' 0, 'M1 ' -1, 'M2 ' -1;
}
to {
font-variation-settings: 'T1 ' 1, 'T2 ' 1, 'T3 ' 1, 'T4 ' 1, 'M1 ' 1, 'M2 ' 1;
}
}
.content.skia {
h1 {
font-family: skia;
animation: skia 5s infinite alternate ease;
text-align: center;
}
}
@keyframes skia {
from {
font-variation-settings: 'wght' 0.48, 'wdth' 0.61998;
}
to {
font-variation-settings: 'wght' 3.2, 'wdth' 1.3;
}
}
.content.sbnation {
img {
width: 100vw;
height: 100vh;
object-fit: cover;
}
}
.content.interface {
span.zicon {
font-family: zicon;
font-weight: normal;
width: 1em;
font-size: 1.4em;
position: relative;
transform: translatey(.18em);
}
span.clock {
transform: translatey(.18em) rotate(180deg);
}
span.mi {
width: 4.5em;
font-variation-settings: 'wght' 300;
}
span.pace {
font-size: 20vw;
margin: -.4em auto 0;
display: block;
}
}
/// STYLES
@font-face {
font-family: 'Tablet Gothic';
src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/467/TabletGothicGX.ttf') format('TrueType');
}
@font-face {
font-family: zicon;
src: url('https://www.axis-praxis.org/fonts/webfonts/Zycon.ttf') format('TrueType');
}
@font-face {
font-family: decovar;
src: url('https://www.axis-praxis.org/fonts/webfonts/DecovarAlpha-VF.ttf') format('TrueType');
}
body {
overflow: hidden;
background-image: linear-gradient(-45deg, #f44242, transparent), linear-gradient(45deg, rgba(#ef9f09,.4), transparent);
background-color: #8e00e0;
transition: background-color .5s ease;
width: 100vw;
height: 100vh;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
color: #fff;
animation: body 400s infinite linear;
}
@keyframes body {
0% {
background-color: #8e00e0;
}
20% {
background-color: #23aeff;
}
40% {
background-color: #0ed148;
}
60% {
background-color: #ffb600;
}
80% {
background-color: #ed5223;
}
100% {
background-color: #8e00e0;
}
}
section {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: none;
&.active {
display: block;
}
}
a {
color: inherit;
opacity: .8;
&:hover {
opacity: 1;
}
}
li {
list-style: none;
font-size: 4vw;
margin: .5em;
}
pre {
font-family: Monaco;
font-size: 2.5vw;
}
.caption {
display: block;
text-align: center;
font-style: italic;
}
.content {
display: table;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
max-width: 100vw;
max-height: 100vw;
}
label {
display: block;
margin: 0 0 .5em 0;
transition: font-variation-settings .3s cubic-bezier(.5, 0, .5, 1.5);
font-variation-settings: 'wght' 200;
&:hover {
font-variation-settings: 'wght' 700;
}
span {
display: inline-block;
width: 6em;
}
}
input:not([type=range]) {
border: none;
border-radius: 3px;
background-color: rgba(#000,.3);
color: inherit;
padding: .3em .5em;
font-family: inherit;
font-variation-settings: 'wght' 300;
font-size: inherit;
outline: none;
&:hover {
box-shadow: 0 0 0 1px rgba(#fff,.9);
}
}
input[type=range] {
width: 50vw;
}
img,
video {
width: 80vw;
height: 80vh;
object-fit: contain;
display: block;
}
iframe {
width: 90vw !important;
height: 90vh !important;
padding: 0 !important;
border: none;
}
h1,
h2 {
font-family: 'Tablet Gothic';
line-height: 1;
width: 80vw;
font-size: 16vw;
text-shadow: .02em .02em 0 rgba(#fff, .3);
animation: variation 32s infinite linear;
margin: .2em 0;
span {
display: block;
}
span:nth-child(2) {
animation: variation 32s infinite linear;
animation-delay: -7s;
}
}
h2 {
font-size: 6vw;
}
@keyframes variation {
0% {
font-variation-settings: 'wght' 300, 'wdth' 7;
}
20% {
font-variation-settings: 'wght' 500, 'wdth' 1;
}
40% {
font-variation-settings: 'wght' 400, 'wdth' 3;
}
60% {
font-variation-settings: 'wght' 900, 'wdth' 5;
}
80% {
font-variation-settings: 'wght' 700, 'wdth' 2;
}
100% {
font-variation-settings: 'wght' 300, 'wdth' 7;
}
}
// Slide behavior
var section = document.querySelectorAll('section');
section[0].classList.add('active');
// Slides
// Decovar
var decovarHead = document.getElementById('decovarHead');
var decovarForm = document.getElementById('decovarForm');
var decovarSettings = {};
decovarForm.oninput=decovarChange;
function decovarChange(event) {
var name = event.srcElement.name;
var value = event.srcElement.value;
decovarSettings[name] = value;
var string = '';
for (var p in decovarSettings) {
string = string + '\'' + p + '\'' + ' ' + decovarSettings[p] + ', ';
}
string = string.slice(0, -2);
decovarHead.style.fontVariationSettings = string;
}
// interface
var interface = document.getElementById('interface');
var deptIcn = document.getElementById('formDeptIcn');
var arrIcn = document.getElementById('formArrIcn');
interface.oninput=interfaceChange;
var parseTime = function(t) {
t = t.split(':');
t[1] = t[1] / 60;
t = parseInt(t[0]) + t[1];
t = t % 12;
t = t / 12 * 2 - 1;
return t
}
function interfaceChange(event) {
var dept = document.getElementById('formDept').value;
var arr = document.getElementById('formArr').value;
dept = parseTime(dept);
arr = parseTime(arr);
deptIcn.style.fontVariationSettings = '\'M1 \'' + dept;
arrIcn.style.fontVariationSettings = '\'M1 \'' + arr;
}
var dept = document.getElementById('formDept').value;
var arr = document.getElementById('formArr').value;
dept = parseTime(dept);
arr = parseTime(arr);
deptIcn.style.fontVariationSettings = '\'M1 \'' + dept;
arrIcn.style.fontVariationSettings = '\'M1 \'' + arr;
// Paging and general stuff
function prev() {
var el = document.querySelector('.active');
var prev = el.previousSibling;
console.log(prev.nodeType);
if(prev && prev.nodeType != 3) {
prev.classList.add('active');
el.classList.remove('active');
}
}
function next() {
var el = document.querySelector('.active');
var next = el.nextSibling;
console.log(next.nodeType);
if(next && next.nodeType != 3) {
next.classList.add('active');
el.classList.remove('active');
}
}
// SETTINGS
var wayDirection = 'horizontal'; // vertical, horizontal
var wayKeys = true; // boolean
var wayScroll = true; // boolean
var waySwiping = true; // boolean
var wayThresholdScroll = 3; // how sensitive is scrolling?
var wayThresholdSwipe = 20; // how sensitive is swiping?
// KEYBOARD
if(wayKeys) { // Key inputs, all the usual suspects for discoverability
document.addEventListener('keyup', (e) => {
if(e.key === 'ArrowLeft' || e.key === 'k') {
prev();
}
else if (e.key === 'ArrowRight' || e.key === 'j') {
next();
}
}, false);
};
// SCROLL EVENTS
var wayScrollFired = false; // Use to debounce scroll events
if(wayScroll) { // only fire if scrolling is an option
window.addEventListener('mousewheel', function(e) { // listen for scroll events
// vertical scrolling
if(wayDirection === 'vertical') {
if(wayThresholdScroll < Math.abs(e.deltaY)) { // does it meet the threshold?
if(!wayScrollFired) { // Fire once, debounce input
if(e.deltaY > 0) {
next();
} else {
prev();
}
wayScrollFired = true; // Don’t fire again until new scroll
}
} else { // Reset debounce when under threshold
wayScrollFired = false;
}
}
// vertical scrolling
else {
if(wayThresholdScroll < Math.abs(e.deltaX)) { // does it meet the threshold?
if(!wayScrollFired) { // Fire once, debounce input
if(e.deltaX > 0) {
next();
} else {
prev();
}
wayScrollFired = true; // Don’t fire again until new scroll
}
} else { // Reset debounce when under threshold
wayScrollFired = false;
}
}
});
};
// TOUCH EVENTS
var waySwipeFired = false; // Only trigger once
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchmove', handleTouchMove, false);
document.addEventListener('touchend', handleTouchEnd, false);
var xDown;
var yDown;
var xDiff;
var yDiff;
function handleTouchStart(e) {
xDown = e.touches[0].clientX;
yDown = e.touches[0].clientY;
}
function handleTouchMove(e) {
var xUp = e.touches[0].clientX;
var yUp = e.touches[0].clientY;
xDiff = xDown - xUp;
yDiff = yDown - yUp;
if(!waySwipeFired) {
if(wayDirection === 'horizontal') {
if(Math.abs(xDiff) > Math.abs(yDiff)) {
if(wayThresholdSwipe < Math.abs(xDiff)) {
if(xDiff > 0) {
next();
} else {
prev();
}
waySwipeFired = true;
}
}
} else {
if(Math.abs(yDiff) > Math.abs(xDiff)) {
if(wayThresholdSwipe < Math.abs(yDiff)) {
if(yDiff > 0) {
next();
} else {
prev();
}
waySwipeFired = true;
}
}
}
}
};
// Reset touch data
function handleTouchEnd(e) {
xDown = null;
yDown = null;
xDiff = null;
yDiff = null;
waySwipeFired = false;
};
Also see: Tab Triggers