Responsive Design

Yamada UI provides features to change styles according to the screen size.

Overview

Responsive design refers to the breakpoints defined in the theme. Yamada UI has a Default Theme where breakpoints are defined.

Usage

To set responsive design to Style Props, set an object with the breakpoints as the key.

  • The keys of the object define the keys set in the theme's Breakpoints.
  • The values of the object define the values of the styles set by the key.
Box

The above code generates the following CSS:

.Box {
  background: var(--ui-colors-bg-contrast);

  @media screen and (max-width: 768px) {
    background: var(--ui-colors-success);
  }
}

Utilities

Yamada UI provides useful custom hooks for building responsive layouts.

useBreakpoint

A custom hook that returns the current breakpoint. This hook monitors the window size and returns the appropriate value.

useBreakpointEffect

A custom hook that executes a specific callback function when the breakpoint changes.

useUpdateBreakpointEffect

A custom hook that skips the side effect on the initial render and executes a specific callback function when the breakpoint changes.

useBreakpointState

A custom hook that returns the current breakpoint from the provided object as the initial value.

useBreakpointValue

A custom hook that returns the value of the current breakpoint from the provided object. This hook monitors changes in the window size and returns the appropriate value.