Themes, fonts and density
Built-in light, dark and Korean-style themes, CSS variables for your own, one option each for font size and family, and compact or comfortable row spacing.
Live demoThemes & fonts
Light and dark themes, CSS variables, font size and family.
Code for this demo
import { createGrid } from '@freegridjs/core';
import { demoColumns, makeRows } from '../data';
import { select, separator, tr, type DemoContext } from '../ui';
export default function mount(ctx: DemoContext) {
const { lang } = ctx;
const grid = createGrid(ctx.host, { columns: demoColumns(lang), data: makeRows(3000), rowSelection: 'multiple', locale: lang });
// A custom theme is just CSS variables on a class named fg-theme-<name>.
const style = document.createElement('style');
style.textContent = `
.fg-theme-ocean { --fg-font: inherit; --fg-font-size: 13px; --fg-radius: 12px; --fg-cell-px: 14px;
--fg-bg: #f3fbfb; --fg-fg: #0b3b3c; --fg-muted: #4f7a7b; --fg-header-bg: #dff2f1; --fg-header-fg: #0b3b3c;
--fg-border: #b9dedc; --fg-row-border: #d5ecea; --fg-row-odd: #ebf7f6; --fg-row-hover: #d8f0ee;
--fg-row-selected: #bfe6e2; --fg-accent: #0f8c86; --fg-accent-fg: #fff; --fg-focus: #0f8c86;
--fg-popup-bg: #fff; --fg-input-bg: #fff; --fg-shadow: 0 12px 32px rgba(11,59,60,.18); }`;
document.head.append(style);
select(ctx, tr(lang, { en: 'Theme', ko: '테마' }), [
['light', 'Light'], ['dark', 'Dark'],
['simple', tr(lang, { en: 'Simple', ko: '심플형' })],
['board', tr(lang, { en: 'Board (Korean)', ko: '게시판형' })],
['erp', tr(lang, { en: 'ERP (Korean)', ko: '관리자·ERP형' })],
['excel', tr(lang, { en: 'Excel-like', ko: '엑셀형' })],
['classic', tr(lang, { en: 'Classic navy', ko: '진한 헤더형' })],
['ocean', tr(lang, { en: 'Ocean (custom CSS)', ko: 'Ocean (사용자 정의 CSS)' })],
], 'light', v => grid.setTheme(v));
separator(ctx);
select(ctx, tr(lang, { en: 'Font size', ko: '글꼴 크기' }), [9, 10, 11, 12, 13, 14, 15, 16, 17, 18].map(n => [String(n), `${n}px`] as [string, string]), '13',
v => grid.setFont({ size: Number(v) }));
select(ctx, tr(lang, { en: 'Font', ko: '글꼴' }), [
['', tr(lang, { en: 'Theme default', ko: '테마 기본' })],
['Georgia, serif', 'Georgia'],
['ui-monospace, Consolas, monospace', 'Monospace'],
['"Malgun Gothic", "Apple SD Gothic Neo", sans-serif', '맑은 고딕 / Apple SD'],
], '', v => grid.setFont({ family: v || null }));
separator(ctx);
// the left and right padding of every cell and header at once; '' goes back to the theme's
select(ctx, tr(lang, { en: 'Cell padding', ko: '셀 여백' }), [
['', tr(lang, { en: 'Theme default', ko: '테마 기본' })],
...[0, 4, 8, 12, 16, 24].map(n => [String(n), `${n}px`] as [string, string]),
], '', v => grid.setCellPadding(v === '' ? null : Number(v)));
return grid;
}Built-in themes: light, dark, simple (all white, no stripes, hairline rules — good with merged cells), and four Korean-style themes — board (bulletin board: thick top rule, horizontal lines), erp (every cell bordered, compact), excel (gridlines, green focus) and classic (navy header). Font size and family are one option each; row heights follow the size unless you set them.
createGrid(el, { columns, data, theme: 'erp', fontSize: 12, fontFamily: 'Pretendard, sans-serif' });
grid.setTheme('board');
grid.setFont({ size: 14 });
grid.setFont({ family: null }); // back to the theme fontMake your own theme
/* any class named fg-theme-<name> is a theme */
.fg-theme-brand {
--fg-font: "Pretendard", sans-serif;
--fg-font-size: 13px;
--fg-bg: #fff; --fg-fg: #1d2433; --fg-muted: #6b7385;
--fg-header-bg: #f2f5fa; --fg-header-fg: #1d2433;
--fg-border: #d9dfe8; --fg-row-border: #edf0f5;
--fg-col-line: inset -1px 0 #edf0f5;
--fg-row-odd: #fff; --fg-row-hover: #f5f8ff; --fg-row-selected: #e6eeff;
--fg-accent: #3056d3; --fg-focus: #3056d3;
--fg-header-text-align: center; --fg-header-label-flex: 1 1 auto;
}| Variable | Kind | Controls |
|---|---|---|
--fg-font / --fg-font-size | font | Font family and size. |
--fg-bg / --fg-fg / --fg-muted | color | Background, text and secondary text. |
--fg-header-bg / --fg-header-fg / --fg-header-weight | color / weight | Header colors and weight. |
--fg-border / --fg-row-border | color | Outer border and row lines. |
--fg-col-line | box-shadow | Vertical cell lines, e.g. 'inset -1px 0 #ddd'. Default none. |
--fg-row-odd / --fg-row-hover / --fg-row-selected | color | Zebra, hover and selected rows. |
--fg-accent / --fg-focus | color | Buttons, sort icons and the focused cell. |
--fg-radius / --fg-cell-px | length | Corner radius and cell padding. |
--fg-header-text-align / --fg-top-border | keyword / border | Center header labels; thick top rule. |
Row spacing
density sets how much room the rows get: 'compact' fits more rows on a screen, 'comfortable' gives touch screens bigger targets, and 'normal' is the default. A fixed rowHeight or headerHeight wins over it. setDensity() and setFont() change spacing and font later, for example from a user setting; row heights follow the font size unless you set them.
cellPadding sets the space on the left and right inside every cell and header cell, in px, for the whole grid at once (the default is 12; density makes it 7 or 14). Set it when you create the grid, or change it later with setCellPadding(); null goes back to the theme value. Column auto-sizing uses the same padding. For row height use rowHeight or density.
createGrid(el, { columns, data, density: 'compact' }); // 'compact' | 'normal' | 'comfortable'
grid.setDensity('comfortable');
grid.getDensity(); // 'comfortable'
grid.setFont({ size: 14 }); // row heights follow the font size
grid.setFont({ family: null }); // back to the theme font
createGrid(el, { columns, data, cellPadding: 6 }); // px left and right in every cell and header
grid.setCellPadding(16); // all cells at once; autoSizeColumns uses it too
grid.setCellPadding(null); // back to the theme / density value
grid.getCellPadding(); // 12