How to Make a Card Game Online
Online card games are rules engines with secrets. Here is how to model the deck, enforce turns, keep hands hidden from other players and survive a dropped phone.

Key takeaways
- Model the game as state plus actions: every move is an action the rules engine accepts or rejects, and the result is a new state.
- Hidden information must stay on the server. Each player receives only their own hand and what is public.
- Plan for disconnects and slow players from day one: seats that survive reconnects, and turn timers with a sensible default move.
To make an online card game, write the rules as a small engine that takes the current game state and a player action and returns the next state (or rejects the action), run that engine on a server that shuffles and deals, and send each player only the cards they are allowed to see. Add turn order with timeouts and reconnects that keep a player’s seat, and you can put almost any card game online, from Crazy Eights to a game you invented. Here is how each piece works.
Model the cards and the zones
Every card game is cards moving between zones. Write the zones down before anything else:
- Card: an id, plus its properties (suit and rank for a standard deck, or name, cost and color for a custom one). Give every physical card a unique id, even duplicates; “the second 7 of hearts” must be distinguishable.
- Zones: draw pile, discard pile, each player’s hand, cards on the table (tricks, melds, a shared river), and anything set aside.
- Visibility per zone: hands are visible to their owner only; the draw pile to no one; the discard pile’s top card (or all of it) to everyone.
- Game state: the zones, whose turn it is, the phase (dealing, bidding, playing, scoring), scores, and any rule flags like the current suit after a wild card.
Writing the visibility column is the step most people skip, and it decides your whole security model later.
A rules engine is a function
The cleanest structure for a card game is a pure function: `next(state, action) → new state or error`. Actions are things like `play {card}`, `draw`, `pass`, `bid {amount}`. The engine checks that the action is legal (is it this player’s turn, do they hold the card, does it follow suit) and then applies it. Nothing else changes the state.
- Legality lives in one place. The interface asks the engine which moves are legal and greys out the rest, but the server checks again on every action.
- Testable without a screen. You can play a thousand random games against the engine in a test and check that no rule is ever broken and every game ends.
- An action log for free. Store every action and you can replay a game, debug a dispute, or show a move history.
- Phases as a small state machine: deal, then play until a hand is empty, then score, then the next deal or game over. Write the transitions explicitly.
Hidden information: the server keeps secrets
In a local game you can render your opponent’s cards face down and call it hidden. Online, if the opponent’s cards are in the data sent to your browser, anyone can read them in the developer tools. Hidden information has to stay on the server. If the idea of a server is new, what a backend is explains it in plain terms.
- 01Shuffle on the server with a proper algorithm (Fisher-Yates) and a good random source. Never shuffle on a client.
- 02Build a view per player: from the full state, produce what each player may see: their own hand, the public table, card counts for other hands (“Sam has 4 cards”), never the draw pile order.
- 03Send only the view. Each player’s connection receives their own view after every action.
- 04Reveal deliberately: when a card becomes public (played, shown at scoring), it moves to a public zone and appears in everyone’s view.
On Startbase, live boards and turns run on Startbase Cloud’s realtime features, and games that need a dedicated server get a room server; see Multiplayer in the Cloud docs. Either way, the principle is the same: the trusted side holds the deck.
Turn order, timers and the slow player
- Explicit turn order: a list of seats and a pointer. Rules that skip or reverse (Uno’s reverse) change the direction or the pointer, nothing else.
- Turn timer: 30 to 60 seconds for realtime play, with a visible countdown. When it runs out, apply a default action (draw and pass, play the lowest legal card) rather than freezing the table.
- Async mode: for two-player games, consider turns that can take hours, with a notification when it is your move. Chess-by-mail style play suits busy friends and needs a durable database, not just a live room.
- Disconnects: keep the seat for a minute or two. A bot or the default action plays for an absent player so the others can continue, and the player takes the seat back on reconnect.
Making it feel like a table
Card games are tactile. Small touches make an online version feel like the real thing: cards that slide from the deck to hands, a fan of your hand at the bottom of the screen, tap to lift a card and tap again (or drag) to play it, the played card sliding to the center with a soft sound, a glow on the current player’s seat. Show legal moves by lifting playable cards slightly. On phones, portrait with your hand at the bottom and opponents across the top fits up to four or five players. The game feel guide covers the small motions and sounds that make a card snap into place.
The brief to paste
An online card game of Crazy Eights for 2 to 5 players in a room with a short join code. Rules: deal 7 cards each (5 with more than 2 players); play a card matching the top discard by suit or rank; eights are wild and the player names the next suit; if you cannot play, draw one card and you may play it; first to empty their hand wins the round and scores the value of cards left in other hands (eights 50, face cards 10, others face value); game to 200. When the draw pile runs out, shuffle the discards except the top card back in. Write the rules as a pure engine (state plus action gives a new state or an error) with tests that play random games to the end. The server shuffles and deals and sends each player only their own hand, the top discard and other players’ card counts. 45-second turn timer that draws and passes on timeout. A dropped player keeps their seat for 2 minutes. Phone portrait: my hand fanned at the bottom, playable cards lifted, opponents across the top.
A note on famous card games
Traditional games like Hearts, Spades, Rummy and Crazy Eights are free for anyone to make. Commercial card games are different: game rules themselves are generally not protected by copyright, but names, card text, artwork and trademarks are. If you are adapting a commercial game, use your own name, art and wording, or better, use it as inspiration for your own twist. If it matters for your situation, ask someone qualified.
Pitfalls specific to card games
- Client-side validation only. If the server does not re-check every move, someone will play cards they do not have.
- Duplicate card ids. Two identical cards with the same id cause cards to vanish or duplicate when moved.
- Unstated edge cases. Empty draw piles, ties and simultaneous actions break games in week two, not day one. Put them in the rules text.
- No reconnect path. Phones lock and switch networks constantly. A player who loses their seat on every lock screen will not come back.
For the general room model (codes, lobbies, testing with two browsers), read the multiplayer game guide. Ready to share? Publish it, then list it in the community so others can play and remix it. For more room-based ideas in the same shape, see multiplayer game ideas.
Frequently asked questions
How do online card games keep hands hidden?
The server holds the full game state, including every hand and the deck order, and sends each player a view containing only their own cards and public information like the top of the discard pile and card counts.
Can I make an online version of an existing card game?
Traditional games like Hearts or Crazy Eights are free to make. For commercial games, rules are generally not protected by copyright but names, art, card text and trademarks are, so use your own branding and wording.
What happens when a player disconnects in an online card game?
Good games hold the seat for a minute or two, play a default move or a simple bot for the absent player so others can continue, and let the player reclaim the seat when they reconnect.

