Chessfield: Interactive 3D Chessboards
Chessfield is a lightweight TypeScript library for rendering interactive 3D chessboards in the browser. Built with Three.js (WebGPU), it provides smooth 60fps rendering, customizable themes, camera controls, and a clean API for integration into any web project.
Table of Contents
Features
🎮 WebGPU Rendering
Modern WebGPU backend via Three.js for smooth 60fps performance with hardware acceleration.
🎨 Customizable Themes
Built-in themes (blue, green, brown, bw, light, dark) plus custom theme support via plugin system.
📷 Camera Controls
5 camera positions (white, right, black, left, top) with orbit controls for free exploration.
♟️ Full Game State
FEN support, last move highlighting, check/mate/draw states, player names, and coordinate display.
⏳ Loading State
Built-in loading overlay with progress events and a whenReady() promise.
🔧 Programmatic Control
Rich API for theme switching, camera changes, shape overlays (rings and arrows), and dynamic configuration.
📦 Zero Dependencies
Only peer dependencies on Three.js and chessground types. No runtime framework lock-in.
Live Demo
Drag to orbit, scroll to zoom, right-click squares to add rings, or right-drag between squares to draw arrows:
Quick Start
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/chessfield@2.5.5/dist/chessfield.css">
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.186.1/build/three.module.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.186.1/build/three.webgpu.js",
"three/tsl": "https://cdn.jsdelivr.net/npm/three@0.186.1/build/three.tsl.js",
"three/": "https://cdn.jsdelivr.net/npm/three@0.186.1/"
}
}
</script>
</head>
<body>
<div id="board" style="width: 600px; height: 600px;"></div>
<script type="module">
import { Chessfield } from 'https://cdn.jsdelivr.net/npm/chessfield@2.5.5/dist/chessfield.js';
const chessfield = new Chessfield(document.getElementById('board'), {
camera: 'white',
angle: 'right',
theme: 'green'
});
</script>
</body>
</html>
npm install chessfield @lichess-org/chessground three
import { Chessfield } from 'chessfield';
import 'chessfield/style.css';
const chessfield = new Chessfield(document.getElementById('board')!, {
camera: 'white',
angle: 'right',
theme: 'green',
fen: 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1',
lastMove: ['e2', 'e4'],
playerNames: { white: 'Magnus', black: 'Hikaru' }
});
// React
import { useEffect, useRef } from 'react';
import { Chessfield } from 'chessfield';
import 'chessfield/style.css';
export function Chessboard({ fen, theme }) {
const ref = useRef<HTMLDivElement>(null);
const fieldRef = useRef<Chessfield>(null);
useEffect(() => {
if (!ref.current) return;
fieldRef.current = new Chessfield(ref.current, { fen, theme });
}, [fen, theme]);
return <div ref={ref} style={{ width: 600, height: 600 }} />;
}
// Vue 3
import { onMounted, ref } from 'vue';
import { Chessfield } from 'chessfield';
import 'chessfield/style.css';
const boardRef = ref<HTMLDivElement>();
let chessfield: Chessfield;
onMounted(() => {
chessfield = new Chessfield(boardRef.value!, { theme: 'blue' });
});
// Template: <div ref="boardRef" style="width: 600px; height: 600px" />
// Angular
import { Component, ElementRef, ViewChild, OnInit } from '@angular/core';
import { Chessfield } from 'chessfield';
@Component({
template: '<div #board style="width: 600px; height: 600px"></div>'
})
export class ChessboardComponent implements OnInit {
@ViewChild('board') boardRef!: ElementRef<HTMLDivElement>;
chessfield!: Chessfield;
ngOnInit() {
this.chessfield = new Chessfield(this.boardRef.nativeElement, { theme: 'brown' });
}
}
Links
- npm Package: chessfield on npm
- GitHub Repository: unicolored/chessfield
- Issues & Contributions: GitHub Issues