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.
<h1>I should scale up and down as viewport size changes, but probably not in Safari.</h1>
/* @link https://utopia.fyi/generator-mk-ii?c=320,14,1.113,1400,17,1.19,6,2, */
:root {
--fluid-min-width: 320;
--fluid-max-width: 1400;
--fluid-screen: 100vw;
--fluid-bp: calc((var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) / (var(--fluid-max-width) - var(--fluid-min-width)));
}
@media screen and (min-width: 1400px) {
:root {
--fluid-screen: calc(var(--fluid-max-width) * 1px);
}
}
:root {
--f--2-min: 11.30;
--f--2-max: 12.00;
--step--2: calc(((var(--f--2-min) / 16) * 1rem) + (var(--f--2-max) - var(--f--2-min)) * var(--fluid-bp));
--f--1-min: 12.58;
--f--1-max: 14.29;
--step--1: calc(((var(--f--1-min) / 16) * 1rem) + (var(--f--1-max) - var(--f--1-min)) * var(--fluid-bp));
--f-0-min: 14.00;
--f-0-max: 17.00;
--step-0: calc(((var(--f-0-min) / 16) * 1rem) + (var(--f-0-max) - var(--f-0-min)) * var(--fluid-bp));
--f-1-min: 15.58;
--f-1-max: 20.23;
--step-1: calc(((var(--f-1-min) / 16) * 1rem) + (var(--f-1-max) - var(--f-1-min)) * var(--fluid-bp));
--f-2-min: 17.34;
--f-2-max: 24.07;
--step-2: calc(((var(--f-2-min) / 16) * 1rem) + (var(--f-2-max) - var(--f-2-min)) * var(--fluid-bp));
--f-3-min: 19.30;
--f-3-max: 28.65;
--step-3: calc(((var(--f-3-min) / 16) * 1rem) + (var(--f-3-max) - var(--f-3-min)) * var(--fluid-bp));
--f-4-min: 21.48;
--f-4-max: 34.09;
--step-4: calc(((var(--f-4-min) / 16) * 1rem) + (var(--f-4-max) - var(--f-4-min)) * var(--fluid-bp));
--f-5-min: 23.91;
--f-5-max: 40.57;
--step-5: calc(((var(--f-5-min) / 16) * 1rem) + (var(--f-5-max) - var(--f-5-min)) * var(--fluid-bp));
--f-6-min: 26.61;
--f-6-max: 48.28;
--step-6: calc(((var(--f-6-min) / 16) * 1rem) + (var(--f-6-max) - var(--f-6-min)) * var(--fluid-bp));
}
body {
font-family: -apple-system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Helvetica,
Arial,
sans-serif,
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol";
// uncomment this to allow the type to scale on resize in Safari
// min-height: 1vw;
}
h1 {
font-size: var(--step-6);
font-weight: 500;
// min-height: 1vw;
}
/*
So there is this bug in Safari mentioned in Chris's article here: https://css-tricks.com/viewport-sized-typography/#bugs
The tl;dr is that when using viewport units to size text, and you resize the viewport, the text doesn't respond and scale like it's supposed to.
Chris' fix back then was: 'To fix this issue (allow resizing without page refresh) you need to cause a “repaint” on the element.'
Today, the bug report is marked as fixed: https://bugs.chromium.org/p/chromium/issues/detail?id=124331
However, I am now experiencing the same issue when creating fluid typography with viewport units *in CSS custom properties*
This is the most reduced test case. I have a fluid type system generated from utopia.fyi for quick reference. And the resulting font scale is directly applied to the h1. Resizing the viewport in Safari does not resize the h1 with it. Only when the page is refreshed at a specific viewport width does the corresponding width's font size apply.
I took hints from the comments here: https://css-tricks.com/snippets/css/fluid-typography/#comment-1607139
I tried all of the "fixes" mentioned in those comments. Setting font-size to 1vw on a container fixes the issue but of course has unwanted side effects.
So I ended up doing something similar (using a viewport-based unit on a container) that doesn't have a side effect: applying `min-height: 1vw` to the body element, which fixes the issue and makes the type scale fluidly on resize in Safari. If applying the min-height to the body doesn't make the type scale (I've gotten mixed results for no apparent reason!), try applying it to the h1 itself.
*/
Also see: Tab Triggers