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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 id="spritz">
<div><input type="tel" value="250" id="wpm"/><label>WPM</label>
</div>
<p>Reading will complete in <span id="completeTime"></span></p>
<div id="redicle">
<div></div>
</div>
<div id="controls">
<button id="fastback" data-label="Move back one sentence"><i class="fa fa-fast-backward" aria-hidden="true"></i></button>
<button id="stepback" data-label="Move back one word"><i class="fa fa-step-backward" aria-hidden="true"></i></button>
<button id="stop" data-label="Stop reading"><i class="fa fa-stop" aria-hidden="true"></i></button>
<button id="play" data-label="Start / Pause reading"><i class="fa fa-play" aria-hidden="true"></i></button>
<button id="stepforward" data-label="Move forward one word"><i class="fa fa-step-forward" aria-hidden="true"></i></button>
<button id="fastforward" data-label="Move forward one sentence"><i class="fa fa-fast-forward" aria-hidden="true"></i></button>
</div>
</header>
<textarea id="text">Clinton Deploys Vowels to Bosnia
(originally appeared in The Onion, Number One In News)
Cities of Sjlbvdnzv, Grzny to Be First Recipients
Before an emergency joint session of Congress yesterday, President Clinton announced US plans to deploy over 75,000 vowels to the war-torn region of Bosnia. The deployment, the largest of its kind in American history, will provide the region with the critically needed letters A,E,I,O and U, and is hoped to render countless Bosnian names more pronounceable.
"For six years, we have stood by while names like Ygrjvslhv and Tzlynhr and Glrm have been horribly butchered by millions around the world," Clinton said. "Today, the United States must finally stand up and say 'Enough.' It is time the people of Bosnia finally had some vowels in their incomprehensible words. The US is proud to lead the crusade in this noble endeavour."
The deployment, dubbed Operation Vowel Storm by the State Department, is set for early next week, with the Adriatic port cities of Sjlbvdnzv and Grzny slated to be the first recipients. Two C-130 transport planes, each carrying over 500 24-count boxes of "E's," will fly from Andrews Air Force Base across the Atlantic and airdrop the letters over the cities.
Citizens of Grzny and Sjlbvdnzv eagerly await the arrival of the vowels. "My God, I do not think we can last another day," Trszg Grzdnjkln, 44, said. "I have six children and none of them has a name that is understandable to me or to anyone else. Mr. Clinton, please send my poor, wretched family just one 'E.' Please."
Said Sjlbvdnzv resident Grg Hmphrs, 67: "With just a few key letters, I could be George Humphries. This is my dream."
The airdrop represents the largest deployment of any letter to a foreign country since 1984. During the summer of that year, the US shipped 92,000 consonants to Ethiopia, providing cities like Ouaouoaua, Eaoiiuae, and Aao with vital, life-giving supplies of L's, S's and T's.
</textarea>
@import url(https://fonts.googleapis.com/css?family=Montserrat|Roboto+Slab);
@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css);
*,*:before,*:after{
box-sizing:border-box;
}
body {
margin: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
#spritz{
font-family:Montserrat;
background:#000;
color:#fff;
text-align:center;
padding:1em;
}
#spritz > div:first-child{
border:1px solid #212121;
display:inline-block;
padding:6px 12px;
text-align:center;
border-radius:2px;
}
#wpm{
width:3ch;
display:inline-block;
text-align:left;
font-family:inherit;
margin-right:1ex;
font-size:1em;
border:0;
background:none;
color:inherit;
}
#text{
flex: 1;
font-family:"Roboto Slab";
font-size:inherit;
padding:1em;
}
#controls button{
background:#424242;
border:0;
border-radius:3px;
display:inline-block;
min-width:2.5em;
min-height:2.5em;
cursor:pointer;
padding:.5em;
transition:.218s ease;
margin:0 6px;
}
input:focus, button:focus{
outline:0;
}
#controls button:hover{
background-color:#5677fc;
color:#fff;
}
#controls button{
position:relative;
}
#controls button[data-label]:hover:before{
content:"";
border-width:12px;
border-style:solid;
border-color:transparent;
border-bottom-color:#222;
position:absolute;
top:100%;
margin-top:-12px;
z-index:10;
left:50%;
margin-left:-12px;
}
#controls button[data-label]:hover:after{
content:attr(data-label);
position:absolute;
background:#222;
color:#fff;
font-family:Montserrat;
padding:6px;
top:100%;
left:50%;
transform:translateX(-50%);
white-space: nowrap;
margin-top:6px;
z-index:10;
border-radius:3px;
box-shadow:0 0 10px 0 rgba(50, 50, 50, .5);
}
#redicle{
position:relative;
border-top:4px solid #fff;
border-bottom:4px solid #fff;
width:10em;
height:3.3ch;
font-size:2em;
margin:12px auto;
}
#redicle:before,
#redicle:after{
content:"";
border-left:4px solid #fff;
position:absolute;
height:.4ch;
left:38%;
}
#redicle:before{
top:0;
}
#redicle:after{
bottom:0;
}
#redicle span{
font-weight:400;
display:block;
position:absolute;
top:.5ch;
color:#fff;
}
#redicle span b{
font-weight:400;
color:#f00;
}
#redicle > div{
height:100%;
width:100%;
margin-left:0;
transition-property:width, margin-left;
transition-timing-function:linear, linear;
}
#redicle > div.quotes{
font-style: initial;
}
#redicle > div.quotes:before{
content:"\"";
position:absolute;
left:0;
font-size:1.5em;
}
#redicle > div.quotes:after{
content:"\"";
position:absolute;
right:0;
font-size:1.5em;
}
#redicle > div.parenthesis{
opacity:1;
}
#redicle > div.parenthesis:before{
content:"(";
position:absolute;
left:0;
font-size:1.5em;
}
#redicle > div.parenthesis:after{
content:")";
position:absolute;
right:0;
font-size:1.5em;
}
var words;
var sentences;
var t;
//elements
var redicle = document.getElementById('redicle').firstElementChild;
var wpm = document.getElementById('wpm');
var copy = document.getElementById('text');
var complete = document.getElementById('completeTime');
function getORP(word){
var orp = Math.ceil((word.length - 1) / 4);
if(/\W/.test(word[orp])) orp = orp - 1;
return orp;
}
function processText(text) {
sentences = [0];
var parenthesis = false;
var quotes = false;
words = text.replace(/((?=\w{15,})(\w{7})|(?!^\w{1,14})$)/g, '$1- ')
.match(/[^\s-]+-?/g)
.filter(function(v){return /[\w]/.test(v)})
.map(function(v, i, arr) {
if (/[.?!]/.test(v) && arr[i + 1]) sentences.push(i + 1);
return {
content: v.replace(/[\(|\)\"]/g, ''),
orp: getORP(v),
parenthesis: checkP(v),
quotes: checkQ(v)
}
});
function checkP(word) {
word = word.replace(/[.?!,;:]/g, '');
if (parenthesis && /\)$/.test(word)) {
parenthesis = false;
return true;
}
if (!parenthesis && /^\(/.test(word)) {
if (/\)$/.test(word)) {
return true
};
parenthesis = true;
}
return parenthesis;
};
function checkQ(word) {
word = word.replace(/[.?!,;:]/g, '');
if (quotes && /\"$/.test(word)) {
quotes = false;
return true;
}
if (!quotes && /^\"/.test(word)) {
if (/\"$/.test(word)) return true;
quotes = true;
}
return quotes;
};
completeTime();
};
function wrap(bool, type) {
var classes = redicle.className.split(' ');
if (bool) {
if (classes.indexOf(type) < 0) classes.push(type);
} else {
if (classes.indexOf(type) >= 0) classes.splice(classes.indexOf(type), 1);
}
redicle.className = classes.join(' ');
};
processText(copy.value);
function applyWord(index) {
redicle.innerHTML = '';
var word = words[index];
var percent = 38 / 100;
var span = document.createElement('span');
span.dataset.index = index;
span.innerHTML = word.content.replace(/./g, function(char, i) {
return i === getORP(word.content) ? '<b>' + char + '</b>' : char;
});
redicle.appendChild(span);
//adjust location
var orp = span.getElementsByTagName('b')[0];
var center = Math.ceil(orp.offsetWidth / 2) - 2; //2px is half marker width
span.style.left = (redicle.parentNode.offsetWidth * percent) - (orp.offsetLeft + center) + 'px';
//wrap
wrap(word.parenthesis, 'parenthesis');
wrap(word.quotes, 'quotes');
};
function completeTime(){
complete.innerText = (words.length / wpm.value).toFixed(1) + ' minutes';
};
function redicleIndex() {
return redicle.firstElementChild ? parseInt(redicle.firstElementChild.dataset.index) : 0;
}
//controls
copy.addEventListener('blur', function() {
pause();
processText(copy.value);
});
document.getElementById('fastback').addEventListener('click', function() {
pause();
var index = redicleIndex();
var goto = sentences.filter(function(v) {
return v < index;
}).pop() || 0;
applyWord(goto);
});
document.getElementById('stepback').addEventListener('click', function() {
pause();
var index = redicleIndex();
if (index !== 0) applyWord(index - 1);
});
document.getElementById('stop').addEventListener('click', function() {
pause();
redicle.innerHTML = '';
redicle.className = '';
});
document.getElementById('play').addEventListener('click', function() {
var classname = this.childNodes[0].className;
if (classname.indexOf('play') >= 0) {
var avgtime = 60000 / wpm.value;
this.childNodes[0].className = classname.replace('play', 'pause');
begin(avgtime);
} else {
pause();
};
});
function begin(time){
redicle.style.transitionDuration = (time*3) + 'ms';
redicle.style.width = 0;
redicle.style.marginLeft = '38%';
redicle.style.backgroundColor = 'rgba(50,50,50,.8)';
var b = setTimeout(function(){
clearTimeout(b);
redicle.removeAttribute('style');
play(redicleIndex(), time);
}, parseFloat(redicle.style.transitionDuration));
}
document.getElementById('stepforward').addEventListener('click', function() {
pause();
var index = redicleIndex();
if (index !== words.length - 1) applyWord(index + 1);
});
document.getElementById('fastforward').addEventListener('click', function() {
pause();
var index = redicleIndex();
var goto = sentences.filter(function(v) {
return v > index;
}).shift() || sentences.shift();
applyWord(goto);
});
wpm.addEventListener('input', function(){
this.style.width = this.value !== '' ? this.value.length + 'ch' : '1ch';
completeTime();
});
var exceptions = [
'ave.',
'blvd.',
'ct.',
'dr.',
'eg.',
'etc.',
'ie.',
'mr.',
'mrs.',
'mo.',
'rd.',
'sr.',
'st.',
'ste.',
'tpk.'
]
function play(index, time) {
var ms = time;
var word = words[index].content;
if (/[,:;]$/.test(word)) ms = ms * 1.5;
if (/\d+[^,:;.!?]{0,}$/.test(word)) ms = ms * 1.5;
if (/[.?!]$/.test(word) && exceptions.indexOf(word.toLowerCase()) < 0) ms = ms * 3;
applyWord(index);
t = setTimeout(function() {
if (words[index + 1]){
play(index + 1, time);
} else {
pause();
redicle.innerHTML = '';
redicle.className = '';
}
}, ms);
}
function pause() {
clearTimeout(t);
var play = document.getElementById('play');
var classname = play.childNodes[0].className;
if (classname.indexOf('pause') >= 0) play.childNodes[0].className = classname.replace('pause', 'play');
}
Also see: Tab Triggers