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

              
                h1
  = "Example for "
  a(href="https://kizu.dev/counters-and-stones/", target="_blank") my article
  = " about counters logic in CSS."

//- Variables shoule be odd, not all render ok,
//- but 3x3, 13x13, 15x15, 19x19 are fine
//- (those > 13x13 can be buggy in Edge)
- const rows = 13;
- const columns = 13;
- const winCombo = 5;

form.board(style=`--rows:${rows};--columns:${columns}`)
  - for (var i = 1; i <= rows * columns; i++)
    input(id=`Black${i}`, type='radio', style=`--stone:B${i};--notstone:W${i}`)
  - for (var i = 1; i <= rows * columns; i++)
    input(id=`White${i}`, type='radio', style=`--stone:W${i};--notstone:B${i}`)
  header
    p
      = 'Current turn: '
      span
      
    button(type='reset') Restart
  section
    - for (var i = 1; i <= rows * columns; i++)
      label(for=`Black${i}`, style=`--stone:B${i}`): span
  section
    - for (var i = 1; i <= rows * columns; i++)
      label(for=`White${i}`, style=`--stone:W${i}`): span
  footer
    button(type='reset') Play again!

//- Here we have selectors which should has parts based on the board dimensions
//- and the number of stones in a row required to win.
//- I generate those selectors there so you'd need to change only the variables here and leave everything else to CSS.
- let check1 = ''
- let check2 = ''
- for (var i = 1; i < winCombo; i++)
  - check1 += `:not(:nth-child(${ columns }n-${ i - 1 }))`
  - check2 += `:not(:nth-child(${ columns }n+${ i }))`

style.
  /* ⋯ */ #{ check1 }[id^=W]:checked #{' + :checked'.repeat(winCombo - 1)} ~ footer,
  /* ⋰ */ #{ check2 }[id^=W]:checked #{ ('+' + '*+'.repeat(columns - 2) + ':checked').repeat(winCombo - 1) } ~ footer,
  /* ⋮  */ [id^=W]:checked #{ ('+' + '*+'.repeat(columns - 1) + ':checked').repeat(winCombo - 1) } ~ footer,
  /* ⋱ */ #{ check1 }[id^=W]:checked #{ ('+' + '*+'.repeat(columns) + ':checked').repeat(winCombo - 1) } ~ footer {
    --endgame: grid;
    --endmessage: 'White won!';
  }

  /* ⋯ */ #{ check1 }#{':checked + '.repeat(winCombo - 1)} [id^=B]:checked ~ footer,
  /* ⋰ */ #{ check2 }#{ (':checked+' + '*+'.repeat(columns - 2)).repeat(winCombo - 1) } [id^=B]:checked ~ footer,
  /* ⋮  */ #{ (':checked+' + '*+'.repeat(columns - 1)).repeat(winCombo - 1) } [id^=B]:checked ~ footer,
  /* ⋱ */ #{ check1 }#{ (':checked+' + '*+'.repeat(columns)).repeat(winCombo - 1) } [id^=B]:checked ~ footer {
    --endgame: grid;
    --endmessage: 'Black won!';
  }

              
            
!

CSS

              
                /* Turn-passing counters magic omg */
.board > input {
  counter-increment: var(--stone) 10;
}
.board > input:checked {
  counter-increment: White 10 Black -10 var(--stone) 100 var(--notstone) -10;
}
.board > input[id^=White]:checked {
  counter-increment: White -10 Black 10 var(--stone) 100 var(--notstone) -10;
}

.board {
  --stone-size: 30px;
  --playfield-width: calc(var(--columns) * var(--stone-size));
  --playfield-height: calc(var(--rows) * var(--stone-size));

  counter-reset: White 0 Black 10;
}

/* Visually hiding inputs */
.board > input {
  position: fixed;
  top: -99em;
  left: -99em;
  clip: rect(1px,1px,1px,1px);
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* Stones! */
.board > section > label {
  visibility: hidden;

  position: relative;

  display: flex;
  flex-wrap: wrap;

  box-sizing: border-box;
  height: var(--stone-size);
  width: var(--stone-size);

  cursor: pointer;

  font-size: var(--stone-size);
}
.board > section > label > span,
.board > section > label > span:before {
  visibility: visible;
  content: '';

  position: relative;

  display: flex;
  flex-wrap: wrap;
  flex-grow: 1;

  width: 0;
  height: var(--stone-size);
}
.board > section > label:hover > span:before {
  width: var(--stone-size);
}
.board > section > label > span:before {
  border-radius: 50%;
  box-shadow:
    inset -0.3em -0.1em 0.8em 0em #000,
    inset -.2em -0.3em 0.4em 0.25em #000,
    inset 1em 0 #AAA;
  background: rgba(0,0,0,0.5);
  transform: scale(0.95)
}
.board > section > label[for^=White] > span:before {
  box-shadow:
    inset -1px -1px 1.9px #000,
    inset 1em 0 #FFF;
  background: rgba(0,0,0,0.3);
  transform: scale(0.98)
}
.board > section > label:after,
.board > section > label > span:after {
  content: counter(Black) counter(var(--stone));

  flex-basis: 100%;
  font-size: 10px;
  position: relative;
  padding-left: calc(100% - 3.5ch);
  box-sizing: border-box;
}
.board > section > label[for^=White]:after {
  content: counter(White) counter(var(--stone));
}
.board > section > label > span:after {
  visibility: hidden;
  content: counter(var(--stone));

  padding-left: calc(100% - 2.5ch);
}

/* Layout and other misc stuff */
.board {
  position: relative;

  display: grid;
  grid-template-columns: 1fr min-content 1fr;

  padding: 0;
  margin: auto;
}

/* Label wrappers */
.board > section {
  display: grid;
  grid-column: 2;
  grid-row: 1;
  grid-template-columns: repeat(var(--columns), var(--stone-size));

  width: var(--playfield-width);
  height: var(--playfield-height);
}

/* Turn marker & reset */
.board > header {
  display: flex;
  flex-wrap: wrap;
  padding: var(--stone-size) calc(0.5 * var(--stone-size));
  justify-content: space-between;
  align-items: center;
  grid-column: 2;
  grid-row: 2;
}
.board > header > button {
  visibility: hidden;
}
.board > :checked ~ header > button {
  visibility: inherit;
}

/* Turn marker logic */
.board > header > p {
  margin: 0;
}
.board > header > p > span {
  display: inline-flex;
  flex-wrap: wrap;
  width: var(--stone-size);
  height: var(--stone-size);
  overflow: hidden;
  vertical-align: middle;
  font-size: var(--stone-size);
}
.board > header > p > span:before {
  content: "";
  position: relative;

  flex-grow: 1;

  width: 0;
  height: 100%;

  border-radius: 50%;
  box-shadow:
    inset -1px -1px 1.9px #000,
    inset 1em 0 #FFF;
  background: rgba(0,0,0,0.3);

  transform: scale(0.98)
}
.board > header > p > span:after {
  content: counter(White);

  position: relative;
  flex-basis: 100%;

  box-sizing: border-box;
  height: 100%;
  padding-left: calc(100% - 1.5ch);

  color: transparent;

  border-radius: 50%;
  box-shadow:
    inset -0.3em -0.1em 0.8em 0em #000,
    inset -.2em -0.3em 0.4em 0.25em #000,
    inset 1em 0 #AAA;
  background: rgba(0,0,0,0.5);

  transform: scale(0.95)
}

/* The block with the win message */
.board > footer {
  grid-column: 2;
  grid-row: 1;

  z-index: 99;

  display: var(--endgame, none);

  justify-content: center;
  text-align: center;
  align-content: center;

  grid-gap: 1em;
  margin: calc(-0.5 * var(--stone-size));

  font: 40px/1.5 Hevetica Neue, Arial, sans-serif;
  color: #000;

  background: rgba(255,255,255,0.9);
}
.board > footer:before {
  content: var(--endmessage);
}

/* New game after win button */
.board > footer > button {
  font-size: 1em;
  border: 2px solid;
  padding: 0.5em 1em;
  border-radius: 9em;
  background: #FFF;
  cursor: pointer;
}

/* The board visuals */
.board:before {
  content: "";

  grid-column: 2;
  grid-row: 1;

  width: calc(var(--playfield-width) + var(--stone-size));
  height: calc(var(--playfield-height) + var(--stone-size));
  margin: calc(-0.5 * var(--stone-size));

  --dotsSizeX: calc(var(--stone-size) * (var(--columns) + 1) - var(--stone-size) * 8);
  --dotsSizeY: calc(var(--stone-size) * (var(--rows) + 1) - var(--stone-size) * 8);
  --dotsPositionX: calc(var(--stone-size) * (var(--columns) + 1) / 2);
  --dotsPositionY: calc(var(--stone-size) * (var(--rows) + 1) / 2);
  background:
    radial-gradient(closest-side circle, #000 3px, transparent 4px)
      var(--dotsPositionX) var(--dotsPositionY)/var(--dotsSizeX) var(--dotsSizeY),
    radial-gradient(closest-side circle, #000 3px, transparent 4px)
      50%,
    linear-gradient(#DCB35C calc(var(--stone-size) - 2px), transparent 0)
      0 0/100% calc(var(--stone-size) * var(--rows) + 2px),
    linear-gradient(to right, #DCB35C calc(var(--stone-size) - 2px), transparent 0)
      0 0/calc(var(--stone-size) * var(--columns) + 2px) 100%,
    linear-gradient(#000 var(--stone-size), transparent 0)
      0 0/100% calc(var(--stone-size) * var(--rows)),
    linear-gradient(to right, #000 var(--stone-size), transparent 0)
      0 0/calc(var(--stone-size) * var(--columns)) 100%,
    linear-gradient(#000 2px, transparent 0)
      -1px -1px/var(--stone-size) var(--stone-size),
    linear-gradient(to right, #000 2px, transparent 0)
      -1px -1px/var(--stone-size) var(--stone-size)
    #DCB35C;
}

/* Some visual styles for the page */
html, body {
  padding: 0;
  margin: 0;
}

body {
  min-height: 100vh;
  text-align: center;
}

h1 {
  margin-bottom: 1em;
}
              
            
!

JS

              
                // JS? What JS? HTML & CSS only, yep yep.
              
            
!
999px

Console