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.
<div class="vis">
<div class="page-container">
<div class="shape-container">
<div class="shape">
<p>
<span class="highlight">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nulla tristique sodales lacus dignissim vehicula. Nunc interdum accumsan nibh
quis aliquet. Vestibulum elit sem, posuere nec luctus at, imperdiet eget nulla.
Ut eleifend, leo sit amet eleifend condimentum, neque risus mattis lectus, eget
molestie augue libero sit amet felis. Sed sed metus risus. Suspendisse eget turpis
ante. Morbi at tempor magna. Nunc bibendum augue erat, eu consectetur felis dignissim
ut. Nam malesuada justo nunc, vel efficitur lacus tincidunt quis. Sed egestas tortor
vitae semper vestibulum. Morbi accumsan magna non neque imperdiet, sed molestie nunc
laoreet. Aliquam venenatis tristique volutpat. Nullam porta neque vitae dui faucibus
vulputate. Nam non metus rutrum, sagittis quam nec, dictum magna. Mauris lacinia euismod
pellentesque. Pellentesque eget imperdiet quam.
</span>
</p>
<p>
<span class="highlight">
Vivamus at finibus est, nec rutrum dui. Proin a mauris efficitur ante vestibulum
tincidunt. Proin vitae ligula in quam dignissim consectetur a nec dui. Nulla maximus
posuere hendrerit. Sed dui metus, molestie a magna et, feugiat malesuada urna. Donec
id suscipit erat. Cras porttitor, purus vel sagittis dapibus, ante nisl consectetur nisl,
non tristique eros dolor vel nunc. Aliquam a dictum ex, vitae pharetra lacus.
</span>
</p>
<p>
<span class="highlight">
Donec maximus, felis vitae placerat malesuada, velit tellus fringilla orci,
eu vulputate orci ex at felis. Curabitur fermentum eros eget ante convallis
dictum nec nec dui. In ullamcorper et mi scelerisque pretium. Morbi pretium
maximus venenatis. Donec sagittis eu ipsum aliquet luctus. Aenean vel mi
feugiat felis tristique egestas. Morbi consectetur efficitur massa, nec
pharetra magna sodales fermentum. In feugiat ipsum felis, eu maximus ligula
ornare at. Pellentesque in fringilla risus. Orci varius natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus. Etiam eu fringilla augue,
vitae ornare nibh. Fusce quis dictum lorem. Nullam posuere auctor rutrum. Nam et
nulla et nibh aliquam rutrum a eu magna. Aliquam at leo rhoncus, malesuada ante
vel, blandit sem. Ut vel gravida lacus, ut semper eros.
</span>
</p>
<p>
<span class="highlight">
Mauris semper risus eu dui vestibulum sollicitudin. Proin id nisl sed justo
sollicitudin laoreet. Fusce tellus eros, auctor nec pulvinar ut, placerat vel
tortor. Nullam non mattis mauris, convallis ullamcorper ante. Sed ut pellentesque
nisl, a sagittis nibh. Ut faucibus, quam eget fermentum porttitor, dolor velit
tincidunt ligula, eu scelerisque tortor nisi nec ex. In at eros hendrerit, venenatis
sem vitae, interdum ipsum. Sed vitae nisl placerat, pellentesque massa nec, bibendum
erat. In non malesuada lorem. Curabitur vulputate ultrices tortor, quis lobortis nunc.
Suspendisse suscipit neque et metus dapibus, sit amet luctus felis vestibulum. Aliquam
pretium ac erat eu luctus. Donec id aliquet ipsum, nec viverra ante. Donec nec placerat
turpis, in blandit ante. Morbi neque urna, feugiat sed auctor nec, scelerisque cursus
mi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia
Curae;
Quisque id erat sed velit condimentum sagittis non in est. Suspendisse faucibus interdum mauris ut aliquet.
</span>
</p>
</div>
<div class="shape">
<span class="highlight">
<p>
<span class="highlight">
Pellentesque fringilla mi feugiat tincidunt varius. Quisque facilisis lectus
posuere leo tempor pretium. Aliquam sodales nisi quam, a vulputate ante
pretium vel. Vestibulum convallis efficitur dignissim. Fusce lorem dui,
imperdiet non auctor quis, rhoncus in felis. Duis leo mauris, auctor et luctus
a, pharetra vitae sapien. Nam suscipit, magna vitae tristique tempus, quam
augue auctor erat, id tempor nibh ex in metus. Aenean at lacus pharetra,
pretium lectus a, dapibus turpis. Aliquam quis orci nec tortor mollis cursus.
</span>
</p>
<p>
<span class="highlight">
Nulla imperdiet nunc dolor, sagittis iaculis justo tempor et. Curabitur
efficitur lorem non dignissim tempus. Donec tincidunt erat at elit porttitor,
eu feugiat odio facilisis. Donec scelerisque finibus lacus, sit amet fermentum
nunc dignissim eu. Curabitur eget pellentesque mauris. Nam vel blandit felis.
Maecenas vitae magna nec orci tincidunt ornare eu nec dolor. Nulla facilisi.
Phasellus sit amet libero non est viverra luctus eget tristique tellus.
Maecenas condimentum risus non ex fermentum finibus. Sed ac tincidunt ligula.
</span>
</p>
<p>
<span class="highlight">
Curabitur vulputate arcu eget turpis accumsan, a bibendum ligula luctus.
Nam et aliquam metus, eget efficitur leo. Donec varius, est accumsan laoreet
imperdiet, mauris velit bibendum mi, ut euismod neque nibh et mi. Aliquam
scelerisque imperdiet ligula, eu facilisis justo. Vestibulum justo velit,
dignissim nec ullamcorper vel, pulvinar sed risus. Praesent sed semper nulla,
nec rutrum ante. Etiam egestas sagittis porttitor. In nec convallis tortor,
ut aliquam quam. Cras sagittis auctor faucibus. Quisque dictum scelerisque diam,
et dignissim nulla. Phasellus dictum tellus ut quam dapibus rhoncus. Quisque
cursus condimentum urna in ultricies. Donec quis ante et nisi hendrerit tempor.
Curabitur imperdiet neque tortor, a aliquam dui maximus in.
</span>
</p>
<p>
<span class="highlight">
Sed in lectus eget arcu elementum porta. Proin ultrices nunc placerat dolor
efficitur, vel mollis nunc egestas. Curabitur imperdiet tellus vitae eleifend tempus.
In hac habitasse platea dictumst. Nullam ac eros lorem. Morbi sit amet tortor vitae
turpis consequat blandit. Fusce urna dui, finibus nec vestibulum et, dapibus id orci.
Pellentesque faucibus mattis diam quis lacinia. Nunc quis bibendum eros. Mauris
tincidunt lectus augue, eget commodo lacus facilisis et. Etiam bibendum mollis massa,
in posuere nulla consequat in. Phasellus egestas dui et justo mollis ornare.
</span>
</p>
<p>
<span class="highlight">
Quisque id erat sed velit condimentum sagittis non in est. Suspendisse faucibus interdum
mauris ut aliquet. Cras viverra consequat sem. Fusce laoreet metus commodo turpis venenatis,
a consectetur purus tristique. In rhoncus finibus tellus et elementum. Aenean id ligula nec
nisl ultricies tincidunt id porta erat. Sed porttitor faucibus varius. Fusce sit amet libero
eget nisl posuere interdum id at arcu. Quisque aliquet neque a iaculis ultrices. Morbi gravida
feugiat egestas. Proin a tellus massa. Quisque at eros massa. Vivamus finibus lacus a enim volutpat
</span>
</p>
</span>
</div>
</div>
<div class="labels">
<span class="interval-label">Unison</span>
<span class="width-label">1</span>
:
<span class="height-label">1</span>
</div>
</div>
<div class="piano-container">
<div id="piano">
<div class="piano-guide piano-guide-0">a</div>
<div class="piano-guide piano-guide-1">w</div>
<div class="piano-guide piano-guide-2">s</div>
<div class="piano-guide piano-guide-3">e</div>
<div class="piano-guide piano-guide-4">d</div>
<div class="piano-guide piano-guide-5">f</div>
<div class="piano-guide piano-guide-6">t</div>
<div class="piano-guide piano-guide-7">g</div>
<div class="piano-guide piano-guide-8">y</div>
<div class="piano-guide piano-guide-9">h</div>
<div class="piano-guide piano-guide-10">u</div>
<div class="piano-guide piano-guide-11">j</div>
<div class="piano-guide piano-guide-12">k</div>
</div>
</div>
</div>
<div class="description">
<blockquote>
<p>
A page, like a building or a room, can be of any size and proportion, but some
proportions and sizes turn out to be distinctly more pleasing than others to most
human beings, and some have quite specific connotations.
</p>
<p>
Certain of these proportions reappear in the structure of the human body; others
appear in musical scales. Indeed, one of the simplest of all systems of page
proportions is based on the familiar intervals of the diatonic scale. Pages that
embody these basic musical proportions have been in common use in Europe for more
than a thousand years.
</p>
<p>
The perfect intervals (<a class="interval" data-index="7">fifth</a> and
<a class="interval" data-index="5">fourth</a>) coincide exactly with the favorite page
shapes of the European Middle Ages, which are still in use today: The page proportions
<a class="interval" data-index="7">2 : 3</a> and <a class="interval" data-index="5">3 : 4</a>.
Renaissance typographers made extensive use of narrower pages, corresponding
to the larger impure intervals (<a class="interval" data-index="9">major</a> and
<a class="interval" data-index="8">minor sixth</a>, <a class="interval" data-index="11">major</a>
and <a class="interval" data-index="10">minor seventh</a>).
</p>
<p>
Each page shape has a counterpart with which it alternates. If a sheet whose proportions
are <a class="interval" data-index="8">5 : 8</a> is folded in half, it produces a sheet
whose proportions are <a class="interval" data-index="4">4 : 5</a>. If this is
folded once again, it produces another sheet whose proportions are <a class="interval" data-index="8">5 : 8</a>.
In the same way, the proportion <a class="interval" data-index="12">1 : 2</a> alternates with the proportion
<a class="interval" data-index="0">1 : 1</a>. The proportion <a class="interval" data-index="6">1 : √2</a>,
corresponding to the <a class="interval" data-index="6">diminished fifth/augmented fourth</a> of equal temperament, is the only
one that alternates with itself.
</p>
<p>
In musical terms, these alternating proportions form harmonic inversions. (The harmonic
inversion of <a class="interval" data-index="7">a fifth</a>, for example, is
<a class="interval" data-index="5">a fourth</a>, and the harmonic inversion of
<a class="interval" data-index="8">a minor sixth</a>
is <a class="interval" data-index="4">a major third</a>.) The total of each such pair is always one octave.
</p>
</blockquote>
<div class="attrib">
Robert Bringhurst,
<a href="https://www.amazon.com/Elements-Typographic-Style-Robert-Bringhurst/dp/0881791326">
The Elements of Typographic Style
</a>
</div>
</div>
html,
body {
margin: 0;
padding: 0;
font-family: 'Libre Baskerville', serif;
background-color: white;
}
body {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
flex-direction: row-reverse;
}
.description {
flex: 1;
padding: 50px;
overflow-y: auto;
background-color: #f5f5f5;
}
blockquote,
.attrib {
font-size: 14px;
line-height: 1.5;
max-width: 768px;
margin: 0 auto 30px auto;
}
blockquote {
quotes: '\201C' '\201D' '\2018' '\2019';
}
blockquote:before {
color: #ccc;
content: open-quote;
font-size: 4em;
line-height: 0.1em;
margin-right: 0.25em;
vertical-align: -0.4em;
}
blockquote p:first-child {
display: inline;
}
.interval {
color: rgb(34, 187, 187);
border-bottom: 1px dotted rgb(34, 187, 187);
cursor: pointer;
}
.attrib {
font-size: 10px;
margin-top: 1em;
}
.attrib a,
.attrib a:visited {
color: black;
}
.vis {
flex: 1.6180339887498948482;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.page-container {
flex: 5;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.shape-container {
display: flex;
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.08), 0 10px 10px rgba(0, 0, 0, 0.06);
}
.shape {
width: 20vw;
height: 20vw;
box-sizing: border-box;
border: 1px solid transparent;
border-right: 1px solid #eee;
font-size: 0.243vw;
text-align: justify;
transition: all 0.2s ease;
position: relative;
background-color: #fff8ea;
}
.shape:last-of-type {
border-right-width: 0;
}
.shape p {
margin: 0;
text-indent: 3em;
}
.shape .highlight {
background-color: antiquewhite;
color: antiquewhite;
line-height: 2;
}
.labels {
padding-top: 20px;
font-size: 14px;
color: black;
}
.width-label {
margin-left: 20px;
}
.piano-container {
flex: 2;
display: flex;
align-items: flex-start;
justify-content: center;
position: relative;
}
#piano {
width: 250px;
height: 15vh;
position: relative;
}
.piano-guide {
position: absolute;
font-size: 11px;
color: #aaa;
vertical-align: baseline;
opacity: 0;
transition: opacity 0.5s ease;
}
#piano:hover .piano-guide {
opacity: 1;
}
.piano-guide-0,
.piano-guide-2,
.piano-guide-4,
.piano-guide-5,
.piano-guide-7,
.piano-guide-9,
.piano-guide-11,
.piano-guide-12 {
top: calc(100% + 8px);
}
.piano-guide-1,
.piano-guide-3,
.piano-guide-6,
.piano-guide-8,
.piano-guide-10 {
top: -20px;
}
.piano-guide-0 {
left: 5%;
}
.piano-guide-1 {
left: 10%;
}
.piano-guide-2 {
left: 17%;
}
.piano-guide-3 {
left: 22%;
}
.piano-guide-4 {
left: 29%;
}
.piano-guide-5 {
left: 41%;
}
.piano-guide-6 {
left: 49%;
}
.piano-guide-7 {
left: 54%;
}
.piano-guide-8 {
left: 61%;
}
.piano-guide-9 {
left: 67%;
}
.piano-guide-10 {
left: 72%;
}
.piano-guide-11 {
left: 80%;
}
.piano-guide-12 {
left: 91%;
}
@media only screen and (max-device-width: 480px) {
body {
display: block;
position: static;
overflow-y: auto;
}
.vis {
padding: 50px;
height: 400px;
}
}
const AREA_SIZE = 20 * 20;
const BASE_NOTE = 'C4';
const BASE_FREQ = Tone.Frequency(BASE_NOTE).toFrequency();
const INTERVAL_DELAY = 0.2;
const PROPORTIONS = [
{ interval: 'Unison', width: 1, height: 1 },
{ interval: 'Minor 2nd', width: 15, height: 16 },
{ interval: 'Major 2nd', width: 8, height: 9 },
{ interval: 'Minor 3rd', width: 5, height: 6 },
{ interval: 'Major 3rd', width: 4, height: 5 },
{ interval: 'Perfect 4th', width: 3, height: 4 },
{
interval: 'Augmented 4th / Diminished 5th',
width: 1,
height: Math.sqrt(2),
heightLabel: '√2'
},
{ interval: 'Perfect 5th', width: 2, height: 3 },
{ interval: 'Minor 6th', width: 5, height: 8 },
{ interval: 'Major 6th', width: 3, height: 5 },
{ interval: 'Minor 7th', width: 9, height: 16 },
{ interval: 'Major 7th', width: 8, height: 15 },
{ interval: 'Octave', width: 1, height: 2 }
];
let shapeEls = Array.from(document.querySelectorAll('.shape'));
let widthLabelEl = document.querySelector('.width-label');
let heightLabelEl = document.querySelector('.height-label');
let intervalLabelEl = document.querySelector('.interval-label');
let sampler = new Tone.Sampler({
C4: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/969699/C4v3.mp3',
'D#4': 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/969699/Ds4v3.mp3',
'F#4': 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/969699/Fs4v3.mp3',
C5: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/969699/C5v3.mp3'
}).toMaster();
let piano = new Nexus.Piano('#piano', {
mode: 'impulse',
lowNote: Tone.Frequency(BASE_NOTE).toMidi(),
highNote: Tone.Frequency(BASE_NOTE).toMidi() + 13
});
let keyboard = new AudioKeys({
polyphony: 1,
rows: 1,
octaveControls: false,
velocityControls: false
});
let skipPianoTrigger = false;
function getWidthAndHeight(proportion) {
let propArea = proportion.width * proportion.height;
let areaUnit = AREA_SIZE / propArea;
let lengthUnit = Math.sqrt(areaUnit);
return {
width: lengthUnit * proportion.width,
height: lengthUnit * proportion.height
};
}
function setProportions(proportion, animate = true) {
let { width, height } = getWidthAndHeight(proportion);
let topMargin = height / 9;
let bottomMargin = topMargin * 2;
let spineMargin = width / 9;
let frontMargin = spineMargin * 2;
for (let shapeEl of shapeEls) {
shapeEl.style.width = `${width}vw`;
shapeEl.style.height = `${height}vw`;
shapeEl.style.paddingTop = `${topMargin}vw`;
shapeEl.style.paddingBottom = `${bottomMargin}vw`;
shapeEl.style.paddingLeft = `${
shapeEl === shapeEls[0] ? frontMargin : spineMargin
}vw`;
shapeEl.style.paddingRight = `${
shapeEl === shapeEls[0] ? spineMargin : frontMargin
}vw`;
}
widthLabelEl.innerHTML = proportion.widthLabel || proportion.width;
heightLabelEl.innerHTML = proportion.heightLabel || proportion.height;
intervalLabelEl.innerHTML = proportion.interval;
if (animate) {
shapeEls[0].animate(
[
{ borderLeftColor: 'rgb(34, 187, 187)' },
{ borderLeftColor: 'transparent' }
],
{ duration: 500, easing: 'ease-out' }
);
setTimeout(() => {
shapeEls[0].animate(
[
{ borderTopColor: 'rgb(34, 187, 187)' },
{ borderTopColor: 'transparent' }
],
{ duration: 500, easing: 'ease-out' }
);
}, INTERVAL_DELAY * 1000);
}
}
function play(index) {
Tone.context.resume();
// Visualize base note now
skipPianoTrigger = true;
piano.toggleIndex(0, true);
setTimeout(() => piano.toggleIndex(0, false), 100);
skipPianoTrigger = false;
// Visualize the note pressed after delay
setTimeout(() => {
skipPianoTrigger = true;
piano.toggleIndex(index, true);
skipPianoTrigger = false;
setTimeout(() => piano.toggleIndex(index, false), 100);
}, INTERVAL_DELAY * 1000);
let proportion = PROPORTIONS[index];
setProportions(proportion, true);
let frequency = (BASE_FREQ * proportion.height) / proportion.width;
sampler.triggerAttack(BASE_FREQ, Tone.now());
sampler.triggerAttack(frequency, Tone.now() + INTERVAL_DELAY);
}
Tone.Buffer.on('load', () => {
piano.on('change', v => {
if (skipPianoTrigger || !v.state) return;
let baseNote = Tone.Frequency('C4').toMidi();
let index = v.note - baseNote;
piano.toggleIndex(index, false);
play(index);
});
document.body.addEventListener('click', evt => {
if (evt.target.classList.contains('interval')) {
let index = evt.target.dataset.index;
play(+index);
evt.preventDefault();
}
});
keyboard.down(({ note }) => {
let baseIdx = Tone.Frequency(BASE_NOTE).toMidi();
if (note >= baseIdx && note <= baseIdx + 12) {
play(note - baseIdx);
}
});
window.addEventListener('resize', () => {
let pianoEl = document.querySelector('#piano');
piano.resize(pianoEl.offsetWidth, window.innerHeight * 0.15);
});
});
setProportions(PROPORTIONS[0], false);
Also see: Tab Triggers