{chess}
A chess position from FEN as an SVG board, with marked squares and arrows.
Syntax
{chess 'fen'}
{chess 'fen', flip, highlight='e2, e4', arrow='e2-e4, g8-f6', size=320, title='Name'}
Parameters
-
fen - The position in FEN. The piece placement alone will do; side to move, castling, en passant and the two counters are checked when written.
Options
-
flip - Bare option: turn the board, Black at the bottom.
-
highlight -
Squares to mark, separated by commas:
'e2, e4'. -
arrow -
Arrows from square to square, separated by commas:
'e2-e4, g1-f3'. -
size - Width and height in pixels, 360 when not given (80 at least); the board shrinks to fit a narrower container.
-
title -
The accessible name of the board.
Chess position, White to movewhen not given.
Description
{chess} draws a chess position as inline SVG: the board, the pieces as shapes of PAD's own (no font, no image), the coordinates along the edges, and optionally marked squares and arrows - for the last move, a plan or a threat. It is drawn on the server and needs no script.
The position is written in FEN (Forsyth-Edwards Notation). Only the first field, the placement of the pieces rank by rank from rank 8, is required: {chess '8/8/8/4k3/8/8/4K3/8'}. When the other fields are written - side to move, castling rights, en passant square, half-move clock and move number - they are checked, and the side to move is part of the description.
flip turns the board so Black plays up. highlight= marks squares and arrow= draws arrows from the middle of one square to the middle of another, over the pieces. size= sets the width and height in pixels.
The board is an image for a screen reader (role="img") with a title and a description listing every piece by side and kind, the side to move, the marks and the arrows. Under the strict check a FEN with a wrong number of ranks, an unknown piece letter or a wrong field is an error, as is a square or an arrow that is not on the board. The colours are --pad-chess-light, -dark, -white, -black, -ink, -mark, -arrow and -text on .pad-chess.
Examples
The starting position
Only the placement field of the FEN, at a smaller size.
{chess 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR', size=240}
After 1.e4, seen by Black
The full FEN, the board flipped, the last move marked and two answers drawn as arrows.
{chess 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1', flip, highlight='e2, e4', arrow='c7-c5, e7-e5', size=280}
A position from data
The FEN from the page's PHP, with a title naming the position for a screen reader.
{chess $fen, highlight='d1, d8', arrow='g5-d8', size=280, title='Morphy against the Duke and the Count, Paris 1858: 17.Rd8 mate'}
<?php
$fen = '1n1Rkb1r/p4ppp/4q3/4p1B1/4P3/8/PPP2PPP/2K5 b k - 1 17';
?>
See also
- {sudoku} A sudoku as a table, the givens bold - and with solve, solved on the server.
- {crossword} A crossword made from a list of words: a numbered SVG grid with the Across and Down clues.
- {chart} Draws a chart as inline SVG on the server - 46 kinds, from bars and lines to sankeys, maps of a hierarchy and org charts.