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.
<body id="page" class="show-variable-fonts">
<div class="wrapper">
<div class="support support--vf">
<span class="status-info__vf">The <strong>Variable Font</strong> is displayed.</span>
<span class="status-info__fallback">The <strong>fallback fonts</strong> are shown.</span>
<a id="toggle" class="switch switch-variable-off" onclick="toggleFonts()">Switch to </a>
</div>
<div class="support support--static">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/814870/icon-cross.svg" class="icon"> The <strong>static fallback fonts</strong> are displayed, because your browser does not support variable fonts.
</div>
<main>
<h1>A Variable Font implemented with fallback fonts</h1>
<p><strong>Resize the browser window</strong> and see how the typeface on this page changes. On narrow screens the text is condensed to fit more words into one line, on bigger screens the body text gets wider. The heading is always at least slightly condensed to make a more compact appearance. This is done by only using <strong>one single font file.</strong></p>
<p>How does it work? This page is set in the beautiful typeface Venn by Dalton Maag. It’s a variable font that can fluidly change its weight and width. If the browser does not support variable fonts, the <strong>fallback web fonts</strong> of Venn will be shown in Regular and Bold and there will be no condensed text. Toggle between the variable font and the fallback fonts to see the differences.</p>
<p><strong>If you want to find out more about this</strong> read my article <a href="https://www.zeichenschatz.net/typografie/implementing-a-variable-font-with-fallback-web-fonts.html" target="_blank">Implementing a variable font with fallback web fonts</a>. It will give you step by step instructions and explain all the details.</p>
</main>
</div>
<footer class="wrapper footer">
Variable Font Demo by <a href="http://zeichenschatz.net" target="_blank">Oliver Schöndorfer</a>, Typeface: <a href="https://daltonmaag.com/library/venn" target="_blank">Venn by Dalton Maag</a>
</footer>
</body>
/* ###############
### LOAD FONTS ###
################## */
/* Load the variable font */
@font-face {
font-family: 'Venn VF';
src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/814870/Venn_VF.woff2') format('woff2-variations'), /* for Safari */
url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/814870/Venn_VF.woff2') format('woff2'); /* for all other supporting browsers */
font-display: fallback;
font-weight: 300 800; /* prevents faux bolding in Safari */
font-stretch: 75 125;
}
/* Load the static fonts as a fallback */
@font-face {
font-family: 'Venn';
src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/814870/Venn_Regular.woff2') format('woff2');
font-display: fallback; /* has nothing to do with the fact that this is the fallback font */
}
@font-face {
font-family: 'Venn';
src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/814870/Venn_Bold.woff2') format('woff2');
font-display: fallback; /* has nothing to do with the fact that this is the fallback font */
font-weight: 700;
}
/* ########################
### TYPOGRAPHIC STYLING ###
########################### */
body {
font-family: 'Venn', sans-serif;
color: #222;
margin: 0 1rem 2.4rem;
}
@supports (font-variation-settings: normal) {
body {
font-family: 'Venn VF', sans-serif;
}
}
.wrapper {
max-width: 50rem;
margin: 0 auto;
}
/* ### Mobile first styling for narrow screens ### */
h1 {
color: #37187c;
margin: 0 0 0.5em;
font-size: 1.8rem;
line-height: 1.1;
font-variation-settings: "wdth" 75, "wght" 700; /* older browsers will just ignore this */
font-weight: 700; /* to prevent faux bolding of variable font */
}
p {
font-size: 1.1rem;
line-height: 1.5;
font-variation-settings: "wdth" 88; /* older browsers will just ignore this */
}
strong {
font-variation-settings: "wdth" 88, "wght" 700;
font-weight: 700; /* to prevent faux bolding of variable font */
}
/* ### Big smart phone ### */
@media screen and (min-width: 460px) and (max-width: 699px) {
h1 {
font-variation-settings: "wdth" 85;
}
p {
line-height: 1.6;
font-variation-settings: "wdth" 95;
}
strong {
font-variation-settings: "wdth" 95, "wght" 700;
}
}
/* ### Tablet and above ### */
@media screen and (min-width: 700px) {
h1 {
font-size: 2.5rem;
font-variation-settings: "wdth" 90;
}
p {
font-size: 1.2rem;
line-height: 1.7;
font-variation-settings: "wdth" 100;
}
strong {
font-variation-settings: "wdth" 100, "wght" 700;
}
}
/*
#################################################################
Everything below this is only styling for the info box and toggle
#################################################################
*/
/* #################
### SUPPORT INFO ###
#################### */
.support {
min-width: 14rem;
color: #fff;
padding: 1rem;
text-align: left;
margin: 0 0 2rem;
border-radius: 5px;
border-top-left-radius: 0;
border-top-right-radius: 0;
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
transition: all 0.2s ease-out;
}
.icon {
width: 1.5rem;
margin-bottom: -0.3rem;
}
.support--vf {
display: none;
background: #339949;
}
.support--static {
display: inline-block;
background: #E0011B;
}
@supports (font-variation-settings: normal) {
.support--vf {
display: inline-block;
}
.support--static {
display: none;
}
}
.show-fallback-fonts .status-info__vf {
display: none;
}
.show-fallback-fonts .support--vf {
background: #E0011B;
}
.show-variable-fonts .status-info__fallback {
display: none;
}
/* ###########
### FOOTER ###
############## */
.footer {
margin-top: 6rem;
font-size: 0.8rem;
color: #555;
}
.footer a:link,
.footer a:visited {
color: inherit;
transition: 0.3s ease-out all;
text-decoration-skip: ink;
}
.footer a:hover,
.footer a:active {
color: #9f5440;
text-decoration: none;
}
@supports (font-variation-settings: normal) {
.show-fallback-fonts {
font-family: 'Venn', sans-serif;
}
}
.switch {
display: block;
cursor: pointer;
text-decoration: underline;
}
.switch:hover{
color: inherit;
}
.switch:active{
text-decoration: none;
}
.switch-variable-off:after {
content: "fallback fonts";
}
.switch-variable-on:after {
content: "variable font";
}
/* ##########
### LINKS ###
############# */
a:link,
a:visited {
color: #37187c;
text-decoration-skip: ink;
transition: all 0.2s ease-out;
}
a:hover,
a:focus,
a:active {
color: #9f5440;
text-decoration: none;
}
function toggleFonts() {
var myPageClasses = document.getElementById("page").classList;
if (myPageClasses.contains("show-fallback-fonts")) {
myPageClasses.remove("show-fallback-fonts");
} else {
myPageClasses.add("show-fallback-fonts");
}
if (myPageClasses.contains("show-variable-fonts")) {
myPageClasses.remove("show-variable-fonts");
} else {
myPageClasses.add("show-variable-fonts");
}
var mySwitchClasses = document.getElementById("toggle").classList;
if (mySwitchClasses.contains("switch-variable-on")) {
mySwitchClasses.remove("switch-variable-on");
} else {
mySwitchClasses.add("switch-variable-on");
}
if (mySwitchClasses.contains("switch-variable-off")) {
mySwitchClasses.remove("switch-variable-off");
} else {
mySwitchClasses.add("switch-variable-off");
}
}
Also see: Tab Triggers