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="container">
<h1>Dithered CSS Gradients</h1>
<p>Solid to solid color | Grainy blend only | Reduced banding | Pure CSS Gradients<br><span>Click/tap & hold on items for more colors</span></p>
<div class="item item--sphere item--color1"></div>
<div class="item item--sphere item--color2"></div>
<div class="item item--sphere item--color3"></div>
<div class="item item--sphere item--color4"></div>
<div class="item item--pudding item--color5"></div>
<div class="item item--droplet item--color6"></div>
<div class="item item--vase item--color7"></div>
<div class="item item--egg item--color8"></div>
<div class="item item--cell"></div>
</div>
@import url(https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700,300);
$size: 130px;
$scale: 1.05;
$border-radius: $size / 2;
$grad-position: 100% 0;
$grad-start: 25%;
$grad-stop: 65%;
$duration: 3.5s;
$noise: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAABBCAMAAAC5KTl3AAAAgVBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABtFS1lAAAAK3RSTlMWi3QSa1uQOKBWCTwcb6V4gWInTWYOqQSGfa6XLyszmyABlFFJXySxQ0BGn2PQBgAAC4NJREFUWMMV1kWO5UAQRdFk5kwzs/33v8Cunr7ZUehKAdaRUAse99ozDjF5BqswrPKm7btzJ2tRziN3rMYXC236humIV5Our7nHWnVdFOBojW2XVnkeu1IZHNJH5OPHj9TjgVxBGBwAAmp60WoA1gBB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sTHPm5IA6bc5ha0gaGkoEttXuxU11B2dOJ65/Q08tEF1+Y9cr2Nh/VECfQ33GyvR/gsdN1LuIeLpKMCAF2yRr769g9/4aJLZNRI71m2S91+Kp+Q0zubTcxoG2/6gm1Q79wkMj2XNO2ui7nWw8ULtu27CCvqTGX2PffD+xcwgh/TrOKvGZMM5jRFGDTn4NO/lwnDR/GY/waDZtkWDUPI0O8ztcFVqp6r2ZW+2bvkJ3raptYagFqu95VdIaml2CIp6CKets34x+fH2C+zH4cVFO7vj+6k2FU39PtRhWluYeZ3gDz1TLB9K2v7SD9gJU1qDxoRDrAWcrFGLyndhdtd0505+gEP79adK8fmFCWNYC+ahzVNcRH79E8dA1iqX/N0qq22xcOc20ALxLDspEj4QCFBQMgaIwoKbxr0Bd7Sbws6GiRK6tqoPfpiCle23axejRLyO1I+ahsEpWrzT5ZsCyS5RcY9jMfENFxSnhKsrfW8JHH6/rdQUMfmQPT3Uz9gY0C/pu1yuCnrPUvio0a1qMEosA/EwIzzid7cqsAAAAASUVORK5CYII=');
@mixin dithered-gradient($position, $start, $stop, $color) {
background: radial-gradient(circle at $position, transparent $start, $color $stop);
mask: $noise, radial-gradient(circle at $position, transparent $start, #000 ($stop + 10%));
}
@mixin radial-gradient-item($position, $start, $stop, $color) {
background: repeat-x $position / 50% 100% radial-gradient(circle at 50% 0, transparent $start, $color $stop);
}
@mixin item-unicolor($color) {
color: $color;
&::before { @include radial-gradient-item($grad-position, $grad-start, $grad-stop, $color); }
}
@mixin item-bicolor($color1, $color2) {
background-color: $color2;
@include item-unicolor($color1);
}
@mixin item-tricolor($color1, $color2, $color3) {
color: $color3;
background-color: $color1;
&::before { @include radial-gradient-item($grad-position, 15%, 45%, $color2); }
&::after { @include radial-gradient-item($grad-position, 50%, 75%, $color3); }
}
$light: #ffecd2;
$dark: #222;
$color1: #7f5fff;
$color2: #fa709a;
$color3: #ff9673;
$color4: #fec440;
$color5: #72f9c1;
$color6: #5193ff;
$color7: #fd2472;
$color8: #5e21d6;
$color9: #e7627d;
$color10: #3d1635;
html {
height: 100%;
font-family: 'Roboto Condensed', sans-serif;
color: $dark;
}
body {
margin: 0;
position: relative;
display: flex;
justify-content: center;
align-items: center;
min-height: 100%;
background-color: #effeff;
&::before, &::after {
content: "";
position: absolute;
top: 0; left: 0;
z-index: -1;
display: block;
width: 100%;
height: 100%;
}
&::before {
@include dithered-gradient(50%, 30%, 60%, #6cc8ff)
}
&::after {
mask-image: $noise, linear-gradient(45deg, #000 0%, transparent 25%, transparent 75%, #000 100%);
background: linear-gradient(45deg, #6d6dff 10%, transparent 25%, transparent 75%, #fbffbe 90%);
}
}
h1 {
margin: 0 0 10px 0;
text-transform: uppercase;
}
p {
margin: 0;
}
span {
line-height: 1.8em;
color: $color2;
}
.container {
box-sizing: border-box;
max-width: 1024px;
padding: 20px;
text-align: center;
}
.item {
position: relative;
display: inline-block;
margin: 20px 35px;
width: $size; height: $size;
background-color: #ffecd2;
box-shadow: -5px 18px 25px -15px;
overflow: hidden;
transition: all 0.2s ease-out;
cursor: pointer;
image-rendering: pixelated;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-tap-highlight-color: transparent;
&::before {
content: "";
position: absolute;
display: block;
top: 0; left: 0;
height: 100%; width: 400%;
mask: $noise, radial-gradient(circle at 50% 0, transparent 5%, #000 ($grad-stop + 15%)) 0 0 / 50% 100%;
}
&:hover {
transform: scale($scale);
&.item::before, &.item::after {
animation: spin-round $duration linear infinite;
}
}
&:active {
animation: hue-rotate 7s infinite;
}
&--sphere {
border-radius: 50%;
}
&--egg {
width: $size * 0.77;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
&--pudding {
width: $size; height: $size;
border-radius: 50% 50% 10% 10%;
&::after {
content: "";
position: absolute;
top: 0;
display: block;
top: 0; left: 0;
height: 100%; width: 400%;
mask: $noise, radial-gradient(circle at 50% 0, transparent 55%, #000 85%) 0 0 / 50% 100%;
}
}
&--droplet {
width: $size * 0.77; height: $size * 0.77;
border-radius: 5% 100% 50% 65% / 5% 65% 50% 100%;
transform: rotate(45deg);
box-shadow: 5px 18px 25px -15px;
&:hover {
transform: rotate(45deg) scale($scale);
}
}
&--vase {
position: relative;
width: floor($size * 0.62); height: $size;
border-radius: 40% 40% 70% 70% / 100%;
&::after {
content: "";
position: absolute;
top: 0;
display: block;
top: 0; left: 0;
height: 100%; width: 400%;
mask: $noise, radial-gradient(circle at 50% 0, transparent 55%, #000 90%) 0 0 / 50% 100%;
}
}
&--cell {
width: $size; height: $size;
border-radius: 50%;
color: #ff4d5d;
background: radial-gradient(circle at 100% 0, #ffa878 5%, transparent 75%), #ff4d5d;
&::before {
top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: ceil($size * 0.69); height: ceil($size * 0.69);
border-radius: 50%;
background: radial-gradient(circle at 0 75%, transparent 20%, #98000e $grad-stop);
mask: $noise, radial-gradient(circle at 50%, transparent $grad-start, #000 ($grad-stop + 10%));
}
&:hover {
animation: spin-flat-thick $duration linear infinite;
&.item--cell::before {
animation: spin-flat $duration linear infinite;
}
&:active {
animation: spin-flat-thick $duration linear infinite, hue-rotate 7s linear infinite;
}
}
}
&--color1 {
@include item-unicolor($color1);
}
&--color2 {
@include item-unicolor($color2);
}
&--color3 {
@include item-unicolor($color3);
}
&--color4 {
@include item-unicolor($color4);
}
&--color5 {
@include item-tricolor($light, $color9, $color10);
}
&--color6 {
@include item-bicolor($color6, $color5);
}
&--color7 {
@include item-tricolor($color4, $color7, $color8);
}
&--color8 {
@include item-unicolor($dark);
}
}
@keyframes spin-round {
from { transform: translateX(0); }
to { transform: translateX(-50%); }
}
@keyframes spin-flat {
0% { transform: translate(-50%, -50%) rotateY(0); }
25% { transform: translate(-50%, -50%) rotateY(90deg); }
50% { transform: translate(-50%, -50%) rotateY(180deg); }
75% { transform: translate(-50%, -50%) rotateY(270deg); }
100% { transform: translate(-50%, -50%) rotateY(360deg); }
}
@keyframes spin-flat-thick {
0% { transform: scale($scale) rotateY(0); }
25% { transform: scale($scale) rotateY(75deg); }
50% { transform: scale($scale) rotateY(0); background: radial-gradient(circle at 0 0, #ffa878 5%, transparent 75%), #ff4d5d; }
75% { transform: scale($scale) rotateY(75deg); }
100% { transform: scale($scale) rotateY(0); background: radial-gradient(circle at 100% 0, #ffa878 5%, transparent 75%), #ff4d5d; }
}
@keyframes hue-rotate {
from { filter: hue-rotate(360deg); }
to { filter: hue-rotate(0deg); }
}
Also see: Tab Triggers