Col
Grid column with responsive sizing, gap distribution, and visibility control.
Col is the leaf component of the grid. It calculates percentage-based widths from the grid column count and handles gap distribution.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Column content |
component | ComponentType | colComponent from context, else config.component | Custom column element |
css | ExtraStyles | — | Extra CSS (overrides cascaded colCss) |
size | ValueType | Inherited | Column width in grid units (clamped to columns) |
padding | ValueType | Inherited | Inner padding |
gap | ValueType | Inherited | Gap between columns |
columns | ValueType | Inherited | Total columns (12 in the default theme) |
Styling
Col renders as a flex column container:
display: flex;
flex-direction: column;
flex-basis: 0;
flex-grow: 1;
position: relative;
box-sizing: border-box;
justify-content: stretch;Width Calculation
With Explicit Size
width = (min(size, columns) / columns) * 100%
flex-basis = calc(width% - gap) // gap converted with rootSize, same unit as the margin
max-width = calc(width% - gap)
flex-grow = 0
flex-shrink = 0Example with size={6}, columns={12}, gap={16} and rootSize: 16:
flex-basis: calc(50% - 1rem);
max-width: calc(50% - 1rem);
flex-grow: 0;
flex-shrink: 0;With no gap (or gap={0}) the value is the plain percentage (50%). A size larger than columns is clamped since 2.9, so size={14} in a 12-column grid gives 100% instead of overflowing the row. On React Native, the width is computed in pixels from the Row's measured width (onLayout) minus the gap.
Without Size (Auto-Width)
flex-basis: 0;
flex-grow: 1;
/* Grows to fill available space */Gap and Padding Distribution
Gap and padding are distributed evenly on all sides (numbers converted to rem):
margin: <gap / 2>; /* Gap distributed on all sides */
padding: <padding / 2>; /* Padding distributed on all sides */Visibility Logic
The isVisible() function determines if a column should render:
isVisible(size)returnstruewhensizeis a non-zero number orundefined(auto-width)- Returns
falsewhensize === 0
Hidden Columns
Set size={0} to hide a column. It gets display: none:
/* When size={0} */
display: none;The column stays mounted, so its state is preserved. It is removed from layout and from the tab order, so nothing inside it can be focused while hidden. Before 2.8 it was moved off-screen and could still receive focus.
Responsive Visibility
<Row>
{/* Sidebar: hidden on mobile (xs), visible from md */}
<Col size={{ xs: 0, md: 3 }}>
<Sidebar />
</Col>
{/* Main: full-width on mobile, 9/12 from md */}
<Col size={{ xs: 12, md: 9 }}>
<MainContent />
</Col>
</Row>Examples
Fixed and Flexible Columns
<Row gap={16}>
<Col size={3}>Fixed 3/12</Col>
<Col>Auto-expands</Col>
<Col size={2}>Fixed 2/12</Col>
</Row>Responsive Column Sizes
<Row gap={16}>
{/* Full-width on mobile, half on tablet, third on desktop */}
<Col size={{ xs: 12, md: 6, lg: 4 }}>
<Card>Product 1</Card>
</Col>
<Col size={{ xs: 12, md: 6, lg: 4 }}>
<Card>Product 2</Card>
</Col>
<Col size={{ xs: 12, md: 12, lg: 4 }}>
<Card>Product 3</Card>
</Col>
</Row>Array Syntax
<Row gap={16}>
<Col size={[12, 6, 4]}>
{/* xs: 12, sm: 6, md: 4 */}
Content
</Col>
</Row>Column Padding
<Row gap={16} padding={24}>
<Col size={6}>
{/* 12px (0.75rem) padding on each side (24/2) */}
Padded content
</Col>
<Col size={6} padding={8}>
{/* Override: 4px padding on each side */}
Less padding
</Col>
</Row>Custom Column Element
<Col size={6} component="article" css={(css) => css`
background: #f5f5f5;
border-radius: 8px;
min-height: 200px;
`}>
<h2>Article Title</h2>
<p>Article content</p>
</Col>Equal-Width Columns
{/* Without size, all columns share space equally */}
<Row gap={16}>
<Col>Equal</Col>
<Col>Equal</Col>
<Col>Equal</Col>
<Col>Equal</Col>
</Row>Last updated on