# Responsive Design
URL: /react/components/concepts/responsive-design
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/concepts/responsive-design.mdx
Learn how to adjust layouts and styles according to viewport size.
Crispy provides a mobile-first responsive system. When you specify a value at a specific breakpoint, that same value is applied to wider viewports.
## Breakpoints
| Name | `min-width` |
| ------ | ----------- |
| `base` | 0px |
| `sm` | 480px |
| `md` | 768px |
| `lg` | 1280px |
| `xl` | 1440px |
## Using Responsive Props in Layout Components
`Box` and Box-based components (`Flex`, `Grid`, `VStack`, `HStack`, etc.) can accept objects with breakpoint names as keys for layout property values.
```tsx
```
| Category | Property |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **Layout** | `display`, `flexDirection`, `gap` |
| **Sizing** | `width`, `minWidth`, `maxWidth`, `height`, `minHeight`, `maxHeight` |
| **Padding** | `padding`, `paddingX`, `paddingY`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`, `p`, `px`, `py`, `pt`, `pr`, `pb`, `pl` |
| **Bleed** | `bleedX`, `bleedY`, `bleedTop`, `bleedRight`, `bleedBottom`, `bleedLeft` |
```tsx
import { Box } from "@seed-design/react";
export default function ResponsivePropsExample() {
return (
{`padding={{ base: "x4", md: "x6", xl: "x8" }}`}
);
}
```
Box component is the most basic layout component. It helps you use design tokens in JSX.
Flex component uses flexbox and helps you use design tokens in JSX.
Grid component uses CSS Grid and helps you use design tokens in JSX.
Creates a vertically stacking layout. It helps you use design tokens in JSX.
Creates a horizontally stacking layout. It helps you use design tokens in JSX.
### Hiding & Showing Elements
You can pass responsive values to `display` to show or hide elements at specific breakpoints.
```tsx
import { VStack, Text, Box } from "@seed-design/react";
export default function ResponsiveDisplayExample() {
return (
아래 Box는 md breakpoint 이상에서만 보입니다.
{`display={{ base: "none", md: "block" }}`}
);
}
```
#### `hideFrom`
Use `hideFrom` to hide elements at a specific breakpoint and above. (`display: none;`)
Can be used in `Box` and Box-based components (`Flex`, `Grid`, `VStack`, `HStack`, etc.).
`hideFrom="md"` is equivalent to `display={{ md: "none" }}`.
```tsx
import { Box, VStack, Text } from "@seed-design/react";
export default function HideFromExample() {
return (
아래 Box는 xl breakpoint 이상에서는 숨겨집니다.
hideFrom="xl"
);
}
```
### Grid
You can specify `columns` and `rows` attributes for each breakpoint.
```tsx
import { Box, Grid, Text, VStack } from "@seed-design/react";
export default function ResponsiveGridExample() {
return (
아래 Grid는 breakpoint 별로 열 수가 다르게 구성됩니다.
1
2
3
4
);
}
```
Grid component uses CSS Grid and helps you use design tokens in JSX.
## Hooks
Provides `useBreakpoint` and `useBreakpointValue` hooks implemented based on `window.matchMedia`.
Whenever possible, use responsive props that work CSS-based, and use hooks only when JS logic is needed.
### `useBreakpoint`
Returns the current breakpoint name.
```tsx
import { Box, useBreakpoint } from "@seed-design/react";
export default function UseBreakpointExample() {
const breakpoint = useBreakpoint();
return (
{breakpoint}
);
}
```
### `useBreakpointValue`
Resolves the responsive value object passed as a parameter to the value that matches the current viewport.
```tsx
import { ActionButton, ActionButtonProps } from "seed-design/ui/action-button";
import { useBreakpointValue, VStack, Text } from "@seed-design/react";
export default function UseBreakpointValueExample() {
const actionButtonProps = useBreakpointValue({
base: {
variant: "neutralWeak",
children: "variant=neutralWeak",
},
lg: {
variant: "brandSolid",
children: "variant=brandSolid",
},
});
return (
아래 ActionButton은 lg breakpoint에서 variant가 변경됩니다.
);
}
```
### Server-Side Rendering
To define a default breakpoint value to be applied when using hooks in an environment where viewport information is unknown (such as SSR), specify `defaultBreakpoint` via `BreakpointProvider`.
If you call a hook outside `BreakpointProvider` but `window.matchMedia` is not available, `useBreakpoint` returns `base`, and `useBreakpointValue` returns the value of the `base` key.
```tsx
import { BreakpointProvider } from "@seed-design/react";
function App() {
return (
);
}
```