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.
<head>
<!-- MDC Web -->
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Mono" rel="stylesheet" />
</head>
<body class="mdc-typography">
<h1 id="title" class="mdc-typography--headline1">Fonts – a dish best served variable</h1>
<p class="mdc-typography--body1">A beta version of the API is now available at <code>fonts.googleapis.com/css2</code>. The new API will allow variable fonts’ full potential to be realized.</p>
<h2 id="feedback" class="mdc-typography--headline2">Feedback</h2>
<p class="mdc-typography--body1">We’d love to hear from you. Tweet us <a href="https://twitter.com/googlefonts">@googlefonts</a> or reach out on our <a href="https://github.com/google/fonts/">GitHub</a>.</p>
<h2 id="disclaimer" class="mdc-typography--headline2">Disclaimer</h2>
<p class="mdc-typography--body1">This version of the API isn’t completely stable. It’s best for experimental work while we document the new endpoint.</p>
<h2 id="syntax" class="mdc-typography--headline2">Syntax</h2>
<p class="mdc-typography--body1">The new endpoint is very strict about accepting requests.
<ul>
<li>List axes alphabetically</li>
<li>Axis value groups (i.e. tuples) need to be sorted numerically</li>
<li>Tuples can’t overlap or touch (e.g. wght 400..500 and 500..600)</li>
</ul>
<h3 id="requests" class="mdc-typography--headline3">Sample requests</h3>
<div class="mdc-data-table">
<table class="mdc-data-table__table sample-requests" aria-label="Sample requests">
<thead>
<tr class="mdc-data-table__header-row">
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Font(s)</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Request</th>
</tr>
</thead>
<tbody class="mdc-data-table__content">
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Roboto (default)</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Roboto</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Roboto Bold</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Roboto:wght@700</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Roboto Regular & Bold</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Roboto:wght@400;700</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Roboto Bold & Bold Italic</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,700;1,700</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Crimson Pro [wght 200-900]</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@200..900</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Crimson Pro Italic [wght 200-900]</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@1,200..900</td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Crimson Pro Bold Italic & [wght 200-900]</td>
<td class="mdc-data-table__cell">https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,200..900;1,700</td>
</tr>
</tbody>
</table>
</div>
<h2 id="fonts" class="mdc-typography--headline2">Available variable fonts</h2>
<p class="mdc-typography--body1">Updated August 28, 2019</p>
<div class="mdc-data-table vf-table">
<table class="mdc-data-table__table" aria-label="Variable Font offerings">
<thead>
<tr class="mdc-data-table__header-row">
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Family</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Style</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Axis</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Min</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Max</th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">Demo</th>
</tr>
</thead>
<tbody class="mdc-data-table__content">
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Comfortaa</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">300</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Crimson Pro</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">200</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">900</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Crimson Pro</td>
<td class="mdc-data-table__cell">italic</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">200</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">900</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Dosis</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">200</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">800</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Fira Code</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">300</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Hepta Slab</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">1</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">900</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Kreon</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">300</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Literata</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">400</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Literata</td>
<td class="mdc-data-table__cell">italic</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">400</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Markazi Text</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">400</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Oswald</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">200</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
<tr class="mdc-data-table__row">
<td class="mdc-data-table__cell">Quicksand</td>
<td class="mdc-data-table__cell">normal</td>
<td class="mdc-data-table__cell">wght</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">300</td>
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">700</td>
<td class="mdc-data-table__cell demo"></td>
</tr>
</tbody>
</table>
</div>
<a id="bottom"></a>
</body>
body {
font-family: Roboto;
font-synthesis: none;
padding: 0 1em 1em;
}
code {
font-family: Roboto Mono;
}
.vf-table .demo {
min-width: 25em;
font-size: 2.625em;
}
.vf-table .demo::before {
content: 'Lorem ipsum';
}
function getAxisSpec(style, axis, min, max) {
if (style === 'normal') {
return `${axis}@${min}..${max}`;
}
if ('ital' < axis) {
return `ital,${axis}@1,${min}..${max}`;
}
return `${axis},ital@${min}..${max},1`;
}
function loadFont(family, style, axis, min, max) {
const axisSpec = getAxisSpec(style, axis, min, max);
const linkEl = document.createElement('link');
linkEl.rel = 'stylesheet';
linkEl.href = `https://fonts.googleapis.com/css2?family=${family}:${axisSpec}`;
document.getElementsByTagName('head')[0].appendChild(linkEl);
}
function getCssProperties(axis, value) {
if (axis === 'wght') {
return `font-weight: ${value};`
}
return '';
}
function buildAnimation(family, style, axis, min, max) {
const animName = family.toLowerCase().replace(' ', '') + style + axis + min + 'to' + max;
const minCssProperties = getCssProperties(axis, min);
const maxCssProperties = getCssProperties(axis, max);
const styleEl = document.createElement('style');
styleEl.type = 'text/css';;
styleEl.innerHTML = `
@keyframes ${animName} {
0% {${minCssProperties}}
50% {${maxCssProperties}}
100% {${minCssProperties}}
}`;
document.getElementsByTagName('head')[0].appendChild(styleEl);
return animName;
}
function linkifyFamily(familyEl) {
const family = familyEl.textContent;
familyEl.innerHTML = `<a href="https://fonts.google.com/specimen/${family}" target="_blank">${family}</a>`;
}
function init() {
document.querySelectorAll('.sample-requests tbody tr').forEach(row => {
const requestEl = row.children[1];
const request = requestEl.textContent;
console.log(requestEl);
requestEl.innerHTML = `<a href="${request}">${request}</a>`;
});
document.querySelectorAll('.vf-table tbody tr').forEach(row => {
const family = row.children[0].textContent;
const style = row.children[1].textContent.toLowerCase();
const axis = row.children[2].textContent;
const min = parseInt(row.children[3].textContent);
const max = parseInt(row.children[4].textContent);
const demoElement = row.children[5];
const animName = buildAnimation(family, style, axis, min, max);
demoElement.style.fontFamily = family;
demoElement.style.fontStyle = style;
demoElement.style.animation = `${animName} 5s infinite`;
loadFont(family, style, axis, min, max);
linkifyFamily(row.children[0]);
});
}
init();
// AUTO-SCROLL ANIMATION
const frames = [
{
target: document.getElementById('title'),
delay: 3000,
},
// {
// target: document.getElementById('feedback'),
// delay: 1000,
// },
// {
// target: document.getElementById('disclaimer'),
// delay: 000,
// },
// {
// target: document.getElementById('syntax'),
// delay: 3000,
// },
{
target: document.getElementById('requests'),
delay: 3000,
},
// {
// target: document.getElementById('fonts'),
// delay: 2000,
// },
{
target: document.getElementById('bottom'),
delay: 5000,
},
]
function scrollAnim(i) {
const frame = frames[i];
frame.target.scrollIntoView({behavior:'smooth'});
setTimeout(() => scrollAnim((i+1)%frames.length), frame.delay);
}
// scrollAnim(0);
Also see: Tab Triggers