---
name: "naive-ui-design-layout"
description: "Layout system for Naive UI including Grid, Flex, Space, and Layout components. Invoke when user needs to create responsive layouts, grid systems, or understand layout components."
metadata:
author: jiaiyan
version: "1.0.0"
---
# Layout System
Naive UI provides a comprehensive layout system including CSS Grid-based layout, Flexbox, Space, and Layout components for building responsive page structures.
## When to Use
- Creating responsive grid layouts
- Building page structures with header, sidebar, content, and footer
- Implementing flexible layouts with Flexbox
- Adding consistent spacing between elements
---
## Grid System (n-grid)
Naive UI uses a CSS Grid-based layout system with 24 columns by default.
### Basic Concepts
- **24-column system**: Default is 24 columns, configurable
- **CSS Grid**: Uses native CSS Grid for layout
- **Responsive**: Supports responsive breakpoints
- **Flexible**: Items can span multiple columns
### Basic Grid
```vue
Full width
Half width
Half width
One third
One third
One third
```
### Grid with Gaps
```vue
{{ i }}
```
### Responsive Grid
```vue
Responsive item
```
### Grid Item Offset
```vue
Offset by 6
```
### Grid Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| cols | Number of columns | `number \| string` | `24` |
| x-gap | Horizontal gap | `number \| string` | `0` |
| y-gap | Vertical gap | `number \| string` | `0` |
| responsive | Responsive mode | `'self' \| 'screen'` | `'self'` |
| collapsed | Collapsed state | `boolean` | `false` |
| collapsedRows | Rows when collapsed | `number` | `1` |
### Grid Item Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| span | Number of columns to span | `number \| string` | `1` |
| offset | Number of columns to offset | `number` | `0` |
| suffix | Whether it's a suffix item | `boolean` | `false` |
---
## Flex Component (n-flex)
A flexible flexbox layout component.
### Basic Flex
```vue
Item 1
Item 2
Item 3
```
### Flex with Justify
```vue
Centered
Left
Right
```
### Flex Vertical
```vue
Item 1
Item 2
```
### Flex Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| justify | Horizontal alignment | `'start' \| 'end' \| 'center' \| 'space-around' \| 'space-between' \| 'space-evenly'` | `'start'` |
| align | Vertical alignment | `'start' \| 'end' \| 'center' \| 'stretch' \| 'baseline'` | — |
| vertical | Vertical direction | `boolean` | `false` |
| reverse | Reverse direction | `boolean` | `false` |
| wrap | Enable wrapping | `boolean` | `true` |
| inline | Inline flex | `boolean` | `false` |
| size | Gap size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'medium'` |
---
## Space Component (n-space)
Add consistent spacing between elements.
### Basic Space
```vue
Button 1
Button 2
Button 3
```
### Space Sizes
```vue
Small gap
Medium gap
Large gap
Custom 24px gap
```
### Vertical Space
```vue
Top
Bottom
```
### Space Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| size | Gap size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'small'` |
| vertical | Vertical direction | `boolean` | `false` |
| wrap | Enable wrapping | `boolean` | `true` |
| inline | Inline mode | `boolean` | `false` |
---
## Layout Components (n-layout)
Build complete page layouts with header, sidebar, content, and footer.
### Basic Layout
```vue
Header
Content
Footer
```
### Layout with Sidebar
```vue
Sidebar
Header
Content
Footer
```
### Collapsible Sidebar
```vue
Sidebar
Content
```
### Layout Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| embedded | Embedded mode (no background) | `boolean` | `false` |
| position | Position mode | `'static' \| 'absolute'` | `'static'` |
| native-scrollbar | Use native scrollbar | `boolean` | `true` |
| has-sider | Has sidebar | `boolean` | `false` |
| sider-placement | Sidebar placement | `'left' \| 'right'` | `'left'` |
### Layout Sider Props
| Name | Description | Type | Default |
|------|-------------|------|---------|
| bordered | Show border | `boolean` | `false` |
| collapsed | Collapsed state | `boolean` | `false` |
| collapse-mode | Collapse mode | `'width' \| 'transform'` | `'transform'` |
| collapsed-width | Width when collapsed | `number` | `48` |
| width | Sidebar width | `number` | `272` |
| show-trigger | Show collapse trigger | `boolean` | `false` |
---
## Responsive Breakpoints
Naive UI uses default breakpoints for responsive design:
| Breakpoint | Screen Width |
|------------|--------------|
| `xs` | `< 640px` |
| `s` | `≥ 640px` |
| `m` | `≥ 1024px` |
| `l` | `≥ 1280px` |
| `xl` | `≥ 1536px` |
| `xxl` | `≥ 1920px` |
### Using Breakpoints
```vue
Responsive grid item
```
---
## Best Practices
1. **Use Grid for 2D layouts**: Use `n-grid` when you need both rows and columns
2. **Use Flex for 1D layouts**: Use `n-flex` for single-row or single-column layouts
3. **Use Space for simple gaps**: Use `n-space` for consistent spacing between elements
4. **Layout composition**: Combine Layout components for full-page structures
5. **Responsive design**: Use responsive props for mobile-first design
6. **Collapsed sidebar**: Use `collapse-mode="width"` for better animation performance
---
## Related Resources
| Resource | Description |
|----------|-------------|
| [Grid Component](https://www.naiveui.com/en-US/os-theme/components/grid) | Grid documentation |
| [Flex Component](https://www.naiveui.com/en-US/os-theme/components/flex) | Flex documentation |
| [Space Component](https://www.naiveui.com/en-US/os-theme/components/space) | Space documentation |
| [Layout Component](https://www.naiveui.com/en-US/os-theme/components/layout) | Layout documentation |