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 cross()
svg.x(class!=attributes.class style!=attributes.style viewBox="0 0 100 100")
path(d="M 80 20 L 20 80" stroke-dasharray="100" stroke-width="10" stroke-linecap="round")
path(d="M 20 20 L 80 80" stroke-dasharray="100" stroke-width="10" stroke-linecap="round")
mixin naught()
svg.o(class!=attributes.class style!=attributes.style viewBox="0 0 100 100")
circle(r="30" cx="50" cy="50" stroke-dasharray="200" stroke-width="10" stroke-linecap="round" fill="none")
form.game
- for (let i = 0; i < 9; i++)
- const x = i % 3
- const y = Math.floor(i / 3)
input(type='checkbox' id=`x-${i}`)
+cross()(class="game__piece" style=`--x: ${x}; --y: ${y}`)
input(type='checkbox' id=`o-${i}`)
+naught()(class="game__piece" style=`--x: ${x}; --y: ${y}`)
.board
- const DELAYS = [0, 3, 1, 2]
- for (let l = 0; l < 4; l++)
- const rotate = l % 2
- const shift = 2 % (l + 1) ? 1 : -1
svg.board__line(viewBox="0 0 10 300" style=`--rotate: ${rotate}; --shift: ${shift}; --delay: ${DELAYS[l]};`)
path(d="M 5 5 L 5 295" stroke-dasharray="300" stroke-width="10" stroke-linecap="round")
- for (let i = 0; i < 9; i++)
.board__cell
label(for=`x-${i}`)
+cross()(class="ghost")
label(for=`o-${i}`)
+naught()(class="ghost")
.game__result.game__result--x.result
.result__content
.result__title X Wins!
+cross()(class="result__winner")
.game__result.game__result--o.result
.result__content
.result__title O Wins!
+naught()(class="result__winner")
.game__result.game__result--draw.result
.result__content
.result__title Draw...
button(type="reset" title="Reset Board")
svg.reset(viewBox="0 0 24 24")
path(d="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z")
@font-face
font-family Cyber
src url("https://assets.codepen.io/605876/Blender-Pro-Bold.otf")
font-display swap
*
box-sizing border-box
:root
--size 50vmin
--cell-size calc(var(--size) / 3)
--bg hsl(210, 50%, 15%)
--cross hsl(280, 80%, 70%)
--naught hsl(150, 80%, 70%)
--line hsl(0, 0%, 90%)
--draw-speed 0.2s
@media(prefers-reduced-motion)
:root
--draw-speed 0s
body
background var(--bg)
min-height 100vh
display grid
place-items center
margin 0
font-family 'Cyber', sans-serif
overflow hidden
color var(--line)
label
position absolute
height 100%
width 100%
input
position fixed
left 100%
button
position absolute
top 125%
background transparent
appearance none
cursor pointer
height 5vmin
width 5vmin
min-height 48px
min-width 48px
border 0
outline transparent
padding 0
left 50%
transform translate(-50%, 0)
transition transform var(--draw-speed)
svg
stroke none
stroke-width 0
&:hover
transform translate(-50%, -4%)
&:active
transform translate(-50%, 2%) scale(0.8)
svg
filter drop-shadow(0 0 1vmin var(--stroke)) brightness(1.2)
stroke var(--stroke, black)
circle
path
animation draw var(--draw-speed) calc(var(--delay, 0) * var(--draw-speed)) ease-in both
path:nth-of-type(2)
--delay 1
@keyframes draw
to
stroke-dashoffset 0
.game
position relative
&__piece
display none
position absolute
left calc(var(--x) * var(--cell-size))
top calc(var(--y) * var(--cell-size))
&__result
display none
position absolute
width calc(var(--size) * 1.5)
height calc(var(--size) * 1.5)
transform translate(-50%, -50%)
top 50%
left 50%
.result
z-index 10
backdrop-filter blur(25px)
&__content
animation flyIn var(--draw-speed) var(--draw-speed) ease-in backwards
height 40%
width 40%
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
border-radius 15%
background hsla(210, 30%, 20%, 0.8)
align-items center
display flex
justify-content center
flex-direction column
font-weight bold
font-size 2rem
box-shadow 0 3vmin 2.5vmin -2.5vmin hsl(0, 0%, 0%)
@keyframes flyIn
0%
transform translate(-50%, 150%) scale(0)
opacity 0
.reset
height 100%
fill var(--line)
.board
height var(--size)
width var(--size)
display grid
grid-template-columns repeat(3, 1fr)
grid-template-rows repeat(3, 1fr)
place-items center
&__line
--stroke var(--line)
position absolute
height var(--size)
width calc(var(--size) * 0.05)
left 50%
top 50%
transform translate(-50%, -50%) rotate(calc(var(--rotate, 0) * -90deg)) translateX(calc(var(--shift, 0) * ((var(--size) / 3) * 0.5)))
path
stroke-dashoffset 300
&__cell
height var(--cell-size)
position relative
width var(--cell-size)
.o
.x
height var(--cell-size)
width var(--cell-size)
z-index 2
.o
--stroke var(--naught)
transform rotateX(180deg)
circle
stroke-dashoffset 200
.x
--stroke var(--cross)
stroke-dashoffset 100
:checked + *
display block
// Game mechanism
:checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
display block
:checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(even)
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ .board .board__cell label:nth-of-type(odd)
display none
#x-0:checked ~ #x-1:checked ~ #x-2:checked ~ .game__result--x
#x-3:checked ~ #x-4:checked ~ #x-5:checked ~ .game__result--x
#x-6:checked ~ #x-7:checked ~ #x-8:checked ~ .game__result--x
#x-0:checked ~ #x-3:checked ~ #x-6:checked ~ .game__result--x
#x-1:checked ~ #x-4:checked ~ #x-7:checked ~ .game__result--x
#x-2:checked ~ #x-5:checked ~ #x-8:checked ~ .game__result--x
#x-0:checked ~ #x-4:checked ~ #x-8:checked ~ .game__result--x
#x-2:checked ~ #x-4:checked ~ #x-6:checked ~ .game__result--x
#o-0:checked ~ #o-1:checked ~ #o-2:checked ~ .game__result--o
#o-3:checked ~ #o-4:checked ~ #o-5:checked ~ .game__result--o
#o-6:checked ~ #o-7:checked ~ #o-8:checked ~ .game__result--o
#o-0:checked ~ #o-3:checked ~ #o-6:checked ~ .game__result--o
#o-1:checked ~ #o-4:checked ~ #o-7:checked ~ .game__result--o
#o-2:checked ~ #o-5:checked ~ #o-8:checked ~ .game__result--o
#o-0:checked ~ #o-4:checked ~ #o-8:checked ~ .game__result--o
#o-2:checked ~ #o-4:checked ~ #o-6:checked ~ .game__result--o
display block
~ .game__result--draw
display none
:checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked ~ :checked
~ .game__result--draw
display block
.ghost
opacity 0
transition opacity var(--draw-speed)
circle
path
animation none
stroke-dashoffset 0
label:hover .ghost
opacity 0.25
Also see: Tab Triggers