Grid
A 24-column layout. A Row lays out its Col children; a column takes span of the 24 and moves to the next line as a whole when it does not fit. Rows align and distribute their columns, and columns can be shifted, reordered, hidden and resized per screen width. The responsive values are resolved in CSS, so the server and the browser render the same page. Breakpoints tells your code which breakpoints the screen matches.
When to use
- Use the grid to lay a page or a section out on equal columns that line up from row to row.
- Use the responsive props (
xstoxxxl) when the layout has to change with the screen width. - For one-dimensional spacing without a column count, plain flex or CSS grid in your own styles is simpler.
Examples
col-24
col-12
col-12
col-8
col-8
col-8
col-6
col-6
col-6
col-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- Columns go into a Row. A column takes span of the 24; the Row is as wide as its parent. -->
<div class="stack">
<Row>
<Col span={24}><div class="box">col-24</div></Col>
</Row>
<Row>
<Col span={12}><div class="box">col-12</div></Col>
<Col span={12}><div class="box alt">col-12</div></Col>
</Row>
<Row>
<Col span={8}><div class="box">col-8</div></Col>
<Col span={8}><div class="box alt">col-8</div></Col>
<Col span={8}><div class="box">col-8</div></Col>
</Row>
<Row>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box alt">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box alt">col-6</div></Col>
</Row>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
gutter={16}
col-6
col-6
col-6
col-6
gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }} (resize the window)
col-6
col-6
col-6
col-6
gutter={[16, 24]}: horizontal and vertical
col-6
col-6
col-6
col-6
col-6
col-6
col-6
col-6
gutter="2rem": a CSS length
col-6
col-6
col-6
col-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">{'gutter={16}'}</span>
<!-- A number is pixels. The Row does not grow past its parent: there is no negative margin. -->
<Row gutter={16}>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}'} (resize the window)</span>
<!-- One value per breakpoint; a breakpoint that is not given keeps the value of the next smaller one. -->
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'gutter={[16, 24]}'}: horizontal and vertical</span>
<Row gutter={[16, 24]}>
{#each [0, 1, 2, 3, 4, 5, 6, 7] as index (index)}
<Col span={6}><div class="box">col-6</div></Col>
{/each}
</Row>
</div>
<div class="field">
<span class="caption">gutter="2rem": a CSS length</span>
<Row gutter="2rem">
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
<Col span={6}><div class="box">col-6</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
</style>
col-8
col-8 offset-8
col-6 offset-6
col-6 offset-6
col-12 offset-6
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- offset skips that many columns before the column. -->
<div class="stack">
<Row>
<Col span={8}><div class="box">col-8</div></Col>
<Col span={8} offset={8}><div class="box alt">col-8 offset-8</div></Col>
</Row>
<Row>
<Col span={6} offset={6}><div class="box">col-6 offset-6</div></Col>
<Col span={6} offset={6}><div class="box alt">col-6 offset-6</div></Col>
</Row>
<Row>
<Col span={12} offset={6}><div class="box">col-12 offset-6</div></Col>
</Row>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
push={6} and pull={18}: the first column in the DOM is drawn second
col-18 push-6
col-6 pull-18
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- push and pull move a column visually. The DOM order, the Tab order and the reading order do not change. -->
<div class="stack">
<div class="field">
<span class="caption">{'push={6} and pull={18}'}: the first column in the DOM is drawn second</span>
<Row>
<Col span={18} push={6}><div class="box">col-18 push-6</div></Col>
<Col span={6} pull={18}><div class="box alt">col-6 pull-18</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
justify="start"
col-4
col-4
col-4
col-4
justify="center"
col-4
col-4
col-4
col-4
justify="end"
col-4
col-4
col-4
col-4
justify="space-between"
col-4
col-4
col-4
col-4
justify="space-around"
col-4
col-4
col-4
col-4
justify="space-evenly"
col-4
col-4
col-4
col-4
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
const values = ['start', 'center', 'end', 'space-between', 'space-around', 'space-evenly'] as const;
</script>
<div class="stack">
{#each values as value (value)}
<div class="field">
<span class="caption">justify="{value}"</span>
<div class="area">
<Row justify={value}>
{#each [0, 1, 2, 3] as index (index)}
<Col span={4}><div class="box" class:alt={index % 2 === 1}>col-4</div></Col>
{/each}
</Row>
</div>
</div>
{/each}
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.area {
background: var(--ads-color-bg-container-disabled);
border-radius: 4px;
}
</style>
align="top"
col-4
col-4
col-4
col-4
align="middle"
col-4
col-4
col-4
col-4
align="bottom"
col-4
col-4
col-4
col-4
align="stretch"
col-4
col-4
col-4
col-4
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
const values = ['top', 'middle', 'bottom', 'stretch'] as const;
const heights = [100, 50, 120, 80];
</script>
<div class="stack">
{#each values as value (value)}
<div class="field">
<span class="caption">align="{value}"</span>
<div class="area">
<Row justify="space-around" align={value}>
{#each heights as height, index (index)}
<Col span={4}>
<!-- stretch makes every column as tall as the line. The box of a column fills it when it is as tall as its parent. -->
<div
class="box"
class:alt={index % 2 === 1}
class:fill={value === 'stretch' && index !== 0}
style:height={value !== 'stretch' ? `${height}px` : index === 0 ? `${height}px` : undefined}
>
col-4
</div>
</Col>
{/each}
</Row>
</div>
</div>
{/each}
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.area {
background: var(--ads-color-bg-container-disabled);
border-radius: 4px;
}
.fill {
height: 100%;
box-sizing: border-box;
}
</style>
Written 1, 2, 3, 4; drawn 1, 2, 3, 4
1 order-1
2 order-2
3 order-3
4 order-4
Written 1, 2, 3, 4; drawn 4, 3, 2, 1
1 order-4
2 order-3
3 order-2
4 order-1
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- order changes how the columns are drawn, not their place in the DOM (a screen reader and Tab keep the written order). -->
<div class="stack">
<div class="field">
<span class="caption">Written 1, 2, 3, 4; drawn 1, 2, 3, 4</span>
<Row>
<Col span={6} order={1}><div class="box">1 order-1</div></Col>
<Col span={6} order={2}><div class="box alt">2 order-2</div></Col>
<Col span={6} order={3}><div class="box">3 order-3</div></Col>
<Col span={6} order={4}><div class="box alt">4 order-4</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">Written 1, 2, 3, 4; drawn 4, 3, 2, 1</span>
<Row>
<Col span={6} order={4}><div class="box">1 order-4</div></Col>
<Col span={6} order={3}><div class="box alt">2 order-3</div></Col>
<Col span={6} order={2}><div class="box">3 order-2</div></Col>
<Col span={6} order={1}><div class="box alt">4 order-1</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
flex={2} and flex={3}: a number n is "n n auto"
2 / 5
3 / 5
flex="100px" and flex="auto": a fixed width and the rest
100px
Fill rest
flex="1 1 200px" and flex="0 1 300px": a raw flex value
1 1 200px
0 1 300px
flex="none" and flex="auto"
none
auto with no-wrap
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<div class="stack">
<div class="field">
<span class="caption">{'flex={2} and flex={3}'}: a number n is "n n auto"</span>
<Row>
<Col flex={2}><div class="box">2 / 5</div></Col>
<Col flex={3}><div class="box alt">3 / 5</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="100px" and flex="auto": a fixed width and the rest</span>
<Row>
<Col flex="100px"><div class="box">100px</div></Col>
<Col flex="auto"><div class="box alt">Fill rest</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="1 1 200px" and flex="0 1 300px": a raw flex value</span>
<Row>
<Col flex="1 1 200px"><div class="box">1 1 200px</div></Col>
<Col flex="0 1 300px"><div class="box alt">0 1 300px</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">flex="none" and flex="auto"</span>
<Row wrap={false}>
<Col flex="none"><div class="box">none</div></Col>
<Col flex="auto"><div class="box alt">auto with no-wrap</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
wrap
wrap={true}
Three columns of 12: the third does not fit in a line
col-12
col-12
col-12
<script lang="ts">
import { Col, Row, Switch } from 'svelte-ant-design';
let wrap = $state(true);
</script>
<div class="stack">
<div class="field">
<span class="caption">wrap</span>
<div class="row">
<Switch bind:checked={wrap} aria-label="wrap" />
<span role="status">{`wrap={${wrap}}`}</span>
</div>
</div>
<div class="field">
<span class="caption">Three columns of 12: the third does not fit in a line</span>
<!-- With wrap, a column that does not fit moves to the next line as a whole. Without it the columns keep their width and run past the end of the Row. -->
<div class="strip">
<Row {wrap}>
<Col span={12}><div class="box">col-12</div></Col>
<Col span={12}><div class="box alt">col-12</div></Col>
<Col span={12}><div class="box">col-12</div></Col>
</Row>
</div>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.strip {
overflow-x: auto;
}
</style>
Outer gutter 16; the inner Row on the left has gutter 4, the one on the right none
12 / 24 of 12
12 / 24 of 12
8
16
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- A Row inside a Col fills the content box of the column and has a gutter of its own. -->
<div class="stack">
<div class="field">
<span class="caption">Outer gutter 16; the inner Row on the left has gutter 4, the one on the right none</span>
<Row gutter={16}>
<Col span={12}>
<Row gutter={4}>
<Col span={12}><div class="box">12 / 24 of 12</div></Col>
<Col span={12}><div class="box alt">12 / 24 of 12</div></Col>
</Row>
</Col>
<Col span={12}>
<Row>
<Col span={8}><div class="box">8</div></Col>
<Col span={16}><div class="box alt">16</div></Col>
</Row>
</Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
xs 2/20/2, sm 4/16/4, md 6/12/6, lg 8/8/8, xl 10/4/10, xxl 11/2/11, xxxl 12/0/12
Col
Col
Col
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- xs is the base for every width; each larger breakpoint applies from its minimum width up. Resize the window. -->
<div class="stack">
<div class="field">
<span class="caption">xs 2/20/2, sm 4/16/4, md 6/12/6, lg 8/8/8, xl 10/4/10, xxl 11/2/11, xxxl 12/0/12</span>
<Row>
<Col xs={2} sm={4} md={6} lg={8} xl={10} xxl={11} xxxl={12}><div class="box">Col</div></Col>
<Col xs={20} sm={16} md={12} lg={8} xl={4} xxl={2} xxxl={0}><div class="box alt">Col</div></Col>
<Col xs={2} sm={4} md={6} lg={8} xl={10} xxl={11} xxxl={12}><div class="box">Col</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
flex 100% / 50% / 40% / 20% / 10% from xs / sm / md / lg / xl
Col
Col
Col
Col
Col
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- A breakpoint object can carry flex: a share of the line that changes with the screen. Resize the window. -->
<div class="stack">
<div class="field">
<span class="caption">flex 100% / 50% / 40% / 20% / 10% from xs / sm / md / lg / xl</span>
<Row>
{#each [0, 1, 2, 3, 4] as index (index)}
<Col xs={{ flex: '100%' }} sm={{ flex: '50%' }} md={{ flex: '40%' }} lg={{ flex: '20%' }} xl={{ flex: '10%' }}>
<div class="box" class:alt={index % 2 === 1}>Col</div>
</Col>
{/each}
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
xs span 5 offset 1; lg span 6 offset 2 (resize the window)
Col
Col
Col
xs={12}, md order 2 / 1: drawn in the other order from md
First in the DOM
Second in the DOM
md push 6 and pull 18: swapped visually from md, the DOM order stays
First in the DOM
Second in the DOM
<script lang="ts">
import { Col, Row } from 'svelte-ant-design';
</script>
<!-- span, offset, push, pull, order and flex go inside a breakpoint object; xs={6} is the same as xs={{ span: 6 }}.
Each key cascades on its own: the offset of xs still applies where lg gives only a span. -->
<div class="stack">
<div class="field">
<span class="caption">xs span 5 offset 1; lg span 6 offset 2 (resize the window)</span>
<Row>
<Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box">Col</div></Col>
<Col xs={{ span: 11, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box alt">Col</div></Col>
<Col xs={{ span: 5, offset: 1 }} lg={{ span: 6, offset: 2 }}><div class="box">Col</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">{'xs={12}'}, md order 2 / 1: drawn in the other order from md</span>
<Row>
<Col xs={12} md={{ span: 12, order: 2 }}><div class="box">First in the DOM</div></Col>
<Col xs={12} md={{ span: 12, order: 1 }}><div class="box alt">Second in the DOM</div></Col>
</Row>
</div>
<div class="field">
<span class="caption">md push 6 and pull 18: swapped visually from md, the DOM order stays</span>
<Row>
<Col xs={12} md={{ span: 18, push: 6 }}><div class="box">First in the DOM</div></Col>
<Col xs={12} md={{ span: 6, pull: 18 }}><div class="box alt">Second in the DOM</div></Col>
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
Horizontal gutter (px)
Vertical gutter (px)
Columns in a row
<Row gutter={[16, 16]}> with 4 columns of span 6, twice
Column
Column
Column
Column
Column
Column
Column
Column
<script lang="ts">
import { Col, RadioGroup, Row } from 'svelte-ant-design';
const gutters = [8, 16, 24, 32, 40, 48];
let horizontal = $state(16);
let vertical = $state(16);
let count = $state(4);
const counts = [2, 3, 4, 6, 8, 12];
</script>
<div class="stack">
<div class="field">
<span class="caption">Horizontal gutter (px)</span>
<RadioGroup bind:value={horizontal} optionType="button" options={gutters} aria-label="Horizontal gutter" />
</div>
<div class="field">
<span class="caption">Vertical gutter (px)</span>
<RadioGroup bind:value={vertical} optionType="button" options={gutters} aria-label="Vertical gutter" />
</div>
<div class="field">
<span class="caption">Columns in a row</span>
<RadioGroup bind:value={count} optionType="button" options={counts} aria-label="Columns in a row" />
</div>
<div class="field">
<span class="caption">{`<Row gutter={[${horizontal}, ${vertical}]}> with ${count} columns of span ${24 / count}, twice`}</span>
<Row gutter={[horizontal, vertical]}>
{#each Array.from({ length: count * 2 }, (_, index) => index) as index (index)}
<Col span={24 / count}><div class="box" class:alt={index >= count}>Column</div></Col>
{/each}
</Row>
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
screens.current
screens.xs ... screens.xxxl (xs is true below 576 px, the others from their width up)
xs: true
sm: false
md: false
lg: false
xl: false
xxl: false
xxxl: false
{#if screens.md}: markup that depends on the screen
The screen is narrower than 768 px
<script lang="ts">
import { Breakpoints, Col, Row } from 'svelte-ant-design';
// The values are read from the screen when the object is created, so they are right on the first render.
// On a server, where there is no screen, they follow options.fallback (default 'xs').
const screens = new Breakpoints();
const names = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'] as const;
</script>
<div class="stack">
<div class="field">
<span class="caption">screens.current</span>
<output>{screens.current}</output>
</div>
<div class="field">
<span class="caption">screens.xs ... screens.xxxl (xs is true below 576 px, the others from their width up)</span>
<Row gutter={[8, 8]}>
{#each names as name (name)}
<Col xs={12} sm={8} md={6}>
<div class="box" class:alt={!screens[name]}>{name}: {screens[name]}</div>
</Col>
{/each}
</Row>
</div>
<div class="field">
<span class="caption">{'{#if screens.md}'}: markup that depends on the screen</span>
{#if screens.md}
<div class="box">The screen is at least 768 px wide</div>
{:else}
<div class="box alt">The screen is narrower than 768 px</div>
{/if}
</div>
</div>
<style>
.stack {
display: grid;
gap: 20px;
width: 100%;
}
.field {
display: grid;
gap: 8px;
}
.caption {
color: var(--ads-color-text-secondary);
font-size: 12px;
}
.box {
padding: 8px 4px;
text-align: center;
font-size: 13px;
color: var(--ads-color-text);
background: var(--ads-color-bg-text-hover);
border: 1px solid var(--ads-color-primary-solid);
border-radius: 4px;
}
.alt {
background: var(--ads-color-bg-container);
}
</style>
Row API
| Property | Description | Type | Default |
|---|---|---|---|
| align | Vertical alignment of the columns of a line: top, middle, bottom or stretch. An object gives one value per breakpoint. | RowAlign | Partial<Record<Breakpoint, RowAlign>> | 'top' |
| justify | Horizontal arrangement of the columns of a line: start, end, center, space-around, space-between or space-evenly. An object gives one value per breakpoint. | RowJustify | Partial<Record<Breakpoint, RowJustify>> | 'start' |
| gutter | Space between the columns. A number is pixels, a string is a CSS length (2rem, 5vw, calc()), an object gives one value per breakpoint, and a pair is [horizontal, vertical] (each can be any of the first three). A string that is not a length is ignored. A negative or non-finite number throws in development. | Gutter | [Gutter, Gutter] | 0 |
| wrap | Whether columns that do not fit move to the next line. With false they stay on one line, keep their widths and run past the end of the Row. | boolean | true |
| children | The columns (Col). Other children are laid out as plain flex items. | Snippet | — |
| class | Extra class of the Row. | string | — |
| style | Inline style of the root. It is written after the values of the component, so it wins on the same property. | string | — |
| native attributes | Everything else goes to the root <div>: id, role, aria-*, data-*, event handlers. | HTMLAttributes<HTMLDivElement> | — |
Differences from Ant Design:
gutter is a flex gap, not a negative margin with padding on the columns, so a Row never grows past its parent (the Ant Design Row does, which makes a page scroll sideways) and a column's own background does not paint the gutter; the responsive values are CSS only and the breakpoints are fixed (576, 768, 992, 1200, 1600 and 1920 px), so a theme cannot change them; Breakpoints replaces the Grid.useBreakpoint hook and is right on the first render; there is no classNames/styles, because none of the three Ant Design libraries has them for the grid.Col API
| Property | Description | Type | Default |
|---|---|---|---|
| span | How many of the 24 columns to take. 0 is display: none. Without it the column keeps its content width. A negative or non-finite number throws in development. | number | — |
| offset | Empty columns before this one. | number | 0 |
| push | Moves the column that many columns towards the inline end, visually only. The DOM order does not change. | number | 0 |
| pull | Moves the column that many columns towards the inline start, visually only. With both push and pull the column moves by the difference. | number | 0 |
| order | The flex order: how the column is drawn, not where it is in the DOM. An integer, negative allowed. | number | 0 |
| flex | A number n is flex: n n auto (0 counts); a string of digits is n 1 0px; a single length or percentage (100px, 30%) is a fixed width, 0 0 <length>; any other string is used as written. It wins over the width of span. | string | number | — |
| xs | From 0 px up: the base of every width. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| sm | From 576 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| md | From 768 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| lg | From 992 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| xl | From 1200 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| xxl | From 1600 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| xxxl | From 1920 px up. A number is a span; an object takes the props of ColSize. | number | ColSize | — |
| children | The content of the column. | Snippet | — |
| class | Extra class of the Col. | string | — |
| style | Inline style of the root. It is written after the values of the component, so it wins on the same property. | string | — |
| native attributes | Everything else goes to the root <div>: id, role, aria-*, data-*, event handlers. | HTMLAttributes<HTMLDivElement> | — |
ColSize: the keys of a breakpoint object
| Property | Description | Type | Default |
|---|---|---|---|
| span | How many of the 24 columns to take; 0 hides the column at this breakpoint. | number | — |
| offset | Empty columns before this one. | number | — |
| push | Visual shift towards the inline end, in columns. | number | — |
| pull | Visual shift towards the inline start, in columns. | number | — |
| order | The flex order. | number | — |
| flex | A raw flex value, as for the flex prop. | string | number | — |
Breakpoints
| Property | Description | Type | Default |
|---|---|---|---|
| new Breakpoints(options?) | Creates the reader. The values are taken from the screen at once, so they are right on the first render in a browser. The listeners exist only while something reactive reads them. | (options?: BreakpointsOptions) => Breakpoints | — |
| options.fallback | The breakpoint to report where there is no screen (on a server): the flags are those of a screen exactly as wide as this breakpoint starts. An unknown value throws in development. | Breakpoint | 'xs' |
| xs | True below 576 px. | boolean | — |
| sm | True from 576 px up. | boolean | — |
| md | True from 768 px up. | boolean | — |
| lg | True from 992 px up. | boolean | — |
| xl | True from 1200 px up. | boolean | — |
| xxl | True from 1600 px up. | boolean | — |
| xxxl | True from 1920 px up. | boolean | — |
| current | The largest breakpoint that matches (xs below 576 px). | Breakpoint | — |
BREAKPOINTS: the minimum widths, in pixels
| Property | Default |
|---|---|
| xs | 0 |
| sm | 576 |
| md | 768 |
| lg | 992 |
| xl | 1200 |
| xxl | 1600 |
| xxxl | 1920 |
Accessibility
- Row and Col are plain
<div>elements with no role, name or state of their own. They are layout, not a data grid, so they do not getrow,cellorgridroles. If your markup needs a role (a list, a region), passroleoraria-*as native attributes. - The reading order is the DOM order.
order,pushandpullchange only how the columns are drawn, so the Tab order and a screen reader can differ from what the eye sees (WCAG 2.4.3 and 1.3.2). Write the columns in the order they should be read and use these props for decoration. - A
spanof0isdisplay: none, so the content is hidden from assistive technology as well as from view, and its controls leave the Tab order. - The grid draws no colour, border or motion and nothing in it is interactive, so contrast, forced-colors, reduced-motion, IME, touch and screen-reader checks do not apply to it. The reading order and the missing roles are covered by tests.