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.
<h1>Common CSS Size Units</h1>
<p>There are many other units of measurement in CSS. Those listed are simply and introduction to some of the most common.</p>
<section>
<h2>Pixels</h2>
<p>The <code>px</code> unit is an absolute measurement. It is analogous to Points or Picas in print design.</p>
<p>A pixel is equal to one dot on the display device. For low resolution devices, this is equal to one literal pixel on the screen. For high resolution devices, such as Retina or 4k displays, a pixel is set so that there are roughly 96 pixels per inch of screen.</p>
<p>By default, the base size of type in the browser is set to 16px.</p>
<p>Pixels are good for situations where you want to define an exact dimension and don’t want to scale them.</p>
</section>
<section>
<h2>Rems</h2>
<p>The <code>rem</code> is a type-relative measurement such that one em is equal to the base type size (the font-size of the <code>html</code> element).</p>
<p>This means that, by default, <code>1rem</code> is equal to <code>16px</code>. Similarly, <code>2rem</code> equals <code>32px</code>.</p>
<p>Though rems are defined relative to type, they can be used to size any property.</p>
<p>Rems are a good option for scalable properties that should be sized relative to other elements and type.</p>
</section>
<section>
<h2>Ems</h2>
<p>Like rems, the <code>em</code> is a type-relative measurement, but such that one em is equal to the current type size (the type size of whatever HTML element you are targeting).</p>
<p>This means that, by default, in any base-size <code>html</code> element, <code>1em</code> is equal to <code>16px</code>. Similarly, <code>2em</code> equals <code>32px</code>.</p>
<p>However, ems are relative to the containing element, so if you set the type size of a <code>ul</code> to <code>.5em</code>, it will equal <code>8px</code>. But if you nest a second <code>ul</code> inside another <code>ul</code>, the type in the nested <code>ul</code> will be <code>.5em</code> of the first one, in other words, <code>4px</code>. If you nested yet another <code>ul</code> inside that one, you would get a type size of <code>2px</code>. This is usually not what you want and can lead to frustration.</p>
<p><strong>For most purposes, it is best to avoid ems and use rems instead.</strong> They are mentioned here because they were common before rems became available.</p>
</section>
<section>
<h2>Percentages</h2>
<p><code>%</code> units are relative units based on a 100% scale.</p>
<p>When used for things like font size, percentages are relative to the containing element type size. So setting a font size of <code>200%</code> of default body type would result in a font size equal to <code>32px</code>.</p>
<p>When used for length measurements like width or margin, percentages are relative to the containing element. So a <code>div</code> that is a direct child of <code>body</code> with a width set to <code>50%</code> would have a width equal to half of the current width of the browser window.</p>
<pre class="code-example-good language-css"><code>.example{
font-size: 90%; /*90% of parent font size*/
width: 50%; /*50% of parent width*/
}</code></pre>
<p>Percentage lengths are great for sizes that scale relative to a user’s browser size. They are very useful in fluid / responsive design.</p>
</section>
<section>
<h2>Viewport Units</h2>
<p>Viewport Units are percentages of the size of the <em>browser window</em>. There are two different viewport unit value types:</p>
<p><code>vw</code> (View Width): which is relative to the <em>width</em> of the browser window.</p>
<p><code>vh</code> (View Height): which is relative to the <em>height</em> of the browser window.</p>
<p>So in the following example:</p>
<pre class="code-example-good language-css"><code>.example{
height: 100vh;
width: 50vw;
}</code></pre>
<p>The element would be exactly as tall (<code>100%</code>) as the height of the browser window, and <code>50%</code> of the width of the window.</p>
</section>
/* ==========================================================================
Type
========================================================================== */
html {
line-height: 1.4;
}
h3 {
margin-top: 3rem;
}
ul{
padding-left: 1.2rem;
}
li {
margin-bottom: .5rem;
}
a {
color: cornflowerblue;
text-decoration: none;
}
a:hover, a:active, a:focus {
border-bottom: 1px solid cornflowerblue;
}
.callout {
font-size: 1.33rem;
}
/* ==========================================================================
Page Layout
========================================================================== */
body {
margin: 4rem auto;
max-width: 35rem;
scroll-behavior: smooth;
}
section {
border-top: 1px solid #ccc;
margin-top: 4rem;
padding-top: 2rem;
}
/* ==========================================================================
Code Examples
========================================================================== */
p > code,
li > code {
background-color: #f5f2f0;
color: #905;
display: inline-block;
margin: 0 .2rem;
padding: .15rem .25rem;
}
pre[class*=language-]{
margin-bottom: 3rem;
}
.bad {
color: firebrick;
}
.code-example-bad {
border-left: 3px solid firebrick;
}
.good {
color: rgb(102, 153, 0);
}
.code-example-good {
border-left: 3px solid rgb(102, 153, 0);
}
.rendered-example {
background-color: ghostwhite;
padding: .75rem;
}
.code-example-good + .rendered-example,
.code-example-good + .rendered-example {
margin-top: -2rem;
}
Also see: Tab Triggers