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.
.scene
- const height = 400
- const width = 150
- const inRange = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min
mixin lava(amount)
.lava-lamp__lava
svg
ellipse.blob.blob--top(cx='35', cy='0', rx='35', ry='10')
ellipse.blob.blob--bottom(cx='75', cy='270', rx='75', ry='10')
- for (let i = 0; i < amount; i++)
- const speed = inRange(8, 50)
- const delay = inRange(0, 10) - 10
- const height = inRange(30, 100)
- const width = inRange(30, 100)
- const skewX = inRange(0, 10) - 5
- const skewY = inRange(0, 10) - 5
- const rotation = inRange(0, 360)
- const x = inRange(0, 150)
- const direction = Math.random() > 0.5 ? 'alternate' : 'alternate-reverse'
circle.blob(r=(height / 2), cx=x, cy='400', style=`--skewX: ${skewX}; --skewY: ${skewY}; --height: ${height}; --speed: ${speed}; --delay: ${delay}; --direction: ${direction};`)
.lava-lamp(style=`--height: ${height}; --width: ${width}`)
.lava-lamp__main
.lava-lamp__glass
+lava(3)
+lava(4)
+lava(2)
+lava(1)
.lava-lamp__base
svg(style='position: absolute; left: 100%')
defs
filter(id=`goo`)
feGaussianBlur(in='SourceGraphic', stdDeviation='10', result='BLUR')
feColorMatrix(in='BLUR', mode='matrix', values='1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7', result='GOO')
feBlend(in='SourceGraphic', in2=`goo`)
*
box-sizing border-box
body
background darken(#8c14fc, 80%)
min-height 100vh
.scene
align-items center
display flex
justify-content center
width 100vw
position relative
height 100vh
overflow-x hidden
$lamp = #000
// $shadow = #bf55ec
// $core = #663399
// $lava = lighten(#9f5afd, 30%)
// $lava-bg = radial-gradient(circle at 50% 50%, $core 25%, $shadow)
$shadow = #19b5fe
$core = #3a539b
$lava = #29f1c3
$lava-bg = radial-gradient(circle at 50% 50%, $core 25%, $shadow)
img
position absolute
top 50%
left 50%
transform translate(-69.5%, -26%)
opacity .2
height 1300px
.lava-lamp
height calc(var(--height) * 1px)
width calc(var(--width) * 1px)
position relative
&:after
content ''
height 500px
width 500px
position absolute
background radial-gradient(circle at 50% 50%, $shadow, transparent 60%)
top 45%
left 50%
z-index 4
transform translate(-50%, -50%)
filter blur(10px)
opacity .5
&:before
content ''
height 25%
width 300%
border-radius 100%
background radial-gradient(ellipse at 50% 50%, $shadow, transparent 60%)
position absolute
top 85%
left 50%
transform translate(-50%, 0)
opacity .5
filter blur(10px)
&__main
border-radius 50% 50% 50% 50% / 60% 60% 40% 40%
width 100%
height 100%
position relative
overflow hidden
z-index 2
&:after
&:before
background $lamp
content ''
height 12%
left 0
position absolute
width 100%
&:after
top 0
&:before
bottom 0
height 26%
&__glass
background $lava-bg
border-radius 50% / 10%
overflow hidden
height 70%
left 0
position absolute
top 10%
width 100%
z-index 2
&__base
height 20%
width 100%
position absolute
bottom 0
overflow hidden
border-radius 0 0 50% 50% / 0 0 35% 35%
&:before
content ''
background $lamp
border-radius 50% 50% 50% 50% / 60% 60% 40% 40%
position absolute
top -60%
height calc(var(--height) * 1px)
width calc(var(--width) * 1px)
&__lava
border-radius 50% / 10%
height 100%
overflow hidden
position absolute
width 100%
filter url('#goo')
svg
height 280px
width 150px
.blob
animation-delay calc(var(--delay) * 1s)
animation-direction var(--direction)
animation-duration calc(var(--speed) * 1s)
animation-iteration-count infinite
animation-name blob
animation-timing-function linear
fill $lava
transform-box fill-box
&--bottom
&--top
animation none
&--top
animation sway 20s infinite linear
@keyframes sway
50%
transform translate(50%, 0)
@keyframes blob
from
transform skew(calc(var(--skewX) * 1deg), calc(var(--skewY) * 1deg)) translate(0, 0)
to
transform skew(calc(var(--skewX) * 1deg), calc(var(--skewY) * 1deg)) translate(0, calc((400 + (var(--height) * 2)) * -1px))
// NOPE
/**
* Possible by randomly generating CSS variables
* within our markup code.
* Those variables define the characteristics of
* each blob.
*/
Also see: Tab Triggers