Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                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}`)
    svg.x(style=`--x: ${x}; --y: ${y}` viewBox="0 0 100 100")
      path(d="M 80 20 L 20 80" stroke="black" stroke-width="10" stroke-linecap="round")
      path(d="M 20 20 L 80 80" stroke="black" stroke-width="10" stroke-linecap="round")
    input(type='checkbox' id=`o-${i}`)
    svg.o(style=`--x: ${x}; --y: ${y}` viewBox="0 0 100 100")
      circle(r="30" cx="50" cy="50" stroke-width="10" stroke-linecap="round" stroke="black" fill="none")
  .board
    - 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};`)
        path(d="M 5 5 L 5 295" stroke-width="10" stroke-linecap="round" stroke="black")
    - for (let i = 0; i < 9; i++)
      .board__cell
        label(for=`x-${i}`)
        label(for=`o-${i}`)
  .game__result.game__result--x X Wins!
  .game__result.game__result--o O Wins!
  .game__result.game__result--draw Draw...
  button(type='reset') Reset Board
              
            
!

CSS

              
                *
  box-sizing border-box

:root
  --size 50vmin
  --cell-size calc(var(--size) / 3)

body
  min-height 100vh
  display grid
  place-items center
  margin 0
  overflow hidden

label
  position absolute
  height 100%
  width 100%

label:nth-of-type(odd)
  color red

label:nth-of-type(even)
  color green

input
  position fixed
  left 100%

button
  position absolute
  top 125%


.game
  position relative

  &__result
    display none


.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
    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)))

  &__cell
    height var(--cell-size)
    position relative
    width var(--cell-size)

.o
.x
  display none
  position absolute
  height var(--cell-size)
  width var(--cell-size)
  left calc(var(--x) * var(--cell-size))
  top calc(var(--y) * var(--cell-size))
  z-index 2

: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
              
            
!

JS

              
                
              
            
!
999px

Console