---
name: ink-layout-styling
description: Use when creating terminal layouts with Ink using Flexbox-based positioning and styling for CLI applications.
allowed-tools: []
---
# Ink Layout and Styling
You are an expert in creating beautiful terminal layouts with Ink using Flexbox-based positioning and styling.
## Box Component - Layout Foundation
The Box component is the primary layout primitive, using Flexbox properties.
### Flexbox Direction
```tsx
// Vertical stack (default)
First
Second
// Horizontal row
Left
Right
// Reverse order
Bottom (renders on top)
Top (renders on bottom)
```
### Spacing and Padding
```tsx
// Margin around element
Content with margin
// Directional margins
Custom margins
// Padding inside element
Content with padding
// Directional padding
Horizontal and vertical padding
```
### Alignment and Justification
```tsx
// Align items on cross axis
Centered
Top aligned
Bottom aligned
// Justify content on main axis
Centered horizontally
Left
Right
Item 1
Item 2
Item 3
```
### Dimensions
```tsx
// Fixed width
Fixed width content
// Percentage width
Half width
// Fixed height
Fixed height
// Min/max dimensions
Constrained width
```
### Borders
```tsx
// Simple border
Bordered content
// Border styles: single, double, round, bold, singleDouble, doubleSingle, classic
Rounded border
// Custom border color
Green double border
```
## Text Component - Styling Text
### Colors
```tsx
// Foreground colors
Error message
Success message
Warning message
Info message
Highlight
Special
// Background colors
Alert!
// Hex colors
Custom color
```
### Text Formatting
```tsx
// Bold
Important text
// Italic
Emphasized text
// Underline
Underlined text
// Strikethrough
Removed text
// Dim
Subtle text
// Inverse
Inverted colors
// Combinations
Multiple styles
```
### Text Wrapping
```tsx
// Wrap text to fit width
This is a long text that will wrap to fit within the 40 character width.
// Truncate text
This text will be truncated
// Truncate with custom ellipsis
This text will be truncated...
```
## Layout Patterns
### Card Layout
```tsx
const Card: React.FC<{ title: string; children: React.ReactNode }> = ({ title, children }) => (
{title}
{children}
);
```
### Split Layout
```tsx
const SplitLayout: React.FC<{ left: React.ReactNode; right: React.ReactNode }> = ({
left,
right,
}) => (
{left}
{right}
);
```
### Header/Content/Footer
```tsx
const Layout: React.FC<{
header: React.ReactNode;
content: React.ReactNode;
footer: React.ReactNode;
}> = ({ header, content, footer }) => (
{header}
{content}
{footer}
);
```
### Grid Layout
```tsx
const Grid: React.FC<{ items: React.ReactNode[]; columns: number }> = ({ items, columns }) => {
const rows: React.ReactNode[][] = [];
for (let i = 0; i < items.length; i += columns) {
rows.push(items.slice(i, i + columns));
}
return (
{rows.map((row, i) => (
{row.map((item, j) => (
{item}
))}
))}
);
};
```
### Responsive Layout
```tsx
import { useStdout } from 'ink';
const ResponsiveLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { stdout } = useStdout();
const isNarrow = stdout.columns < 80;
return (
{children}
);
};
```
## Utility Components
### Spacer
```tsx
// Push elements apart
Left
Right
```
### Newline
```tsx
First line
After blank line
```
## Best Practices
1. **Use Box for layout**: Don't use Text for layout, use Box
2. **Flexbox thinking**: Think in terms of Flexbox properties
3. **Consistent spacing**: Use consistent margin/padding values
4. **Color sparingly**: Don't overuse colors, use them for emphasis
5. **Test terminals**: Test on different terminal sizes and emulators
## Common Layout Patterns
### Full-width header
```tsx
Application Title
```
### Centered modal
```tsx
Modal content
```
### Sidebar layout
```tsx
Sidebar
Main content
```