Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


Save Automatically?

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


                <h1>Tic Tac Toe</h1>
<p id="info">Click the Join Game button when ready</p>
<section id="board"></section>
  <button id="join">Join Game at Server:</button>
  <input id="serverIp">
  <button id="leave">Leave Game</button>



                section {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: 1fr 1fr 1fr;
  grid-gap: 5px;
  height: 300px;
  width: 300px;
  background-color: black;

section div {
  display: grid;
  justify-items: center;
  align-items: center;
  cursor: pointer;
  background-color: white;
  color: blue;
  font: bold 60px Arial;

#leave {
  display: none;

footer {
  margin-top: 20px;


                const section = document.querySelector('section');
const messageArea = document.querySelector('#info');
const square = location => document.querySelector(`#s${location}`);
const joinButton = document.querySelector('#join');
const leaveButton = document.querySelector('#leave');
const serverTextField = document.querySelector('#serverIp');

joinButton.addEventListener('click', joinGame);
leaveButton.addEventListener('click', () => leaveGame('Bye!'));

let socket, mark, gameOver = false;

addEventListener('load', () => {
  for (let i = 0; i < 9; i++) {
    const square = document.createElement('div');
    square.setAttribute('id', `s${i}`);
    square.addEventListener('click', () => { socket.send(`MOVE ${i}`); });

function joinGame() {
  const host = serverTextField.value || 'localhost';
  gameOver = false;
  socket = new WebSocket(`wss://${host}:58901`);
  socket.addEventListener('message', (event) => { processCommand(; });
  document.querySelectorAll('section div').forEach(s => s.textContent = ''); = 'none'; = 'none'; = 'inline';
  socket.onerror = () => leaveGame("Error: The server is probably down");

function leaveGame(message) {
  messageArea.textContent = message || 'Game over';
  gameOver = true; = 'inline'; = 'inline'; = 'none';

function processCommand(command) {
  if (command.startsWith('WELCOME')) {
    mark = command[8];
    opponentMark = mark === 'X' ? 'O' : 'X';
  } else if (command.startsWith('VALID_MOVE')) {
    square(command.substring(11)).textContent = mark;
    messageArea.textContent = 'Valid move, please wait';
  } else if (command.startsWith('OPPONENT_MOVED')) {
    square(command.substring(15)).textContent = opponentMark;
    messageArea.textContent = 'Opponent moved, your turn';
  } else if (command.startsWith('MESSAGE')) {
    messageArea.textContent = command.substring(8);
  } else if (command.startsWith('VICTORY')) {
    leaveGame('WINNER WINNER');
  } else if (command.startsWith('DEFEAT')) {
    leaveGame('Oh sorry you lost');
  } else if (command.startsWith('TIE')) {
    leaveGame('Tie game so boring');
  } else if (command.startsWith('OTHER_PLAYER_LEFT')) {
    leaveGame(!gameOver ? 'Woah your opponent bailed' : '');