Styling
The default look is close to Excel. Change colors, fonts and sizes with CSS variables, and highlight rows and cells with classes. You will rarely need to override the grid's internal CSS.
import { createGrid } from 'horee-grid'
const rows = Array.from({ length: 100 }, (_, i) => ({ id: i + 1, item: `Item ${i + 1}`, stock: (i * 37) % 120, safe: 40 }))
const grid = createGrid(host, {
locale: 'en',
rowKey: 'id',
rowHeight: 32,
columns: [
{ field: 'item', title: 'Item', flex: 1 },
{ field: 'stock', title: 'Stock', type: 'number', width: 100 },
{ field: 'safe', title: 'Safety stock', type: 'number', width: 100 }
],
rows,
rowClass: r => (r.stock < r.safe ? 'short' : undefined)
})
const css = document.createElement('style')
css.textContent = `
.hg.theme-ocean { --hg-accent: #0b63ce; --hg-sel: #dbe9ff; --hg-head-bg: #eef3fa; --hg-line: #d5deea; }
.hg.theme-ink { --hg-bg: #111418; --hg-fg: #e5e8eb; --hg-line: #2a2f36; --hg-head-bg: #191d22; --hg-head-fg: #aab2bb;
--hg-sel: #273244; --hg-hover: #1a2029; --hg-accent: #f0b429; }
.hg-row.short .hg-cell { color: #d1242f; }`
document.head.append(css)
toolbar.innerHTML = `
<button data-theme="">Default</button><button data-theme="theme-ocean">ocean</button><button data-theme="theme-ink">ink</button>
<button data-lines="all">lines all</button><button data-lines="row">lines row</button><button data-lines="none">lines none</button>`
toolbar.onclick = e => {
const el = host.querySelector('.hg')
const { theme, lines } = e.target.dataset
if (theme !== undefined) {
el.classList.remove('theme-ocean', 'theme-ink')
if (theme) el.classList.add(theme)
}
if (lines) {
// Same classes the lines option adds (usually you pass lines: 'row' when creating)
el.classList.remove('hg-lines-row', 'hg-lines-none')
if (lines !== 'all') el.classList.add('hg-lines-' + lines)
}
}CSS variables
Set them on the grid element (.hg) or any element above it. One set for the whole app, a different set per screen, or just one grid — all work the same way.
:root {
--hg-font: "Inter", sans-serif;
--hg-font-size: 13px;
--hg-accent: #0b63ce;
}
.dark .hg {
--hg-bg: #111418;
--hg-fg: #e5e8eb;
--hg-line: #2a2f36;
--hg-head-bg: #191d22;
}| Variable | Used for | Default |
|---|---|---|
--hg-font | Font | Inherited |
--hg-font-size | Font size | 13px |
--hg-bg | Cell background | #fff |
--hg-fg | Text | #1f2328 |
--hg-line | Cell lines · borders | #d4d4d4 |
--hg-head-bg | Header · row number background | #f3f3f3 |
--hg-head-fg | Header text | #333 |
--hg-foot-bg | Fixed bottom row (totals) background | --hg-head-bg |
--hg-sel | Selected row background | #e2f0d9 |
--hg-hover | Row under the mouse | #f5f9ff |
--hg-accent | Active cell · sort marker · checkbox · drag marker | #107c41 |
--hg-dirty | Changed cell mark | #e8590c |
--hg-error | Invalid value border | #d93025 |
--hg-row-h | Row height (set by the rowHeight option) | 27px |
The grid sets --hg-row-h itself from the rowHeight option. It is used for scroll calculations, so do not change it in CSS; set rowHeight instead. The header row height is headerHeight (default row height + 2).
Cell lines
createGrid(host, { columns, rows, lines: 'row' })lines | Look |
|---|---|
'all' (default) | Horizontal and vertical lines, like Excel |
'row' | Horizontal lines only; suits read-only lists |
'none' | No lines |
Highlighting rows and cells
createGrid(host, {
columns,
rows,
rowClass: row => (row.stock < row.safe ? 'short' : undefined)
}).hg-row.short .hg-cell { color: #d1242f; }
.hg-row.short .hg-cell:first-child { font-weight: 600; }For a single cell, use the column's cellClass:
{ field: 'diff', title: 'Difference', type: 'number', cellClass: ({ value }) => (value ? 'warn' : undefined) }A background on .hg-row is not visible, because each cell (.hg-cell) has its own background. Use .hg-row.name .hg-cell.
Classes the grid adds
You can rely on these classes in your CSS. Other internal class names may change between versions.
| Class | Where |
|---|---|
.hg | The grid's outer element |
.hg-row · .hg-cell | Rows · cells |
.hg-cell[data-c="column id"] | Cells of a specific column |
.hg-sel | Selected rows (.hg-row) |
.hg-cur | Current row (setCurrent) |
.hg-active | Active cell |
.hg-dirty | Changed cell |
.hg-foot | Fixed bottom row area |
.hg-loading | Loading server data (.hg) |
.hg-lines-row · .hg-lines-none | The lines option (.hg) |
Dark mode
Just change the variables. The examples in these docs switch the same way when you click the ☾ button at the top right.
[data-theme="dark"] .hg {
--hg-bg: #14181c;
--hg-fg: #e6e9ec;
--hg-line: #2a3037;
--hg-head-bg: #1b2026;
--hg-head-fg: #c3cad2;
--hg-sel: #17352a;
--hg-hover: #1a222a;
--hg-accent: #3ccf7f;
}