A simple and interactive Tic Tac Toe game built using HTML, CSS, and JavaScript. Two players can play on the same device. The interface highlights the winner and allows restarting or resetting the game.
- Two players take turns marking a 3×3 grid with X or O.
- The first player to place three marks in a horizontal, vertical, or diagonal row wins.
- Click "New Game" to start again after a win.
- Click "Reset Game" to clear the board at any time.
- 3x3 interactive grid using
buttonelements. - Real-time turn indication and move handling.
- Winner detection with congratulatory message.
- Visual distinction for X and O players.
- New Game and Reset Game buttons to replay or restart the game.
- Player Turn Handling using a boolean
turnOvariable (true= O,false= X). - Win Conditions stored in
winPatterns(8 possible combinations). - Event listeners attached to each
.boxto handle player moves. - DOM manipulation to update game UI and control logic.
playTurn()– Handles the marking and turn switch.checkWinner()– Checks all 8 winning combinations after every move.showWinner(winner)– Displays the winner message and disables all boxes.resetGame()– Resets all variables and clears the grid.disableBoxes()&enableBoxes()– Controls box state after game ends or restarts.
- Layout:
- Uses Flexbox to center game board and message box.
- Game Board:
- Grid layout (3x3) made with styled
buttonelements. - Hover and focus removed for a clean interface.
- Grid layout (3x3) made with styled
- Colors:
- Background: Soft teal
- X: Blue, O: Pink
- Winner message and buttons styled for emphasis.
- Responsiveness:
- Centralized layout adapts well to screen sizes.
(Replace with your screenshots)
| Gameplay | Winner Message |
|---|---|
![]() |
![]() |
- HTML5
- CSS3 (Flexbox, Custom Buttons)
- JavaScript (Vanilla JS for DOM and logic)
- Clone the repo or download the code.
- Open
index.htmlin a browser. - Start playing!
- Add player vs computer mode.
- Add animation or sound effects.
- Add score tracking across rounds.
- Make it mobile responsive with media queries.
Prateek Kumar
Computer Science student at Chitkara University.
This project is open-source and available for educational or personal use.
