Density
Comfortable and compact. Compact turns on by itself on screens under 52rem tall, so low laptops keep the main content on the first screen.
<html data-density="compact">
Comfortable and compact
Controls, rows and panel padding shrink; text size stays. The gallery's density button sets it for the whole page.
Comfortable
| Name | Rows |
|---|---|
| orders | 1,240 |
| customers | 312 |
Compact
| Name | Rows |
|---|---|
| orders | 1,240 |
| customers | 312 |
Code
import { Button, Field, Input, Table } from '@sypnia/ui/react';
// Comfortable and compact side by side. Compact turns on by itself on screens under 52rem tall, or with
// data-density="compact" on <html> (the gallery's density button) or on any element.
const rows = [{ id: 1, name: 'orders', rows: '1,240' }, { id: 2, name: 'customers', rows: '312' }];
export default function Both() {
return (
<div className="sy-cols" style={{ '--cols': 2, '--gap': 'var(--s-5)' } as React.CSSProperties}>
{(['comfortable', 'compact'] as const).map((d) => (
<div key={d} data-density={d} className="sy-stack" style={{ '--gap': 'var(--gap-stack)' } as React.CSSProperties}>
<strong>{d === 'compact' ? 'Compact' : 'Comfortable'}</strong>
<Field label="Table name"><Input defaultValue="orders" /></Field>
<Table label={`Tables, ${d}`} rows={rows} rowKey={(r) => r.id} columns={[{ id: 'name', header: 'Name', cell: (r) => r.name }, { id: 'rows', header: 'Rows', cell: (r) => r.rows, numeric: true }]} />
<div><Button variant="primary">Save</Button></div>
</div>
))}
</div>
);
} When to use it
Use it when
- People who work with a lot of data and want more on screen.
- Nothing to do on low screens: it is automatic.
Do not use it when
- Making text smaller to fit more: density changes space, not reading size.
- Writing your own media query for short screens in a component: the tokens already do it.
For everyone
- Touch targets stay at least 44 px on touch screens in both densities.
data-density="comfortable"turns the automatic compact mode off for people who need more room.