Documentation
Properties
Property / Type | Default | Description |
---|---|---|
CSSResult |
"styles" |
|
{ [square: string]: string | undefined; } |
The current position of the board, as a To set the position using FEN, or a keyword like |
|
boolean |
false |
Whether to show the board notation. |
boolean |
"true" |
Whether to show the board notation. This is always the inverse of |
"black" | "white" |
"white" |
The orientation of the board. |
boolean |
false |
If |
"trash" | "snapback" |
"snapback" |
If This property has no effect when |
string | ((piece: string) => string) | undefined |
A template string or function used to determine the source of piece images, If If |
|
RenderPieceFunction | undefined |
"Function" |
A function that renders DOM for a piece to a container element. This The default value renders an SVG image of the piece, unless the |
number | "fast" | "slow" |
200 |
Animation speed for when pieces move between squares or from spare pieces |
number | "fast" | "slow" |
60 |
Animation speed for when pieces that were dropped outside the board return |
number | "fast" | "slow" |
30 |
Animation speed for when pieces "snap" to a square when dropped. |
number | "fast" | "slow" |
100 |
Animation speed for when pieces are removed. |
number | "fast" | "slow" |
200 |
Animation speed for when pieces appear on a square. Note that the "appear" animation only occurs when |
boolean |
false |
If |
Methods
Method | Parameters | Description |
---|---|---|
|
Sets the position of the board. |
|
|
Returns the current position as a FEN string. |
|
|
Sets the board to the start position. |
|
|
Removes all the pieces on the board. If This is shorthand for |
|
|
Executes one or more moves on the board. Moves are strings the form of "e2-e4", "f6-d5", etc., Pass |
|
|
Flip the orientation. |
|
|
Recalculates board and square sizes based on the parent element and redraws |
Events
Name | Description |
---|---|
CustomEvent |
Fired when the cursor is over a square
Note that |
CustomEvent |
Fired when the cursor exits a square Note that |
CustomEvent |
Fired when the snapback animation is complete when
|
CustomEvent |
Fired when a piece completes a snap animation
|
CustomEvent |
Fired when a piece is picked up
The drag action is prevented if the listener calls |
CustomEvent |
Fired when a user-initiated drag moves
|
CustomEvent |
Fired when a user-initiated drag ends
|
CustomEvent |
Fired when a piece move completes
|
CustomEvent |
Fired when the board position changes
Warning: do not call any position-changing methods in your event |
Event |
Fired in the case of invalid attributes. |
CSS Properties
Name | Description | Default |
---|---|---|
--light-color
|
The background for white squares and text color for black squares |
"#f0d9b5" |
--dark-color
|
The background for black squares and text color for white squares |
"#b58863" |
--highlight-color
|
The highlight color |
"yellow" |
CSS Parts
Name | Description |
---|---|
board
|
The chess board |
square
|
A square on the board |
piece
|
A chess piece |
spare-pieces
|
The spare piece container |
dragged-piece
|
The currently dragged piece |
white
|
A white square |
black
|
A black square |
highlight
|
A highlighted square |
notation
|
The square location labels |
alpha
|
The alpha (column) labels |
numeric
|
The numeric (row) labels |
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-element.js exports the objToFen
function
to help convert between Position Objects and FEN Strings.
FEN String
You can use Forsyth-Edwards Notation (FEN) to represent a board position.
Note that FEN notation captures more information than chessboard-element 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-element.js exports the fenToObj
function to help convert a FEN String to a
Position Object.