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>Easing settings</h1>
<p>
As you resize the window width between 400px and 1400px, you'll see the values move from 0 to 100. With linear easing, they move in a predictable, smooth way, but the "in" easing values slowly accelerate while the "out" ones slowly decelerate. These settings are useful for tuning values like font-size which can create layout problems if they get too large too quickly.
</p>
<ul>
<li class="linear"></li>
<li class="in-quad"></li>
<li class="in-cubic"></li>
<li class="in-quart"></li>
<li class="in-quint"></li>
<li class="out-quad"></li>
<li class="out-cubic"></li>
<li class="out-quart"></li>
<li class="out-quint"></li>
</ul>
// strip-units required by spread mixin
// http://stackoverflow.com/questions/12328259/how-do-you-strip-the-unit-from-any-number-in-sass
@function strip-units($number)
@return $number / ($number * 0 + 1)
// pow and sqrt required by ease function
// adapted from https://github.com/at-import/Sassy-math/blob/master/sass/math.scss
@function pow($base, $exponent)
$value: $base
@if $exponent > 1
@for $i from 2 through $exponent
$value: $value * $base
@if $exponent < 1
@for $i from 0 through -$exponent
$value: $value / $base
@return $value
@function sqrt($number)
$root: 4
@for $i from 1 through 50
$root: $root - (pow($root, 2) - $number) / (2 * $root)
@return $root
// adapted from https://www.kirupa.com/forum/showthread.php?378287-Robert-Penner-s-Easing-Equations-in-Pure-JS-%28no-jQuery%29
@function ease($iteration, $start-value, $change, $total-iterations, $ease)
$progress: $iteration / $total-iterations
// value increases evenly
@if $ease == linear
@return $change * $progress + $start-value
// value increases on a curve, accelerating
@if $ease == in-quad
@return $change * $progress * $progress + $start-value
// value increases on a curve, decelerating
@if $ease == out-quad
@return -$change * $progress * ($progress - 2) + $start-value
// value accelerates sharply
@if $ease == in-cubic
@return $change * pow($progress, 3) + $start-value
// value decelerates sharply
@if $ease == out-cubic
@return $change * (pow($progress - 1, 3) + 1) + $start-value
// value accelerates more sharply
@if $ease == in-quart
@return $change * pow($progress, 4) + $start-value
// value decelerates more sharply
@if $ease == out-quart
@return -$change * (pow($progress - 1, 4) - 1) + $start-value
// value accelerates very sharply
@if $ease == in-quint
@return $change * pow($progress, 5) + $start-value
// value decelerates very sharply
@if $ease == out-quint
@return $change * (pow($progress - 1, 5) + 1) + $start-value
// spreads a property value from min to max across media queries
// $property: CSS property to set
// $property-min: min value of the property
// $property-max: max value of the property
// $dimension: media query dimension - either min-width or min-height
// $dimension-min: first media query of the chosen dimension
// $dimension-max: final media query of the chosen dimension
// $default-value: true/false (defaults to true).
// Should a default value (min for min-width/height,
// max for max-width/height) be included outside the query?
// $precision: how many pixels each media query should cover
// $ease: easing function to use when calculating value
// helpful for fine-tuning some widths in the mid-range
=spread($property, $property-min, $property-max, $dimension: min-width, $dimension-min: 400px, $dimension-max: 1400px, $default-value: true, $precision: 50px, $ease: linear)
$total-iterations: abs(strip-units(ceil(($dimension-max - $dimension-min) / $precision))) - 1
$max-dimension: $dimension == max-width or $dimension == max-height
@if $default-value
#{$property}: if($max-dimension, $property-max, $property-min)
@for $iteration from 0 through $total-iterations
$iteration: if($max-dimension, $total-iterations - $iteration, $iteration)
@media (#{$dimension}: $dimension-min + ($iteration * $precision))
#{$property}: ease($iteration, $property-min, $property-max - $property-min, $total-iterations, $ease)
// demo styles
body
font-family: sans-serif
line-height: 1.5
margin: 25px
h1
+spread(font-size, 20px, 35px)
font-weight: bold
li
background: #eee
border: #ccc 1px solid
ul
margin: 0
padding: 0
li
font-size: 14px
list-style-type: none
margin: 0 0 10px
padding: 5px
white-space: nowrap
// debugging
=spread-debug($ease: linear)
$min: 1
$max: 100
$start: 400px
$end: 1400px
$precision: 10px
width: #{$min}px
&:after
display: block
content: '#{$ease}: #{$min}'
$total-iterations: strip-units(ceil(($end - $start) / $precision)) - 1
@for $iteration from 0 through $total-iterations
@media (min-width: $start + ($iteration * $precision))
width: percentage(ease($iteration, $min, $max - $min, $total-iterations, $ease: $ease) / 100)
&:after
content: '#{$ease}: #{ease($iteration, $min, $max - $min, $total-iterations, $ease: $ease)}'
.linear
+spread-debug(linear)
.in-quad
+spread-debug(in-quad)
.out-quad
+spread-debug(out-quad)
.in-cubic
+spread-debug(in-cubic)
.out-cubic
+spread-debug(out-cubic)
.in-quart
+spread-debug(in-quart)
.out-quart
+spread-debug(out-quart)
.in-quint
+spread-debug(in-quint)
.out-quint
+spread-debug(out-quint)
Also see: Tab Triggers