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.
<div>*</div>
div {
width: 100vmin;
height: 100vmin;
--primary: hsl(346, 70%, 50%);
--secondary: hsl(196, 70%, 95%);
--light: hsla(196, 90%, 98%, .4);
--angle-start: 20vmin;
--angle-degrees: 35deg;
--background-angle-gradient: linear-gradient(var(--angle-degrees), transparent calc(var(--angle-start) - var(--angle-offset, 2vmin)), var(--secondary) var(--angle-start), transparent calc(var(--angle-start) + var(--angle-offset, 2vmin)));
/* You can have multiple gradients in one variable... that can then be in a fuller multiple value `background` */
--background-box:
linear-gradient(90deg, var(--primary) 40%, var(--primary) 60%),
linear-gradient(to bottom, var(--primary) 4%, transparent 4%, transparent 96%, var(--primary) 96%),
linear-gradient(to right, var(--primary) 4%, var(--secondary) 4%, var(--secondary) 96%, var(--primary) 96%);
--background-box-width: 40vmin;
--background-box-height: 20%;
--background-circle: radial-gradient(circle at 66.7% 66.7%, var(--secondary) 0, var(--secondary) 5vmin, transparent var(--radial-offset, 10vmin));
--background-back: linear-gradient(to bottom, var(--light), var(--light));
background-image:
var(--background-angle-gradient),
var(--background-box),
var(--background-circle);
background-repeat: no-repeat;
background-position:
center center,
calc(var(--box-x, 20vmin) + 10vmin) 23%,
var(--box-x, 20vmin) 20%,
var(--box-x, 20vmin) 20%,
center center;
background-size:
auto,
calc(var(--background-box-width) / 2) calc(var(--background-box-height) / 2),
var(--background-box-width) var(--background-box-height),
var(--background-box-width) var(--background-box-height),
auto;
color: rgba(0,0,0,0);
text-shadow: -46vmin -40vmin .25vmin var(--sparkle-color-1),
-48vmin -13vmin .5vmin var(--sparkle-color-2),
-44vmin 13vmin .85vmin var(--sparkle-color-3),
-46vmin 40vmin .15vmin var(--sparkle-color-4),
46vmin -40vmin .65vmin var(--sparkle-color-1),
44vmin -13vmin .5vmin var(--sparkle-color-2),
48vmin 13vmin .75vmin var(--sparkle-color-3),
46vmin 40vmin .35vmin var(--sparkle-color-4),
-40vmin -46vmin .95vmin var(--sparkle-color-1),
-14vmin -48vmin .25vmin var(--sparkle-color-2),
14vmin -44vmin .55vmin var(--sparkle-color-3),
40vmin -46vmin .5vmin var(--sparkle-color-4),
-40vmin 46vmin .65vmin var(--sparkle-color-1),
-15vmin 44vmin .15vmin var(--sparkle-color-2),
15vmin 48vmin .95vmin var(--sparkle-color-3),
41vmin 46vmin .65vmin var(--sparkle-color-4);
transition: text-shadow 700ms ease-in-out;
font-size: 5vmin;
display: flex;
justify-content: center;
align-items: center;
}
body {
overflow: hidden;
background: hsl(196, 70%, 12%);
display: flex;
justify-content: center;
align-items: flex-end;
min-height: 100vh;
}
var div = document.querySelector('div');
var style = div.style;
//The following variable names match the appropriate CSS Variables
var anglePosition = parseFloat(getComputedStyle(div).getPropertyValue('--angle-start')); //You can get the default value from the default CSS...
var angleOffset = 2; //... or use your own starting value
var angleDegrees = parseFloat(getComputedStyle(div).getPropertyValue('--angle-degrees'));
var boxX = 20;
var radialOffset = 10;
//Additional variables used in the requestAnimationFrame
var goUp = false;
var STEP_AMOUNT = .1;
var MAX_VMIN_VALUE = 32;
var MIN_VMIN_VALUE = 14;
requestAnimationFrame(move);
//This examples keeps things simple with linear easing. You could certainly make these ease in, out, etc, and you could also make them respond to user interaction
function move() {
//Setup new angled gradient value, adjusting both the background position and the gradient's color stop offset
anglePosition = anglePosition + (goUp ? STEP_AMOUNT : -STEP_AMOUNT);
angleOffset = angleOffset + ((goUp ? STEP_AMOUNT : -STEP_AMOUNT) / 4);
angleDegrees = angleDegrees + ((goUp ? STEP_AMOUNT : -STEP_AMOUNT) * 1.25);
style.setProperty('--angle-start', anglePosition + 'vmin');
style.setProperty('--angle-offset', angleOffset + 'vmin');
style.setProperty('--angle-degrees', angleDegrees + 'deg');
//New x position value for the 2 gradients that make the box. This could alternately be done inside the gradients instead of the `background-position` var
boxX = boxX + ((goUp ? -STEP_AMOUNT : STEP_AMOUNT) / .8);
style.setProperty('--box-x', boxX + 'vmin');
//New color stop distance for the radial gradient
radialOffset = radialOffset + ((goUp ? -STEP_AMOUNT : STEP_AMOUNT));
style.setProperty('--radial-offset', radialOffset + 'vmin');
//change directions periodically
if (anglePosition > MAX_VMIN_VALUE || anglePosition < MIN_VMIN_VALUE) {
goUp = !goUp;
}
requestAnimationFrame(move);
}
//Make the sparkles sparkle. Combines with a CSS Transition for the fade in and out effect
//Could be simpler if Firefox allowed calc inside rgba... but the following will have broader support
setInterval(function() {
style.setProperty('--sparkle-color-1', getColor());
style.setProperty('--sparkle-color-2', getColor());
style.setProperty('--sparkle-color-3', getColor());
style.setProperty('--sparkle-color-4', getColor());
}, 700);
function getColor() {
return 'rgba(240, 249, 208, ' + (Math.random() * .8) + ')';
}
Also see: Tab Triggers