Center
Center centers its children both vertically and horizontally using flexbox.
**Important:** Children that use CSS Grid with fr units must define their own
width (e.g., w-96, max-w-md). This is because fr units require a defined
container width to calculate available space, but flex items without explicit
width use intrinsic sizing—creating a circular dependency where the grid
collapses to minimum content width.
Usage
import { Center, CenterProps } from "@desk/ui/components/center";Best practices
Centercenters a single child on both axes; grid children usingfrunits need an explicit width (e.g.w-96) or they collapse to min-content.as/asChildare mutually exclusive (asChildwins, dev-warned); useinlineto center inline-level content without breaking the text flow.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "div" | "li" | "nav" | "ol" | "span" | "ul" | "article" | "aside" | "figcaption" | "figure" | "footer" | "header" | "main" | "section" | Render as a different host element from the closed layout vocabulary
({@link LayoutElement}). The set is deliberately closed: | |
| asChild | boolean | Merge props onto child element | |
| inline | boolean | Use inline-flex instead of flex for inline centering |
Also exports
- interface
CenterProps
Composition
Used by