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.
<div class="grid grid-1"><span><span></span></span></div>
<div class="grid grid-2"><span><span></span></span></div>
<div class="grid grid-3"><span><span></span></span></div>
/**
* Little helper to create a circle
* @group control-points
* @access private
* @param {Number} $size - Circle size
* @output Dimensions, margin and border-radius
*/
@mixin circle($size) {
width: $size;
height: $size;
margin: -($size/2);
border-radius: 50%;
}
/**
* Helper to position an item in absolute context
* @param {Number} $top (null) - Top offset
* @param {Number} $right (null) - Right offset
* @param {Number} $bottom (null) - Bottom offset
* @param {Number} $left (null) - Left offset
* @output `position: absolute` and offsets
*/
@mixin absolute($top: null, $right: null, $bottom: null, $left: null) {
position: absolute;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
/**
* Linear interpolation
* @author Tim Severien
* @param {Number} $a
* @param {Number} $b
* @param {Number} $p
* @return {Number}
*/
@function lerp($a, $b, $p) {
@return ($b - $a) * $p + $a;
}
/**
* Linear interpolation points
* @author Tim Severien
* @param {Number} $a
* @param {Number} $b
* @param {Number} $p
* @return {List}
*/
@function lerp-point($a, $b, $p) {
@return lerp(nth($a, 1), nth($b, 1), $p), lerp(nth($a, 2), nth($b, 2), $p);
}
/**
* Bezier Reduce
* @author Tim Severien
* @param {List} $points
* @param {Number} $p
* @return {Number}
*/
@function bezier-reduce($points, $p) {
@while length($points) > 1 {
$tmp: ();
@for $i from 1 to length($points) {
$tmp: append($tmp, lerp-point(nth($points, $i), nth($points, $i + 1), $p));
}
$points: $tmp;
}
@return nth($points, 1);
}
/**
* Bezier shadow
* @param {List} $points - List of points from Bezier
* @param {Number} $detail - Number of particles
* @output box-shadow
* @author Tim Severien
*/
@mixin bezier-shadow($points, $detail) {
$shadow: ();
@for $i from 0 to $detail {
$point: bezier-reduce($points, $i / $detail);
$shadow: append($shadow, nth($point, 1) nth($point, 2), comma);
}
box-shadow: $shadow;
}
/**
* Curve wrapper
* @access private
* @param {Map} $conf - Curve configuration
* @requires {mixin} absolute
* @output Contexte
*/
@mixin draw-curve-wrapper($conf) {
@include absolute($top: 0, $right: 0, $bottom: 0, $left: 0);
color: map-get($conf, 'color');
}
/**
* Display dots with `::after` pseudo-element
* @access private
* @param {Map} $conf - Curve configuration
* @requires {mixin} absolute
* @requires {mixin} circle
* @output Dots
*/
@mixin draw-dots($conf) {
$args: map-get($conf, 'points');
$size: map-get($conf, 'size');
&::after {
content: '';
@include circle(4px);
@include absolute($left: 0, $top: 0);
@include bezier-shadow((
0 $size,
(nth($args, 1) * $size) ((1 - nth($args, 2)) * $size),
(nth($args, 3) * $size) ((1 - nth($args, 4)) * $size),
$size 0
), map-get($conf, 'detail'));
}
}
/**
* Draw control-points as well as lines getting to those
* @access private
* @param {Map} $conf - Curve configuration
* @requires {mixin} absolute
* @requires {mixin} circle
* @output control-points
*/
@mixin draw-control-points($conf) {
$args: map-get($conf, 'points');
$size: map-get($conf, 'size');
$color: map-get($conf, 'color');
$x1: nth($args, 1);
$y1: nth($args, 2);
$x2: nth($args, 3);
$y2: nth($args, 4);
&::before {
content: '';
@include absolute;
@include circle(10px);
box-shadow:
0 $size 0 0 tomato,
$size 0 0 0 deepskyblue,
($size * $x1) $size - ($size * $y1) 0 0 tomato,
($size * $x2) $size - ($size * $y2) 0 0 deepskyblue;
}
> * {
@include absolute($top: 0, $right: 0, $bottom: 0, $left: 0);
&::before {
@include absolute($left: 0, $bottom: 0);
content: '';
width: $x1 * 100%;
height: $y1 * 100%;
background: linear-gradient(
if($x1 == 1, 90deg, 0 - atan($y1 / $x1) * 1rad),
transparent calc(50% - 1px),
$color calc(50% - 1px),
$color calc(50% + 1px),
transparent calc(50% + 1px)
);
}
&::after {
$v: abs($x2 * 100 - 100);
$w: abs($y2 * 100 - 100);
@include absolute($top: 0, $right: 0);
width: if($v == 0, 1px, $v * 1%);
height: if($w == 0, 1px, $w * 1%);
content: '';
background: linear-gradient(
if($x2 == 1, 90deg, 0 - atan(($y2 - 1) / ($x2 - 1)) * 1rad),
transparent calc(50% - 1px),
$color calc(50% - 1px),
$color calc(50% + 1px),
transparent calc(50% + 1px)
);
}
}
}
/**
* Main function, drawing a Bezier function
* @access private
* @param {Map} $conf - Curve configuration
* @output Dots and possibly control-points
*/
@mixin draw-curve($conf) {
// Print the wrapper
@include draw-curve-wrapper($conf);
// Print the dots
@include draw-dots($conf);
// Print the control-points
@if map-get($conf, 'control-points') != false {
@include draw-control-points($conf);
}
}
/**
* Draw coords system
* @access private
* @param {Map} $conf - Curve configuration
* @param {Bool} $display-name (false) - Enable/disable name display
*/
@mixin draw-system($conf) {
width: map-get($conf, 'size');
height: map-get($conf, 'size');
position: relative;
color: map-get($conf, 'color');
border-left: 2px solid;
border-bottom: 2px solid;
border-top: 1px dashed;
border-right: 1px dashed;
&::after,
&::before {
position: absolute;
bottom: -1.75em;
text-transform: uppercase;
font-size: .75em;
}
@if map-get($conf, 'informations') {
@if map-has-key($conf, 'name') {
// Display name
&::before {
content: "#{map-get($conf, 'name')}";
left: 0;
}
}
// Display values
&::after {
content: "#{map-get($conf, 'points')}";
right: 0;
}
}
// Print the curve
> * {
@include draw-curve($conf);
}
}
/**
* Draw a cubic bezier function.
* Also initialize a global variable holding the configuration.
* @access public
* @param {Number} $x1 - X of first pair
* @param {Number} $y1 - Y of first pair
* @param {Number} $x2 - X of second paid
* @param {Number} $y2 - Y of second pair
* @param {Map} $options - Map of options
*/
@mixin cubic-bezier($x1, $y1, $x2, $y2, $options: ()) {
// Default options
$options: map-merge((
// Enable/disable control-points
'control-points': true,
// Extra informations
'informations': true,
// Size of the grid
'size': 300px,
// Color scheme
'color': #999,
// Points from the curve
'points': ($x1, $y1, $x2, $y2),
// Number of dots on the curve
'detail': 30
), $options);
// Start printing things
@include draw-system($options);
}
/**
* DEMO *
**/
.grid {
margin: 1em;
float: left;
}
.grid-1 {
@include cubic-bezier(.42, 0, 1, 1, (
'name': 'ease-in'
));
}
.grid-2 {
@include cubic-bezier(.42, 0, .58, 1, (
'name': 'ease-in-out'
));
}
.grid-3 {
@include cubic-bezier(.13, .88, .5, .42);
}
Also see: Tab Triggers