Repository navigation
1. Config Properties
hyeongi-park edited this page Jul 27, 2026
·
1 revision
var config = {
draggable: true, // If true, pieces on the board are draggable to other squares
dropOffBoard: 'snapback', // If 'snapback', pieces dropped off the board return to their original square; if 'trash', they are removed
position: 'start', // Sets the initial position of the board ('start', FEN String, or Position Object)
interactiveShapes: false, // If true, enables interactive shapes: right-click draws a circle marker, and right-click drag draws an arrow.
onChange: function(oldPos, newPos) {
// Fires when the board position changes (oldPos to newPos)
},
onDragStart: function(source, piece, position, orientation) {
// Fires when a piece is picked up; return false to prevent the drag action
},
onDragMove: function(newLocation, oldLocation, source, piece, position, orientation) {
// Fires when a dragged piece changes location
},
onDrop: function(source, target, piece, newPos, oldPos, orientation) {
// Fires when a piece is dropped; return 'snapback' or 'trash' if needed
},
onMouseoutSquare: function(square, piece, position, orientation) {
// Fires when the mouse leaves a square (does not fire during drag-and-drop)
},
onMouseoverSquare: function(square, piece, position, orientation) {
// Fires when the mouse enters a square (does not fire during drag-and-drop)
},
onMoveEnd: function(oldPosition, newPosition) {
// Fires at the end of animations when the board position changes
},
onSnapbackEnd: function(piece, square, position, orientation) {
// Fires when the snapback animation is complete when pieces are dropped off the board
},
onSnapEnd: function(source, target, piece) {
// Fires when the piece snap animation is complete
},
orientation: 'white', // Sets the initial orientation of the board ('white' or 'black')
showNotation: true, // Turn board notation on or off
sparePieces: false, // If true, the board will have spare pieces that can be dropped onto the board
showErrors: 'console', // Controls how Chessboard reports errors (e.g., false, 'console', 'alert', or a function)
pieceTheme: 'img/chesspieces/wikipedia/{piece}.png', // Template string or function used to determine piece image sources
nagTheme: 'img/nags/custom/{nag}.png', // Template string or function used to determine nag image sources
appearSpeed: 200, // Animation speed for when pieces appear on a square
moveSpeed: 200, // Animation speed for when pieces move between squares or from spare pieces to the board
snapbackSpeed: 50, // Animation speed for when pieces dropped outside the board return to their original square
snapSpeed: 25, // Animation speed for when pieces snap to a square when dropped
trashSpeed: 100 // Animation speed for when pieces are removed
};
var board = Chessboard('myBoard', config);- Type: Boolean
-
Default:
false -
Description: If
true, pieces on the board are draggable to other squares. - Example: Draggable Snapback
-
Type:
'snapback'or'trash' -
Default:
'snapback' -
Description:
- If
'snapback', pieces dropped off the board will return to their original square. - If
'trash', pieces dropped off the board will be removed from the board. -
Note: This property has no effect when
draggableisfalse.
- If
- Example: Draggable Snapback | Draggable Trash
-
Type:
'start'or FEN String or Position Object -
Default:
N/A - Description: If provided, sets the initial position of the board.
- Example: Start Position | Position FEN | Position Object
-
Type:
'white'or'black' -
Default:
'white' - Description: If provided, sets the initial orientation of the board.
- Example: Orientation
- Type: Boolean
-
Default:
true - Description: Turn board notation on or off.
- Example: Notation
- Type: Boolean
-
Default:
false -
Description: If
true, the board will have spare pieces that can be dropped onto the board. (Setting this totrueautomatically setsdraggabletotrue). - Example: Spare Pieces
- Type: Boolean
-
Default:
false - Description: If true, it enables interactive shapes where a right click draws a circle marker and a right click drag draws an arrow.
- Type: Function
-
Default:
N/A - Description: Fires when the board position changes. The first argument is the old position, the second is the new position.
Warning: Do not call any position-changing methods (
clear(),move(),position(),start()) inside youronChangefunction to prevent infinite loops.
- Example: onChange
- Type: Function
-
Default:
N/A -
Description: Fires when a piece is picked up. Arguments:
(source, piece, position, orientation). Returnfalseto prevent the drag action. - Example: onDragStart | Prevent Drag
- Type: Function
-
Default:
N/A -
Description: Fires when a dragged piece changes location. Arguments:
(newLocation, oldLocation, source, piece, position, orientation). - Example: onDragMove
- Type: Function
-
Default:
N/A -
Description: Fires when a piece is dropped. Arguments:
(source, target, piece, newPos, oldPos, orientation). Return'snapback'to return the piece, or'trash'to remove it. - Example: onDrop | Snapback | Trash
- Type: Function
-
Default:
N/A -
Description: Fires when the mouse leaves/enters a square. Arguments:
(square, piece, position, orientation). (Does not fire during drag-and-drop; useonDragMoveinstead). - Example: Highlight Legal Moves
- Type: Function
-
Default:
N/A -
Description: Fires at the end of animations when the board position changes. Arguments:
(oldPosition, newPosition). - Example: onMoveEnd
- Type: Function
-
Default:
N/A -
Description: Fires when the "snapback" animation is complete. Arguments:
(piece, square, position, orientation). - Example: onSnapbackEnd
- Type: Function
-
Default:
N/A -
Description: Fires when the piece "snap" animation is complete. Arguments:
(source, target, piece). - Example: Only Allow Legal Moves
- Type: String or Function
-
Default:
'img/chesspieces/wikipedia/{piece}.png' - Description: A template string or function used to determine the source of piece images.
- Example: Piece Theme String | Function
- Type: String or Function
-
Default:
'img/nags/chesscom/{nag}.png' - Description: A template string or function used to determine the source of NAG (Numeric Annotation Glyphs) images.
-
Type:
falseor String or Function -
Default:
N/A -
Description: Controls how Chessboard reports errors.
-
false: Ignore errors. -
'console': Send toconsole.log(). -
'alert': Send towindow.alert(). -
Function: Custom handler with arguments(code, errorString, data).
-
-
Type: Number or
'slow'or'fast' -
Default:
200 -
Description: Animation speed when pieces appear on a square (Only occurs when
sparePiecesisfalse).
-
Type: Number or
'slow'or'fast' -
Default:
200 - Description: Animation speed for when pieces move between squares or from spare pieces to the board.
- Example: Animation Speed
-
Type: Number or
'slow'or'fast' -
Default:
50 - Description: Animation speed for when pieces dropped outside the board return to their original square.
- Example: Animation Speed
-
Type: Number or
'slow'or'fast' -
Default:
25 - Description: Animation speed for when pieces "snap" to a square when dropped.
- Example: Animation Speed
-
Type: Number or
'slow'or'fast' -
Default:
100 - Description: Animation speed for when pieces are removed.
- Example: Animation Speed