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.
<a href="https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41">
<img src="https://share.marketkarma.com/58-bytes-of-CSS-to-look-great-nearly-everywhere.example.jpg" alt="58 bytes of CSS to look great nearly everywhere">
</a>
<p>When making this website, I wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:</p>
<pre>
html {
max-width: 38rem;
padding: 2rem;
margin: auto;
}
</pre>
<p>let's break this down:</p>
<blockquote>
<b>max-width: <code>38rem</code></b><br>
it appears that the default font size for most browsers is <code>16px</code>, so <code>38rem</code> is <code>608px</code>. supporting <code>600px</code> displays at a minimum seems reasonable.
</blockquote>
<blockquote>
<b>padding: <code>2rem</code></b><br>
if the display's width goes under <code>38rem</code>, then this padding keeps things looking pretty good until around <code>256px</code>. while this may seem optional, it actually hits two birds with one stone - the padding also provides sorely-needed top and bottom whitespace.
</blockquote>
<blockquote>
<b>margin: <code>auto</code></b><br>
this is really all that is needed to center the page, because main is a block element under semantic html5.
</blockquote>
<blockquote>
<b>a key insight:</b> it took me a surprising number of iterations to arrive at this point. perhaps that speaks to the fact that i know nothing about "modern" web development, or, as i'm more inclined to believe, just how hard it is to keep it simple in a world of complication
</blockquote>
<blockquote>
<b>update 1:</b> following some discussion, I've since changed the padding to <code>1.5rem</code> for a happier compromise between mobile and desktop displays.
</blockquote>
<blockquote>
<b>update 2:</b> the ch unit was brought to my attention, and I quite like it! I've since changed to <code>70ch/2ch</code>, which looks nearly the same with 2 less bytes, except that the padding is a little bit smaller (a good thing for mobile).
</blockquote>
<h2>100 Bytes of CSS to Look Great Everywhere (enhanced version)</h2>
<pre>
html {
max-width: 70ch;
padding: 3em 1em;
margin: auto;
line-height: 1.75;
font-size: 1.25em;
}
</pre>
<p>This should be simple drop-in css to look good on most displays.</p>
<p>Let's break this down. I've adapted the original text with my own commentary.</p>
<blockquote>
<b>max-width:</b> <code>70ch</code><br>
the "readable range" is usually 60-80 character widths, and CSS lets you express that directly with the <code>ch</code> unit.
</blockquote>
<blockquote>
<b>padding:</b> <code>3em 1em</code><br>
If the display's width goes under the max-width set above, then this padding prevents edge-to-edge text on mobile. We use <code>3em</code> to provide top/bottom whitespace.
</blockquote>
<blockquote>
<b>margin:</b> <code>auto</code><br>
This is really all that is needed to center the page - applied on html, because Dan's site doesnt have a semantic tag and is more likely to exist in most sites. That the top tag centers itself relative to nothing is unintuitive, but thats how browsers do.
</blockquote>
<blockquote>
<b>line-height:</b> <code>1.75</code><br>
Spacing between the lines to help increase visual clarity. Always leave line height unitless because reasons.
</blockquote>
<blockquote>
<b>font-size:</b> <code>1.5em</code><br>
I've noticed that recent design trends and screen sizes have tended toward bigger font sizes. Or maybe I'm getting old. Prefer <code>em</code> or <code>rem</code> over px if you want to let users scale it.
</blockquote>
<blockquote>
You can use <code>:root</code> instead of <code>html</code> to guarantee that there is some selector present, but its a touch too fancy for me and uses an extra character :)
</blockquote>
<h2>Optional 100 More Bytes</h2>
<pre>
h1,h2,h3,h4,h5,h6 {
margin: 3em 0 1em;
}
p,ul,ol {
color: #1d1d1d;
margin-bottom: 2em;
}
</pre>
<h2>Reference</h2>
<ul>
<li><a href="https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41">58 Bytes of CSS to Look Great Nearly Everywhere</a>
</li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS">CSS Reference on MDN</a></li>
</ul>
/*
58 bytes of CSS to look great nearly everywhere
See: https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41
When making this website, I wanted a simple, reasonable way to make it
look good on most displays. Not counting any minimization techniques,
the following 58 bytes worked well for me:
html {
max-width: 38rem;
padding: 2rem;
margin: auto;
}
let's break this down:
max-width: 38rem
it appears that the default font size for most browsers is 16px, so 38rem is 608px.
supporting 600px displays at a minimum seems reasonable.
padding: 2rem
if the display's width goes under 38rem, then this padding keeps things looking
pretty good until around 256px. while this may seem optional, it actually hits
two birds with one stone - the padding also provides sorely-needed top and bottom
whitespace.
margin: auto
this is really all that is needed to center the page, because main is a block
element under semantic html5.
a key insight: it took me a surprising number of iterations to arrive at this point.
perhaps that speaks to the fact that i know nothing about "modern" web development,
or, as i'm more inclined to believe, just how hard it is to keep it simple in a world
of complication.
update 1: following some discussion, I've since changed the padding to 1.5rem for a
happier compromise between mobile and desktop displays.
update 2: the ch unit was brought to my attention, and I quite like it! I've since
changed to 70ch/2ch, which looks nearly the same with 2 less bytes, except that the
padding is a little bit smaller (a good thing for mobile).
100 Bytes of CSS to look great everywhere (enhanced version)
html {
max-width: 70ch;
padding: 3em 1em;
margin: auto;
line-height: 1.75;
font-size: 1.25em;
}
This should be simple drop-in css to look good on most displays.
Let's break this down. I've adapted the original text with my own commentary.
max-width: 70ch
the "readable range" is usually 60-80 character widths, and CSS lets you express that
directly with the ch unit.
padding: 3em 1em
If the display's width goes under the max-width set above, then this padding prevents
edge-to-edge text on mobile. We use 3em to provide top/bottom whitespace.
margin: auto
This is really all that is needed to center the page - applied on html, because Dan's
site doesnt have a semantic tag and is more likely to exist in most sites. That the
top tag centers itself relative to nothing is unintuitive, but thats how browsers do.
line-height: 1.75
Spacing between the lines to help increase visual clarity. Always leave line height
unitless because reasons.
font-size: 1.5em
I've noticed that recent design trends and screen sizes have tended toward bigger font sizes.
Or maybe I'm getting old. Prefer em or rem over px if you want to let users scale it.
You can use :root instead of <html> to guarantee that there is some selector present,
but its a touch too fancy for me and uses an extra character :)
*/
html {
font-family: sans-serif;
font-size: 1.5em;
line-height: 1.75;
margin: auto;
max-width: 70ch;
padding: 3em 1em;
}
img {
width: 100%;
}
/* Optional 100 more bytes */
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 3em 0 1em;
}
p,
ul,
ol {
color: #1d1d1d;
margin-bottom: 2em;
}
Also see: Tab Triggers