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.
- const SIZE = 40
mixin cylinder(radius = 10, sides = 10, cut = [5, 10], top = true, bottom = true)
- const innerAngle = (((sides - 2) * 180) / sides) * 0.5
- const cosAngle = Math.cos(innerAngle * (Math.PI / 180))
- const side = 2 * radius * Math.cos(innerAngle * (Math.PI / 180))
//- Use the cut to determine how many sides get rendered and from what point
.cylinder(style=`--side: ${side}; --sides: ${sides}; --radius: ${radius};` class!=attributes.class)
if top
.cylinder__end.cylinder__segment.cylinder__end--top
if bottom
.cylinder__end.cylinder__segment.cylinder__end--bottom
- const [start, end] = cut
- let i = start
while i < end
.cylinder__side.cylinder__segment(style=`--index: ${i};`)
- i++
mixin cuboid()
.cuboid(class!=attributes.class)
if block
block
- let s = 0
while s < 6
.cuboid__side
- s++
.scene
svg(role='img' viewbox='0 0 24 24' xmlns='http://www.w3.org/2000/svg')
title DigitalOcean
path(d='M12.04 0C5.408-.02.005 5.37.005 11.992h4.638c0-4.923 4.882-8.731 10.064-6.855a6.95 6.95 0 014.147 4.148c1.889 5.177-1.924 10.055-6.84 10.064v-4.61H7.391v4.623h4.61V24c7.86 0 13.967-7.588 11.397-15.83-1.115-3.59-3.985-6.446-7.575-7.575A12.8 12.8 0 0012.039 0zM7.39 19.362H3.828v3.564H7.39zm-3.563 0v-2.978H.85v2.978z')
.logo(style=`--size: ${SIZE}`)
.logo__arc.logo__arc--inner
+cylinder((SIZE * 0.61) * 0.5, 80, [0, 60], false, false).cylinder-arc.cylinder-arc--inner
.logo__arc.logo__arc--outer
+cylinder((SIZE * 1) * 0.5, 100, [0, 75], true, true).cylinder-arc.cylinder-arc--outer
.logo__square.logo__square--one
+cuboid().square-cuboid.square-cuboid--one
.logo__square.logo__square--two
+cuboid().square-cuboid.square-cuboid--two
.logo__square.logo__square--three
+cuboid().square-cuboid.square-cuboid--three
:root
--size 40
--bg hsl(0, 0%, 98%)
--hue 215
--rotation-y -75deg
--rotation-x -14deg
--remove 0
.cuboid
width 100%
height 100%
position relative
// 1 is the top and go t, r, back, l, f, b
&__side
filter brightness(var(--b, 1))
position absolute
&__side:nth-of-type(1)
--b 1.1
height calc(var(--depth, 20) * 1vmin)
width 100%
top 0
transform translate(0, -50%) rotateX(90deg)
&__side:nth-of-type(2)
--b 0.9
height 100%
width calc(var(--depth, 20) * 1vmin)
top 50%
right 0
transform translate(50%, -50%) rotateY(90deg)
&__side:nth-of-type(3)
--b 0.5
width 100%
height calc(var(--depth, 20) * 1vmin)
bottom 0
transform translate(0%, 50%) rotateX(90deg)
&__side:nth-of-type(4)
--b 1
height 100%
width calc(var(--depth, 20) * 1vmin)
left 0
top 50%
transform translate(-50%, -50%) rotateY(90deg)
&__side:nth-of-type(5)
--b 0.8
height 100%
width 100%
transform translate3d(0, 0, calc(var(--depth, 20) * 0.5vmin))
top 0
left 0
&__side:nth-of-type(6)
--b 1.2
height 100%
width 100%
transform translate3d(0, 0, calc(var(--depth, 20) * -0.5vmin)) rotateY(180deg)
top 0
left 0
.cylinder
--bg 'hsl(%s, 100%, 50%)' % var(--hue)
height 100%
width 100%
position relative
&__segment
filter brightness(var(--b, 1))
background var(--bg, hsl(0, 80%, 50%))
position absolute
top 50%
left 50%
// Top
&__end
--b 1.2
--end-coefficient 0.5
height 100%
width 100%
border-radius 50%
opacity calc(1 - var(--remove))
transform translate3d(-50%, -50%, calc((var(--depth, 0) * var(--end-coefficient)) * 1vmin))
transition opacity 0.2s
&__end--bottom
--b 0.8
--end-coefficient -0.5
&__side
--b 0.89
height calc(var(--depth, 30) * 1vmin)
width calc(var(--side) * 1vmin)
transform translate(-50%, -50%) rotateX(90deg) rotateY(calc((var(--index, 0) * 360 / var(--sides)) * 1deg)) translate3d(50%, 0, calc((var(--radius) * (var(--cylinder-projection, 100) / 100)) * 1vmin))
*
*:after
*:before
box-sizing border-box
transform-style preserve-3d
touch-action none
body
background var(--bg)
min-height 100vh
display grid
place-items center
.scene
background none
position relative
// transform translate3d(0, 0, 100vmin) rotateX(-16deg) rotateY(28deg) rotateX(90deg) rotateZ(calc(var(--coefficient-x, 0) * var(--rotation-y, 0deg))) rotateX(calc(var(--coefficient-y, 0) * var(--rotation-x, 0deg)))
transform translate3d(0, 0, 100vmin) rotateX(-16deg) rotateY(28deg) rotateX(90deg)
transform translate3d(0, 0, 100vmin) rotateX(-16deg) rotateY(28deg) rotateX(90deg) rotateX(calc(var(--tilt-x, 0) * 1deg))
.logo
height calc(var(--size) * 1vmin)
width calc(var(--size) * 1vmin)
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
// &__cap
// position absolute
// height calc(var(--size) * 0.1925vmin)
// width calc(var(--size) * 0.1975vmin)
// background 'hsl(%s, 100%, 50%)' % var(--hue)
// &--top
// top 50%
// transform translate(0, -50%) rotateX(90deg)
// &--bottom
// bottom 0
// right 50%
// transform translate(50%, 0) rotateY(90deg)
&__arc
border-radius 50%
position absolute
height calc(var(--diameter) * 1%)
width calc(var(--diameter) * 1%)
transform translate(-50%, -50%)
top 50%
left 50%
transition opacity 0.2s
&--inner
--diameter 61
&--outer
--diameter 100
&__square
position absolute
height calc(var(--height, 0) * 1%)
width calc(var(--width, 0) * 1%)
left calc(var(--x, 0) * 1%)
top calc(var(--y, 0) * 1%)
transform 'translate3d(calc((%s * %s) * 1%), calc((%s * %s) * 1%), calc((%s * %s) * 1vmin))' % (var(--coefficient-x, 0) var(--offset-x, 0) var(--coefficient-y) var(--offset-y, 0) var(--coefficient-x) var(--offset-z, 0))
z-index 3
&--one
--height 19.25
--width 19.25
--x 31
--y 61.5
--offset-x 50
--offset-y 10
--offset-z -2
// transform 'translate3d(calc(min(0, calc(%s * %s)) * 1%), calc((%s * %s) * 1%), calc((%s * %s) * 1vmin))' % (var(--coefficient-x, 0) var(--offset-x, 0) var(--coefficient-y) var(--offset-y, 0) var(--coefficient-x) var(--offset-z, 0))
&--two
--height 14.75
--width 14.75
--x 16
--y 80.75
--offset-x -35
--offset-y -20
--offset-z 4
&--three
--height 12.5
--width 12.5
--x 3.5
--y 68.25
--offset-x 25
--offset-y 30
--offset-z -6
.square-cuboid
opacity 0.5
.cuboid__side
background 'hsl(%s, 100%, 50%)' % var(--hue)
&--one
--depth calc((var(--size) * 0.1925) * 0)
&--two
--depth calc((var(--size) * 0.1475) * 0)
&--three
--depth calc((var(--size) * 0.125) * 0)
.cylinder-arc
--depth calc((var(--size) * 0.1925) * var(--cylinder-depth, 1))
transform translate(-50%, -50%) rotate(-90deg)
position absolute
top 50%
left 50%
&--outer
.cylinder__end--top
.cylinder__end--bottom
background-color transparent
border-width calc(var(--size) * 0.1975vmin)
border-style solid
border-color 'hsl(%s, 100%, 50%)' % var(--hue)
--clip polygon(50% 0, 50% 50%, 0 50%, 0 100%, 100% 100%, 100% 0)
-webkit-clip-path var(--clip)
clip-path var(--clip)
import { GUI } from 'https://cdn.skypack.dev/dat.gui'
const CONFIG = {
depth: 1,
projection: 100,
remove: false,
tilt: 0,
}
const CTRL = new GUI()
CTRL.add(CONFIG, 'depth', 0, 5, 0.1)
.name('Depth (vmin)')
.onChange(depth =>
document.documentElement.style.setProperty('--cylinder-depth', depth)
)
CTRL.add(CONFIG, 'projection', 0, 150, 1)
.name('Projection(%)')
.onChange(projection =>
document.documentElement.style.setProperty('--cylinder-projection', projection)
)
CTRL.add(CONFIG, 'remove')
.name('Remove Ends?')
.onChange(remove =>
document.documentElement.style.setProperty('--remove', remove ? 1 : 0)
)
CTRL.add(CONFIG, 'tilt', 0, 100, 1)
.name('Tilt(deg)')
.onChange(tilt =>
document.documentElement.style.setProperty('--tilt-x', tilt * -1)
)
Also see: Tab Triggers