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="word">
<span class="letter" style="background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%0A%20%20%3Cdefs%2F%3E%0A%20%20%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23FFF369%22%20d%3D%22M0%200h256v256H0z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23E6D617%22%20d%3D%22M38.5%2023L49%2044H28zM100.5%2044L111%2065H90zM143%2018l10%2021h-20zM223.5%2034L234%2055h-21zM128.5%2089l10.5%2020h-21zM49%2088l10%2021H39zM100.5%20149l10.5%2021H90zM180.5%2088l10.5%2021h-21zM32.5%20210L43%20231H22zM223.5%20128l10.5%2021h-21zM110.5%20200l10.5%2020h-21zM174.5%20182l10.5%2021h-21zM223.5%20203l10.5%2021h-21zM42%20141l10%2021H32z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E")">h</span><span class="letter" style="background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%0A%20%20%3Cdefs%2F%3E%0A%20%20%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23FF9B0F%22%20d%3D%22M0%200h256v256H0z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23DE8201%22%20d%3D%22M38.5%2023L49%2044H28zM100.5%2044L111%2065H90zM143%2018l10%2021h-20zM223.5%2034L234%2055h-21zM128.5%2089l10.5%2020h-21zM49%2088l10%2021H39zM100.5%20149l10.5%2021H90zM180.5%2088l10.5%2021h-21zM32.5%20210L43%20231H22zM223.5%20128l10.5%2021h-21zM110.5%20200l10.5%2020h-21zM174.5%20182l10.5%2021h-21zM223.5%20203l10.5%2021h-21zM42%20141l10%2021H32z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E")">e</span><span class="letter" style="background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%0A%20%20%3Cdefs%2F%3E%0A%20%20%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%233FCDFF%22%20d%3D%22M0%200h256v256H0z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23037FAA%22%20d%3D%22M26.5%2040.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L26.5%2016l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM43.5%20131.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L43.5%20107l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM175%2040.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L175%2016l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8zM227.5%2098.5l-9.698%205.253%201.852-11.126-7.846-7.88%2010.843-1.624L227.5%2073l4.849%2010.123%2010.843%201.624-7.846%207.88%201.852%2011.126zM109%2091.5l-9.992%205.253%201.908-11.126-8.084-7.88%2011.172-1.624L109%2066l4.996%2010.123%2011.172%201.624-8.084%207.88%201.908%2011.126zM211%20213.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L211%20189l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8zM141.5%20180.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L141.5%20156l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM52%20222.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L52%20198l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E")">l</span><span class="letter" style="background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%0A%20%20%3Cdefs%2F%3E%0A%20%20%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%233FCDFF%22%20d%3D%22M0%200h256v256H0z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23037FAA%22%20d%3D%22M26.5%2040.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L26.5%2016l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM43.5%20131.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L43.5%20107l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM175%2040.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L175%2016l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8zM227.5%2098.5l-9.698%205.253%201.852-11.126-7.846-7.88%2010.843-1.624L227.5%2073l4.849%2010.123%2010.843%201.624-7.846%207.88%201.852%2011.126zM109%2091.5l-9.992%205.253%201.908-11.126-8.084-7.88%2011.172-1.624L109%2066l4.996%2010.123%2011.172%201.624-8.084%207.88%201.908%2011.126zM211%20213.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L211%20189l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8zM141.5%20180.75l-9.698%205.099%201.852-10.8-7.846-7.648%2010.843-1.575L141.5%20156l4.849%209.826%2010.843%201.575-7.846%207.648%201.852%2010.8zM52%20222.75l-9.992%205.099%201.908-10.8-8.084-7.648%2011.172-1.575L52%20198l4.996%209.826%2011.172%201.575-8.084%207.648%201.908%2010.8z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E")">l</span><span class="letter" style="background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20256%20256%22%3E%0A%20%20%3Cdefs%2F%3E%0A%20%20%20%20%3Cmask%20id%3D%22myMask%22%3E%0A%20%20%20%20%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%22256%22%20height%3D%22256%22%20fill%3D%22white%22%20%2F%3E%0A%20%20%3C%2Fmask%3E%0A%20%20%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%20mask%3D%22url(%23myMask)%22%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%2300C34C%22%20d%3D%22M0%200h256v256H0z%22%2F%3E%0A%20%20%20%20%3Cpath%20fill%3D%22%23009239%22%20d%3D%22M0%2013.088L50.912%2064%200%20114.912-50.912%2064zM128%2013.088L178.912%2064%20128%20114.912%2077.088%2064zM61%2077.088L111.912%20128%2061%20178.912%2010.088%20128zM192%2077.088L242.912%20128%20192%20178.912%20141.088%20128zM192-50.912L242.912%200%20192%2050.912%20141.088%200zM61-50.912L111.912%200%2061%2050.912%2010.088%200zM61%20205.088L111.912%20256%2061%20306.912%2010.088%20256zM192%20205.088L242.912%20256%20192%20306.912%20141.088%20256zM255%2013.088L305.912%2064%20255%20114.912%20204.088%2064zM1%20141.088L51.912%20192%201%20242.912-49.912%20192zM129%20141.088L179.912%20192%20129%20242.912%2078.088%20192zM256%20141.088L306.912%20192%20256%20242.912%20205.088%20192z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E")">o</span></div>
<select class="voices"></select>
<div class="instructions">Type then press enter and I will speak (for now, I work best on a computer)</div>
body {
padding: 0;
margin: 0;
font-family: "Lilita One", sans-serif;
}
.word {
position: relative;
background: #e5f7ff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
font-size: 20vw;
text-transform: uppercase;
overflow: hidden;
text-align: center;
line-height: 1;
}
input {
font-size: 1rem;
width:1rem;
}
.word:after {
content: " ";
background: rgb(255, 255, 255);
display: inline-block;
width: 0.1em;
height: .75em;
animation: flash 0.5s alternate infinite;
margin: 0 0.1em;
position: relative;
}
.letter {
position: relative;
display: inline-block;
background-clip: text;
-webkit-text-stroke: .05em white;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0.4vh 0.4vh 0.4vh rgba(0, 0, 0, 0.3));
animation-duration: 0.2s;
animation-name: slidein;
background-size: 75px 75px;
background-repeat: repeat;
min-width: 0.2em;
z-index: 1;
}
@keyframes slidein {
from {
transform: scale(2.5) rotate(10deg);
}
to {
transform: scale(1) rotate(0deg);
}
}
@keyframes flash {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Hiding this as my daughter doesn't need to change voices */
.voices {
position: absolute;
top: 1em;
left: 1em;
opacity: 0;
}
.instructions {
position: fixed;
bottom: 0.5em;
text-align: center;
width: 100%;
color: #1394ce;
}
const word = document.querySelector(".word");
const synth = window.speechSynthesis;
document.addEventListener("keyup", function (event) {
if (synth.speaking) return;
if (
event.code !== "Enter" &&
event.code !== "Backspace" &&
word.textContent.length > 8
) {
const utterThis = new SpeechSynthesisUtterance(
`Sorry, I can't handle any more letters`
);
sayThis(utterThis);
return;
}
switch (event.code) {
case "Enter":
{
const utterThis = new SpeechSynthesisUtterance(word.textContent);
sayThis(utterThis);
}
break;
case "Backspace":
word.removeChild(word.lastChild);
event.preventDefault();
break;
default:
{
const span = document.createElement("span");
const letter = event.key.toLowerCase();
span.innerHTML = String(letter);
span.className = "letter";
span.setAttribute("style", createStyleAttribute());
const utterThis = new SpeechSynthesisUtterance(letter);
sayThis(utterThis, 2);
word.appendChild(span);
}
break;
}
});
function createStyleAttribute(type) {
const colours = colorCombos[Math.floor(Math.random() * colorCombos.length)];
const svg = encodeURIComponent(
svgTemplates[Math.floor(Math.random() * svgTemplates.length)](
colours[0],
colours[1]
)
);
return `background-image:url("data:image/svg+xml,${svg}")`;
}
const svgTemplates = [
(bg, fg) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
<defs/>
<mask id="myMask">
<rect x="0" y="0" width="256" height="256" fill="white" />
</mask>
<g fill="none" fill-rule="evenodd" mask="url(#myMask)">
<path fill="${bg}" d="M0 0h256v256H0z"/>
<path fill="${fg}" d="M0 13.088L50.912 64 0 114.912-50.912 64zM128 13.088L178.912 64 128 114.912 77.088 64zM61 77.088L111.912 128 61 178.912 10.088 128zM192 77.088L242.912 128 192 178.912 141.088 128zM192-50.912L242.912 0 192 50.912 141.088 0zM61-50.912L111.912 0 61 50.912 10.088 0zM61 205.088L111.912 256 61 306.912 10.088 256zM192 205.088L242.912 256 192 306.912 141.088 256zM255 13.088L305.912 64 255 114.912 204.088 64zM1 141.088L51.912 192 1 242.912-49.912 192zM129 141.088L179.912 192 129 242.912 78.088 192zM256 141.088L306.912 192 256 242.912 205.088 192z"/>
</g>
</svg>`,
(bg, fg) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
<defs/>
<g fill="none" fill-rule="evenodd">
<path fill="${bg}" d="M0 0h256v256H0z"/>
<path fill="${fg}" d="M26.5 40.75l-9.698 5.099 1.852-10.8-7.846-7.648 10.843-1.575L26.5 16l4.849 9.826 10.843 1.575-7.846 7.648 1.852 10.8zM43.5 131.75l-9.698 5.099 1.852-10.8-7.846-7.648 10.843-1.575L43.5 107l4.849 9.826 10.843 1.575-7.846 7.648 1.852 10.8zM175 40.75l-9.992 5.099 1.908-10.8-8.084-7.648 11.172-1.575L175 16l4.996 9.826 11.172 1.575-8.084 7.648 1.908 10.8zM227.5 98.5l-9.698 5.253 1.852-11.126-7.846-7.88 10.843-1.624L227.5 73l4.849 10.123 10.843 1.624-7.846 7.88 1.852 11.126zM109 91.5l-9.992 5.253 1.908-11.126-8.084-7.88 11.172-1.624L109 66l4.996 10.123 11.172 1.624-8.084 7.88 1.908 11.126zM211 213.75l-9.992 5.099 1.908-10.8-8.084-7.648 11.172-1.575L211 189l4.996 9.826 11.172 1.575-8.084 7.648 1.908 10.8zM141.5 180.75l-9.698 5.099 1.852-10.8-7.846-7.648 10.843-1.575L141.5 156l4.849 9.826 10.843 1.575-7.846 7.648 1.852 10.8zM52 222.75l-9.992 5.099 1.908-10.8-8.084-7.648 11.172-1.575L52 198l4.996 9.826 11.172 1.575-8.084 7.648 1.908 10.8z"/>
</g>
</svg>`,
(bg, fg) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
<defs/>
<g fill="none" fill-rule="evenodd">
<path fill="${bg}" d="M0 0h256v256H0z"/>
<path fill="${fg}" d="M38.5 23L49 44H28zM100.5 44L111 65H90zM143 18l10 21h-20zM223.5 34L234 55h-21zM128.5 89l10.5 20h-21zM49 88l10 21H39zM100.5 149l10.5 21H90zM180.5 88l10.5 21h-21zM32.5 210L43 231H22zM223.5 128l10.5 21h-21zM110.5 200l10.5 20h-21zM174.5 182l10.5 21h-21zM223.5 203l10.5 21h-21zM42 141l10 21H32z"/>
</g>
</svg>`
];
const colorCombos = [
["#00C34C", "#009239"],
["#D571E1", "#72007F"],
["#3FCDFF", "#037FAA"],
["#FFF369", "#E6D617"],
["#FF9B0F", "#DE8201"]
];
function populateVoiceList(voiceSelect) {
const voices = synth.getVoices();
for (let i = 0; i < voices.length; i++) {
let option = document.createElement("option");
option.textContent = voices[i].name + " (" + voices[i].lang + ")";
if (voices[i].default) {
option.textContent += " -- DEFAULT";
}
option.setAttribute("data-lang", voices[i].lang);
option.setAttribute("data-name", voices[i].name);
voiceSelect.appendChild(option);
}
}
if (synth.onvoiceschanged !== undefined) {
synth.onvoiceschanged = () =>
populateVoiceList(document.querySelector("select"));
}
function sayThis(utterThis, rate) {
const voices = synth.getVoices();
const voiceSelect = document.querySelector("select");
const selectedOption = voiceSelect.selectedOptions[0];
let selectedVoice;
if (selectedOption) {
selectedVoice = selectedOption.getAttribute("data-name");
}
for (let i = 0; i < voices.length; i++) {
if (voices[i].name === selectedVoice) {
utterThis.voice = voices[i];
break;
}
}
utterThis.pitch = 1;
utterThis.rate = rate || 1.2;
synth.speak(utterThis);
}
document.addEventListener('click', function handleDocumentClick() {
word.innerHTML = '';
});
Also see: Tab Triggers