Chess PGN Viewer
Operator: Abdulla Al Fahad. How tools are built and checked
A PGN file is a game written as text: a block of tags, then the moves with comments in braces and alternatives in brackets. Reading it as text is slow; replaying it on a board is what you want, with the side lines kept apart from the main game.
Every move is checked for legality as it is read, so a typo in a downloaded game shows up as a message that names the move, instead of a board that quietly drifts out of sync.
Key features
- PGN text or files of up to 5 MB and 1,000 games, with a list to pick a game, or a single FEN; variations to any depth, comments in braces or after a semicolon, and annotation symbols from $ codes and from marks such as !, ?, !! and ?!, with [%clk] and [%eval] commands stripped from the comments
- Buttons and keys (Left and Right step, Home and End jump, Up and Down switch between a move and its alternatives, F flips the board), check, checkmate, stalemate and draw status, a copy button for the FEN, and four board colour themes
- Diagrams as SVG, PNG or a vector PDF, and a print sheet that collects up to 60 positions at 1, 2, 4, 6 or 9 per page
How games, variations and positions are read
The game text may start with seven-tag-roster lines such as [White "Paul Morphy"]; a header line that follows movetext starts the next game. A FEN header on a game with SetUp makes it start from that position; a bad FEN header is reported and the standard start is used. Move numbers, the result token and NAG codes such as $1 for ! are understood, and a lone FEN or just its piece-placement field is accepted in place of a game.
Variation brackets work as in PGN: the moves inside replace the move just before the opening bracket, so (2... Nc6) after 2... d6 shows an alternative for Black's second move. If a move inside a variation is not legal, only that line stops, and the message names the move and the one before it; the rest of the game loads.
How it works
chess.js 1.4 plays each move on the position before it, which is how illegal moves are caught and how the FEN after every move is produced. It keeps only a game's main line, so the tree of moves and variations is built by the page and chess.js checks each node.
The board is drawn from the FEN: 64 squares, then the pieces. The pieces are plain polygons and circles designed for this page, with no font and no image, so the SVG, the PNG and the PDF all show the same shapes and nothing depends on the viewer's fonts. The last move is tinted on the screen board; saved diagrams leave the tint out.
The print sheet draws squares, pieces, coordinates and captions as vector shapes, one diagram per cell sized to fit it, with the side to move under each unless you type your own caption.
When this helps
- A coach opens a 40-game tournament file, picks the game a student lost, and walks through the three variations the student's opponent annotated.
- A club newsletter editor pastes a FEN for each of six endgame studies and prints them 6 to a page with captions.
- A student pastes the 20 FENs of a tactics chapter and prints them 9 to a page with the caption 'White to move, mate in 2'.
- A reader opens a PGN downloaded from a friend and finds that the game stops at move 14 because of a typo that the page names.
Opening a file
- Paste a PGN or FEN, open a .pgn file, or press Load an example game.
- Pick a game from the list if the file has several.
- Step with the buttons or the arrow keys; click any move, including those in brackets.
- Save the position as SVG, PNG or PDF, or press Add the current position to build a sheet.
Example
Load an example game: the Opera Game, 1858, with one variation and six annotated moves
1. e4 e5 2. Nf3 d6 (2... Nc6 3. Bb5) 3. d4 Bg4?! ... 16. Qb8+!! Nxb8 17. Rd8# 1-0What you get
33 half-moves in the main line and 36 nodes with the 2 variation moves; the last position is checkmate (Rd8#). The position after 10.Nxb5 saved as a PNG at 2x with a caption is 1347 x 1475 px. Seven positions at 4 per page print on 2 pages.Tips for best results
- For a handout, choose the Print (grey) colours: the squares stay legible on a photocopier and use little ink.
- Use the Up and Down arrows to jump between a move and the alternatives written for it; Left and Right stay on the line you are in.
- Paste a list of positions as 'FEN | caption' lines to build a sheet in one go; a line with a bad FEN is skipped and its line number is reported.
Limits
Arrows and coloured squares in comments (the [%cal] and [%csl] commands) are removed, not drawn.
Games are checked against the rules of standard chess, so a game that starts from a non-standard setup without a FEN header is reported as illegal.
Common errors and how to fix them
- "Nf6" is not a legal move after 12...Rd8
- The move text or the move before it has a typo, or the game used a different starting position without a FEN header. Fix the text and open it again.
- "games.pgn" contains binary data, so it is not a PGN file
- A single NUL byte is enough to trigger this. Open the file in a text editor, check that it is a .pgn and not a database export such as .cbh, and save a plain-text copy.
- That is not a valid FEN: Invalid FEN: missing white king
- Every position needs both kings; check the piece-placement field.
Best practices
- Split a database of more than 1,000 games before opening it: the page lists only the first 1,000 and says so, and the rest cannot be reached.
FEN in one paragraph
A FEN has six fields: the pieces from rank 8 down to rank 1 (digits count empty squares, capitals are White), whose turn it is, castling rights, the en passant square, the half-move clock for the fifty-move rule, and the full-move number. If you give only the first field or the first two, the page fills in the rest with 'no castling, no en passant, move 1'.
Frequently asked questions
Why does the PNG not show the yellow last-move squares?
The saved diagrams leave them out so that a printed position does not hint at the previous move. The on-screen board shows them to help you follow the game.
In the move list, why does a variation come after the move it replaces?
That is the order PGN itself uses: in '1. e4 e5 (1... c5) 2. Nf3' the bracket holds the alternative to e5, written right after e5. The moves inside it start from the position before e5, and clicking one of them puts that line on the board.