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.
mixin flaps()
.package__flap.package__flap--top
.package__flap.package__flap--bottom
mixin side()
.package__side(class=`package__side--${attributes.class || 'side'}`)
+flaps()
if block
block
.scene
.package__wrapper
.package
+side()(class="main")
+side()(class="tabbed")
+side()(class="extra")
+side()(class="flipped")
:root
--bg hsl(180, 20%, 92%)
--face-1 hsl(28, 41%, 57%)
--face-2 hsl(29, 58%, 66%)
--face-3 hsl(30, 69%, 70%)
--face-4 hsl(31, 82%, 74%)
--face-5 hsl(30, 72%, 70%)
--face-6 hsl(21, 75%, 28%)
--flap-one hsl(32, 76%, 70%)
--flap-two hsl(32, 76%, 74%)
--flap-three hsl(32, 72%, 72%)
--flap-four hsl(32, 78%, 76%)
--flap-five hsl(32, 78%, 72%)
*
*:after
*:before
box-sizing border-box
transform-style preserve-3d
body
background var(--bg)
min-height 100vh
display grid
place-items center
perspective 100vmin
overflow hidden
.scene
transform rotateX(calc(var(--rotate-x, -24) * 1deg)) rotateY(calc(var(--rotate-y, -32) * 1deg)) rotateX(90deg)
*
*:after
transition transform calc(var(--speed, 0.2) * 1s) calc((var(--step, 1) * var(--delay, 0.2)) * 1s)
.package__side--extra
--step 1
.package__side--tabbed
--step 2
.package__side--flipped
.package__side--tabbed:after
--step 3
.package__side--extra > .package__flap--bottom
--step 4
.package__side--tabbed > .package__flap--bottom
--step 5
.package__side--main > .package__flap--bottom
--step 6
.package__side--flipped > .package__flap--bottom
--step 7
.package__wrapper
--step 8
.package
--step 9
.package__side--extra > .package__flap--top
--step 12
.package__side--tabbed > .package__flap--top
--step 13
.package__side--main > .package__flap--top
--step 14
.package__side--flipped > .package__flap--top
--step 15
.package
height calc(var(--height, 20) * 1vmin)
width calc(var(--width, 20) * 1vmin)
transform-origin 50% 100%
transform rotateX(calc(var(--packaged, 0) * -90deg))
&__wrapper
transform translate(0, calc(var(--packaged, 0) * -100%))
&__flap
width 99.5%
height 49.5%
background var(--flap-bg, var(--face-4))
position absolute
left 50%
transform translate(-50%, 0) rotateX(calc((var(--packaged, 0) * var(--rotation, -90)) * 1deg))
&--top
transform-origin 50% 100%
bottom 100%
&--bottom
--rotation 90
top 100%
transform-origin 50% 0%
&__side
height calc(var(--height, 20) * 1vmin)
position absolute
top 0
&:not(.package__side--main)
&:not(.package__side--main):after
transform rotateY(calc((var(--packaged, 0) * var(--rotation, 90)) * 1deg))
&--extra
&--tabbed
& > .package__flap--bottom
top 98%
& > .package__flap--top
bottom 98%
&--main
background var(--face-5)
left 50%
top 50%
transform translate(-50%, -50%) translate3d(0, 0, 0)
width calc(var(--width, 20) * 1vmin)
& > .package__flap
height calc(var(--depth, 20) * 0.495vmin)
&--tabbed
--rotation -90
left 100%
background var(--face-2)
width calc(var(--depth, 20) * 1vmin)
transform-origin 0% 50%
& > .package__flap
height calc(var(--width, 20) * 0.495vmin)
--flap-bg var(--face-3)
&:after
content ''
position absolute
left 99.5%
height 100%
width 10%
background var(--face-3)
$clip = polygon(0 0%, 100% 20%, 100% 80%, 0 100%)
clip-path $clip
-webkit-clip-path $clip
transform-origin 0% 50%
&--extra
right 100%
background var(--face-2)
width calc(var(--depth, 20) * 1vmin)
transform-origin 100% 50%
& > .package__flap
height calc(var(--width, 20) * 0.495vmin)
--flap-bg var(--face-3)
&--flipped
background var(--face-3)
right 100%
width calc(var(--width, 20) * 1vmin)
transform-origin 100% 50%
& > .package__flap
height calc(var(--depth, 20) * 0.495vmin)
--flap-bg var(--face-4)
&--extra > .package__flap.package__flap--top
--flap-bg var(--flap-one)
&--extra > .package__flap.package__flap--bottom
--flap-bg var(--flap-two)
&--tabbed > .package__flap.package__flap--bottom
--flap-bg var(--flap-three)
&--flipped > .package__flap.package__flap--bottom
--flap-bg var(--flap-four)
&--main > .package__flap.package__flap--top
--flap-bg var(--flap-five)
import { GUI } from 'https://cdn.skypack.dev/dat.gui'
const CONFIG = {
'rotate-x': -24,
'rotate-y': -32,
'packaged': false,
}
const UPDATE = () => Object.keys(CONFIG).forEach(key => document.documentElement.style.setProperty(`--${key}`, typeof CONFIG[key] === 'boolean' ? CONFIG[key] ? 1 : 0 : CONFIG[key]))
const CTRL = new GUI()
CTRL.add(CONFIG, 'rotate-x', -90, 90, 1).onChange(UPDATE).name('Rotate X')
CTRL.add(CONFIG, 'rotate-y', -90, 90, 1).onChange(UPDATE).name('Rotate Y')
CTRL.add(CONFIG, 'packaged').onChange(UPDATE).name('Package?')
UPDATE()
Also see: Tab Triggers