Chapter 02 Foundations
Layout
Components fit their container, not a list of devices. Most need no breakpoint at all: they wrap and shrink, and work down to 320 pixels wide, the width of a phone or of a page zoomed to 400%.
Breakpoints
Tailwind's five, in rem so they follow the reader's text size.
| Name | Token | rem | px | Starts |
|---|---|---|---|---|
sm | --ui-breakpoint-sm | 40rem | 640 | Large phones held sideways, small tablets. |
md | --ui-breakpoint-md | 48rem | 768 | Tablets. |
lg | --ui-breakpoint-lg | 64rem | 1024 | Laptops, tablets held sideways. |
xl | --ui-breakpoint-xl | 80rem | 1280 | Desktops. |
2xl | --ui-breakpoint-2xl | 96rem | 1536 | Wide desktops. |
Tailwind's @container scale is smaller: @sm is 24rem, not 40rem.
| Tailwind variant | rem | px |
|---|---|---|
@3xs | 16rem | 256 |
@2xs | 18rem | 288 |
@xs | 20rem | 320 |
@sm | 24rem | 384 |
@md | 28rem | 448 |
@lg | 32rem | 512 |
@xl | 36rem | 576 |
@2xl | 42rem | 672 |
@3xl | 48rem | 768 |
@4xl | 56rem | 896 |
@5xl | 64rem | 1024 |
@6xl | 72rem | 1152 |
@7xl | 80rem | 1280 |
Page and grid
ui-page on the wrapper gives 12 columns, a capped width and padding that grows with the screen.
| Class or token | Does |
|---|---|
ui-page | The page wrapper: centred, 12 columns, side padding and gap that grow with the screen. |
ui-grid | The same 12 columns and gap with no padding, to split a column again. |
ui-col-1 … ui-col-12 | Spans that many of the 12 columns. |
ui-col-sm-6, ui-col-md-4 … | Spans that many from that breakpoint up: sm, md, lg, xl, 2xl. Below it, the child fills the row. |
--ui-page-max | Widest the columns get, 96rem (2xl). Set 64rem for a narrower site. |
--ui-page-gutter | Side padding, 1rem to 3rem. |
--ui-grid-gap | Gap between columns and rows, 1rem to 2rem. |
Try the page
Set the screen width: the side bar moves up at md, the cards add columns at sm and lg.
A page from four classes
ui-page, ui-col-md-4 and ui-col-lg-3 for the side bar, and a nested ui-grid for the cards. No CSS of your own.
<div class="ui-page">
<header>Header</header>
<nav class="ui-col-md-4 ui-col-lg-3">Side bar</nav>
<main class="ui-grid ui-col-md-8 ui-col-lg-9">
<article class="ui-col-sm-6 ui-col-lg-4">Card 1</article>
<article class="ui-col-sm-6 ui-col-lg-4">Card 2</article>
<article class="ui-col-sm-6 ui-col-lg-4">Card 3</article>
</main>
<footer>Footer</footer>
</div>Your own components
@container on the box, then a @min-[40rem]: variant: the card reads its box, so it fits a side bar and a full page.
<div class="@container">
<article class="grid gap-4 @min-[40rem]:grid-cols-[12rem_1fr]">
<img src="/kettle.jpg" alt="Steel kettle" />
<p class="body-md">Steel kettle, 1.7 litres.</p>
</article>
</div>Widths
The fixed widths in the kit; nothing is wider than 320px less 2rem.
| Token | Value | For |
|---|---|---|
--ui-dialog-size | 24rem · 32rem · 48rem | Small, default and large dialog. |
--ui-page-max | 96rem | Widest the page columns get. Set 64rem for a narrow site. |
--ui-page-gutter | 1rem → 3rem | Side padding of ui-page, grows with the screen. |
--ui-grid-gap | 1rem → 2rem | Gap between columns and rows. |
.ui-toast | 24rem | Toast. |
.ui-popover | 22rem at most | Popover. |
.ui-tooltip | 18rem at most | Tooltip. |
Rules
- Nothing scrolls sideways at 320px except a table in its frame.
- Below sm, a side bar's links go in a drawer.
- Logical sides only, so the layout works right to left.