Setup

Create a new project and get the foundation ready for our tic-tac-toe game.

Create the Project

Open your terminal and run:

Terminal
npx create-what tic-tac-toe --yes
cd tic-tac-toe
npm install
npm run dev

--yes takes the defaults this tutorial assumes: the SPA template, no React compatibility layer, and vanilla CSS. Leave it off and create-what asks you those three questions before it writes anything.

Open http://localhost:5173 in your browser. You should see the default What app.

Start with a Clean Slate

Replace the contents of src/main.jsx with this starter code:

src/main.jsx
import { mount } from 'what-framework';

function Game() {
  return (
    <div className="game">
      <h1>Tic-Tac-Toe</h1>
      {/* We'll add the board here */}
    </div>
  );
}

mount(<Game />, '#app');

Add Some Styles

The scaffold already created src/styles.css and already links it from index.html. Replace its contents with the game styles:

src/styles.css
/* Game Layout */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px;
  font-family: -apple-system, sans-serif;
}

.game h1 {
  margin-bottom: 24px;
}

/* Board */
.board {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 4px;
  background: #333;
  padding: 4px;
  border-radius: 8px;
}

/* Squares */
.square {
  width: 80px;
  height: 80px;
  background: #fff;
  border: none;
  font-size: 32px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.square:hover {
  background: #f0f0f0;
}

.square:first-child { border-radius: 4px 0 0 0; }
.square:nth-child(3) { border-radius: 0 4px 0 0; }
.square:nth-child(7) { border-radius: 0 0 0 4px; }
.square:last-child { border-radius: 0 0 4px 0; }

/* Game Info */
.game-info {
  margin-top: 24px;
  text-align: center;
}

.status {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.moves {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.moves button {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}

.moves button:hover {
  background: #f5f5f5;
}

Import the Styles

Add one line at the top of main.jsx so the stylesheet travels with the module, as every file in the rest of this tutorial does, and delete the <link rel="stylesheet" href="/src/styles.css" /> line from index.html: with both, the page loads the stylesheet twice. Keep the mount() call: src/main.jsx is the app entry (index.html loads it directly), so without it nothing renders.

src/main.jsx
import './styles.css';
import { mount } from 'what-framework';

function Game() {
  return (
    <div className="game">
      <h1>Tic-Tac-Toe</h1>
    </div>
  );
}

mount(<Game />, '#app');

Checkpoint

Your app should now show a centered "Tic-Tac-Toe" heading. If you see that, you're ready for the next step!

You're all set!

Next, we'll build the game board with 9 clickable squares.