Skip to content

4. Position Object & FEN String

hyeongi-park edited this page Jul 27, 2026 · 1 revision

Position Object

You can use a JavaScript object to represent a board position.

The object property names must be algebraic squares (ie: e4, b2, c6, etc) and the values must be a valid piece codes (ie: wP, bK, wQ, etc).

See an example of using an object to represent a position here.

ChessBoard-Web.js exposes the Chessboard.objToFen method to help convert between Position Objects and FEN Strings.

FEN String

You can use Forsyth-Edwards Notation (FEN) to represent a board position.

For example, for the move 22. Qf6+ in the 'Immortal Game'—hailed as a legendary chess match—, the FEN code is as follows: r1bk2nr/p2p1pNp/n2B1Q2/1p1NP2P/6P1/3P4/P1P1K3/q5b1 b - - 2 22

image

Note that FEN notation captures more information than ChessBoard-Web.js requires, like who's move it is and whether or not castling is allowed. This information will be ignored; only the position information is used.

See an example of using a FEN String to represent a position here and here.

ChessBoard-Web.js exposes the Chessboard.fenToObj method to help convert a FEN String to a Position Object.

Clone this wiki locally