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. You can use the CSS from another Pen by using it's URL and the proper URL extention.
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="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nunc velit, gravida sed justo luctus, tincidunt condimentum quam. Integer mattis fermentum auctor. Nunc magna risus, tempor at varius ac, vestibulum sit amet sem. Nunc nunc lacus, pharetra id vulputate id, imperdiet id arcu. Quisque ut convallis velit. Suspendisse ex nibh, auctor nec nulla id, feugiat vehicula lorem. Donec eget ullamcorper urna. Pellentesque magna arcu, tempus sed luctus vitae, vehicula ac urna. Nam ac sem sit amet sem ultricies lacinia. Nulla eget tellus dui. Nunc hendrerit vestibulum nisl vel ultrices. Donec lorem turpis, porttitor ac commodo non, sagittis eget ligula. Etiam hendrerit mollis est vel bibendum. Praesent efficitur interdum tincidunt.</p>
<p>Nam non fringilla risus. Sed augue neque, egestas et porttitor condimentum, ullamcorper et nulla. Phasellus interdum sollicitudin neque at accumsan. Nulla faucibus libero nisl, non mattis dolor porttitor in. Morbi felis metus, efficitur id accumsan eu, sodales sit amet nulla. Vestibulum in lectus eu augue luctus pretium id vel nunc. Nam sit amet euismod purus. Praesent mattis libero est, a sagittis tortor sodales non. Praesent finibus nisi posuere magna elementum maximus.</p>
</div>
<div class="switch-group">
<label id="Label_fontDancing" for="fontDancing">Dancing Script</label>
<div class="switch-container">
<input class="switch switch--left" type="radio" name="font" id="fontDancing" value="dancing" checked="checked">
<input class="switch switch--right" type="radio" name="font" id="fontDyslexic" value="dyslexic">
<span class="status"></span>
</div>
<label id="Label_fontDyslexic" for="fontDyslexic">Open Dyslexic</label>
</div>
<div class="switch-group">
<label id="Label_lightTheme" for="lightTheme">Light theme</label>
<div class="switch-container switch-container--theme">
<input class="switch switch--left" type="radio" name="theme" id="lightTheme" value="light" checked="checked">
<input class="switch switch--right" type="radio" name="theme" id="darkTheme" value="dark">
<span class="status"></span>
</div>
<label id="Label_darkTheme" for="darkTheme">Dark theme</label>
</div>
@import url('https://fonts.googleapis.com/css?family=Dancing+Script:400,700');
@font-face {
font-family: 'opendyslexic';
src: url('https://dyslexicfonts.com/fonts/OpenDyslexic-Regular.otf');
font-style: normal;
font-weight: normal;
}
@font-face {
font-family: 'opendyslexic';
src: url('https://dyslexicfonts.com/fonts/OpenDyslexic-Bold.ttf');
font-weight: bold;
font-style: normal;
}
:root {
--font-family: 'Dancing Script';
--bg-color: #fff;
--color: #222;
/* Radio button style */
--width: 5rem;
--height: 5rem;
--border: 10px;
--circle-diameter: 3rem;
}
* {
font-size: 16px;
font-family: var(--font-family);
color: var(--color);
background-color: var(--bg-color);
transition: all .5s ease-in-out;
}
.text {
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
width: 80vw;
height: auto;
min-height: 200px;
margin: 0 auto;
padding: 20px;
border-radius: 20px;
box-shadow: 0px 1px 3px 2px var(--color);
}
#Label_fontDancing {
font-family: 'Dancing Script', Arial, sans-serif !important;
}
#Label_fontDyslexic {
font-family: 'opendyslexic', Arial, sans-serif !important;
}
label {
width: 15ch;
text-align: center;
cursor: pointer;
}
.switch-group {
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: min-content;
margin: 20px auto;
}
/* Radio button styles */
.switch-container {
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
width: min-content;
margin: 20px auto;
border-radius: 25% / 50%;
box-shadow: 0px 2px 3px 1px #333;
}
.switch-container .switch {
position: relative;
display: inline-flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: var(--width);
height: var(--height);
margin: 0;
cursor: pointer;
}
.switch-container .switch:before {
content: '';
width: 100%;
height: 100%;
position: relative;
top: 0;
left: 0;
border: var(--border) solid #009294;
box-sizing: border-box;
background: linear-gradient(aquamarine, darkturquoise);
}
.switch-container .switch--left:before {
border-top-left-radius: 50%;
border-bottom-left-radius: 50%;
border-right: 0;
}
.switch-container .switch--right:before {
border-top-right-radius: 50%;
border-bottom-right-radius: 50%;
border-left: 0;
}
.switch-container span {
left: calc(0px + var(--border));
width: calc(var(--circle-diameter) + (var(--border)) );
height: calc(var(--circle-diameter) + (var(--border)) );
border-radius: 50%;
box-sizing: content-box;
background-color: darkturquoise;
z-index: 2;
transition: all .3s ease-in-out;
}
.switch-container .switch--left:checked ~ span {
display: block;
position: absolute;
left: calc(0px + var(--border));
box-shadow: inset 0 0 10px 5px #00b0b3, 1px 0px 5px 1px #666;
}
.switch-container .switch--right:checked ~ span {
display: block;
position: absolute;
left: calc( 100% - var(--circle-diameter) - (var(--border)*2) );
box-shadow: inset 0 0 10px 5px #00b0b3, -1px 0px 5px 1px #666;
}
.switch-container--theme .switch--left:before {
background: linear-gradient(to right, #fff, gray);
border-color: #eee;
}
.switch-container--theme .switch--right:before {
background: linear-gradient(to right, gray, #000);
border-color: #111;
}
.switch-container--theme span {
background-color: silver;
}
.switch-container--theme .switch--left:checked ~ span {
box-shadow: inset 0 0 10px 5px #8a8a8a, 1px 0px 5px 1px #666;
}
.switch-container--theme .switch--right:checked ~ span {
box-shadow: inset 0 0 10px 5px #8a8a8a, -2px 0px 2px 0px #ddd;
}
document.addEventListener("DOMContentLoaded", function(event) {
/*
let f = Cookies.get("font");
if ( (typeof f === "undefined") || (f === 'dancing') ) {
root.style.setProperty('--font-family', 'Dancing Script');
document.getElementById("fontDancing").checked = true;
document.getElementById("fontDyslexic").checked = false;
} else {
root.style.setProperty('--font-family', 'opendyslexic' );
document.getElementById("fontDyslexic").checked = true;
document.getElementById("fontDancing").checked = false;
}*/
const root = document.documentElement;
const fonts = document.querySelectorAll('input[name="font"]');
fonts.forEach((font) => {
font.addEventListener('click', changeFont)
})
function changeFont(ev) {
console.dir(ev.target.value);
switch (ev.target.value) {
case 'dancing':
root.style.setProperty('--font-family', 'Dancing Script');
//Cookies.set("font", "dancing", { expires: 30 });
break;
case 'dyslexic':
root.style.setProperty('--font-family', 'opendyslexic');
//Cookies.set("font", "dyslexic", { expires: 30 });
break;
}
}
//let t = Cookies.get("theme");
/*if ((typeof t === "undefined") || (t === 'light')) {
root.style.setProperty('--bg-color', '#fff');
root.style.setProperty('--color', '#222');
document.getElementById("lightTheme").checked = true;
document.getElementById("darkTheme").checked = false;
} else {
root.style.setProperty('--bg-color', '#222');
root.style.setProperty('--color', '#fff');
document.getElementById("darkTheme").checked = true;
document.getElementById("lightTheme").checked = false;
}*/
const themes = document.querySelectorAll('input[name="theme"]');
themes.forEach((theme) => {
theme.addEventListener('click', changeTheme)
})
function changeTheme(ev) {
switch (ev.target.value) {
case 'light':
root.style.setProperty('--bg-color', '#fff');
root.style.setProperty('--color', '#222');
//Cookies.set("theme", "light", { expires: 30 });
break;
case 'dark':
root.style.setProperty('--bg-color', '#222');
root.style.setProperty('--color', '#fff');
//Cookies.set("theme", "dark", { expires: 30 });
break;
}
}
});
Also see: Tab Triggers