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.
<section id="example-1" class="example-section">
<pre class="example-snippet">@include angled-edge('outside bottom', 'lower right', tomato);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-2" class="example-section">
<pre class="example-snippet">@include angled-edge('outside bottom', 'lower left', yellowgreen);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-3" class="example-section">
<pre class="example-snippet">@include angled-edge("inside bottom", "upper left", deepskyblue);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-4" class="example-section">
<pre class="example-snippet">@include angled-edge("inside bottom", "upper right", blueviolet);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-5" class="example-section">
<pre class="example-snippet-padded">@include angled-edge("outside top", "upper right", orchid);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-6" class="example-section">
<pre class="example-snippet-padded">@include angled-edge("outside top", "upper left", khaki);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-7" class="example-section">
<pre class="example-snippet">@include angled-edge("inside top", "lower left", lime);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
<hr>
<section id="example-8" class="example-section">
<pre class="example-snippet">@include angled-edge("inside top", "lower right", fuchsia);</pre>
<div class="example-container">
<div class="has-angle"></div>
</div>
</section>
//-------------------------------------------------------------------------------------
// Angled Edges v2.0.0 (https://github.com/josephfusco/angled-edges)
// Copyright 2017 Joseph Fusco
// Licensed under MIT (https://github.com/josephfusco/angled-edges/blob/master/LICENSE)
//-------------------------------------------------------------------------------------
/// Replace `$search` with `$replace` in `$string`.
///
/// @author Hugo Giraudel
/// @link http://www.sassmeister.com/gist/1b4f2da5527830088e4d
///
/// @param {String} $string - Initial string
/// @param {String} $search - Substring to replace
/// @param {String} $replace ('') - New value
/// @return {String} Updated string
///
@function ae-str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + ae-str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
/// Encode SVG to use as background.
///
/// @param {String} $string
/// @return {String} Encoded svg data
///
@function ae-svg-encode($string){
$result: ae-str-replace($string, '<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
$result: ae-str-replace($result, '%', '%25');
$result: ae-str-replace($result, '"', '\'');
$result: ae-str-replace($result, '<', '%3C');
$result: ae-str-replace($result, '>', '%3E');
@return 'data:image/svg+xml,' + $result;
}
/// Outputs pseudo content for main mixin.
///
/// @author Joseph Fusco
///
/// @param {String} $location
/// @param {Number} $height
/// @output psuedo content
///
@mixin ae-pseudo($wedge, $height, $width) {
background-image: url($wedge);
background-position: center center;
background-repeat: no-repeat;
// full width wedge - needed as Firefox ignores preserveAspectRatio="none" in this case
@if ($width == null) {
background-size: 100% 100%;
}
content: '';
height: $height * 1px;
left: 0;
position: absolute;
right: 0;
width: 100%;
z-index: 1;
}
/// Attatches an svg wedge shape to an element.
///
/// @author Joseph Fusco
///
/// @param {String} $location - 'inside top', 'outside top', 'inside bottom', 'outside bottom'
/// @param {String} $hypotenuse - 'upper left', 'upper right', 'lower left', 'lower right'
/// @param {Color} $fill
/// @param {Number} $height
/// @param {Number} $width
/// @output '::before' and/or '::after' with svg background image
///
@mixin angled-edge($location, $hypotenuse, $fill, $height: 100, $width: null) {
position: relative;
$points: (
'upper left': '0,#{$height} #{$width},#{$height} #{$width},0',
'upper right': '0,#{$height} #{$width},#{$height} 0,0',
'lower left': '0,0 #{$width},#{$height} #{$width},0',
'lower right': '0,0 #{$width},0 0,#{$height}'
);
// full width wedge
@if ($width == null) {
$points: (
'upper left': '0,#{$height} 100,#{$height} 100,0',
'upper right': '0,#{$height} 100,#{$height} 0,0',
'lower left': '0,0 100,#{$height} 100,0',
'lower right': '0,0 100,0 0,#{$height}'
);
}
// ensure $fill color is using rgb()
$fill-rgb: 'currentColor';
// capture alpha component of $fill to use with fill-opacity
$fill-alpha: alpha($fill);
$wedge: '<svg width="#{$width}" height="#{$height}" fill="#{$fill-rgb}" fill-opacity="#{$fill-alpha}"><polygon points="#{map-get($points, $hypotenuse)}"></polygon></svg>';
// full width wedge
@if ($width == null) {
$wedge: '<svg preserveAspectRatio="none" viewBox="0 0 100 #{$height}" fill="#{$fill-rgb}" fill-opacity="#{$fill-alpha}"><polygon points="#{map-get($points, $hypotenuse)}"></polygon></svg>';
}
$encoded-wedge: ae-svg-encode($wedge);
@if ($location == 'inside top') {
&::before {
@include ae-pseudo($encoded-wedge, $height, $width);
top: 0;
}
} @else if ($location == 'outside top') {
&::before {
@include ae-pseudo($encoded-wedge, $height, $width);
top: -$height * 1px;
}
} @else if ($location == 'inside bottom') {
&::after {
@include ae-pseudo($encoded-wedge, $height, $width);
bottom: 0;
}
} @else if ($location == 'outside bottom') {
&::after {
@include ae-pseudo($encoded-wedge, $height, $width);
bottom: -$height * 1px;
}
} @else {
@error 'Invalid argument for $location - must use: `inside top`, `outside top`, `inside bottom`, `outside bottom`';
}
@if (map-has-key($points, $hypotenuse) == false) {
@error 'Invalid argument for $hypotenuse - must use: `upper left`, `upper right`, `lower left`, `lower right`';
}
}
// ================================================
#example-1 {
.has-angle {
@include angled-edge("outside bottom", "lower right", tomato);
}
}
#example-2 {
.has-angle {
@include angled-edge("outside bottom", "lower left", yellowgreen);
}
}
#example-3 {
.has-angle {
@include angled-edge("inside bottom", "upper left", deepskyblue);
}
}
#example-4 {
.has-angle {
@include angled-edge("inside bottom", "upper right", blueviolet);
}
}
#example-5 {
.has-angle {
@include angled-edge("outside top", "upper right", orchid);
}
}
#example-6 {
.has-angle {
@include angled-edge("outside top", "upper left", khaki);
}
}
#example-7 {
.has-angle {
@include angled-edge("inside top", "lower left", lime);
}
}
#example-8 {
.has-angle {
@include angled-edge("inside top", "lower right", fuchsia);
}
}
// Example styles
hr {
border: 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.example-section {
margin: 100px 0;
}
.example-container {
width: 500px;
max-width: 100%;
margin: 0 auto;
}
.example-snippet {
text-align: center;
margin: 0 auto 50px;
font-size: 18px;
opacity: 0;
}
.example-snippet-padded {
@extend .example-snippet;
padding-bottom: 100px;
}
.has-angle {
box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
height: 200px;
background-color: #333;
margin-bottom: 200px;
}
@media (min-width: 550px) {
.example-snippet {
opacity: 1;
font-size: 13px;
}
}
@media (min-width: 800px) {
.example-snippet {
opacity: 1;
font-size: 18px;
}
}
Also see: Tab Triggers