Skip to content

Responsive

Components for showing/hiding content based on screen size.

import { Show, Hide } from 'asterui'

Uses the same breakpoints as Tailwind CSS:

BreakpointMin Width
xs0px
sm640px
md768px
lg1024px
xl1280px
2xl1536px

Show Above Breakpoint

Show content only at medium screens and above.

import { Show, Button } from 'asterui'

function App() {
  return (
      <Show above="md">
        <Button color="primary">Visible on md and larger</Button>
      </Show>
    )
}

export default App

Hide Below Breakpoint

Hide content on small screens.

import { Hide, Alert } from 'asterui'

function App() {
  return (
      <Hide below="md">
        <Alert type="info">This is hidden on small screens</Alert>
      </Hide>
    )
}

export default App

Show At Specific Breakpoints

Show content only at specific breakpoints.

import { Show, Alert } from 'asterui'

function App() {
  return (
      <Show at="xs">
        <Alert type="info">Mobile view (xs)</Alert>
      </Show>
      <Show at="sm">
        <Alert type="warning">Small screen (sm)</Alert>
      </Show>
      <Show at={['md', 'lg']}>
        <Alert type="success">Tablet or small desktop (md/lg)</Alert>
      </Show>
      <Show at={['xl', '2xl']}>
        <Alert type="info">Large desktop (xl/2xl)</Alert>
      </Show>
    )
}

export default App

Show Between Breakpoints

Show content within a range of breakpoints.

Responsive Content

Visible on sm, md, and lg screens only
import { Show, Card } from 'asterui'

function App() {
  return (
      <Show between={['sm', 'lg']}>
        <Card title="Responsive Content" className="bg-base-200">
          Visible on sm, md, and lg screens only
        </Card>
      </Show>
    )
}

export default App

Responsive Layout

Build different layouts for mobile and desktop.

Logo
import { Show, Hide, Flex, Button } from 'asterui'

function App() {
  return (
      <Flex justify="between" align="center" className="p-4 bg-base-200 rounded-lg">
        <div className="font-bold">Logo</div>
        <Show above="md">
          <Flex gap="md">
            <Button variant="ghost" size="sm">
              Home
            </Button>
            <Button variant="ghost" size="sm">
              About
            </Button>
            <Button variant="ghost" size="sm">
              Contact
            </Button>
          </Flex>
        </Show>
        <Hide above="md">
          <Button variant="ghost" size="sm">
            Menu
          </Button>
        </Hide>
      </Flex>
    )
}

export default App
PropertyDescriptionTypeDefault
childrenContent to show/hideReact.ReactNode-
aboveShow/hide at this breakpoint and aboveBreakpoint-
belowShow/hide below this breakpointBreakpoint-
atShow/hide at exactly this breakpoint (or array of breakpoints)Breakpoint | Breakpoint[]-
betweenShow/hide between two breakpoints (inclusive)[Breakpoint, Breakpoint]-
data-testidTest ID for testingstring-
  • Uses JavaScript to detect breakpoint, not CSS media queries
  • Only one condition prop (above, below, at, or between) should be used at a time
  • Server-side rendering defaults to 1024px width (lg breakpoint)

See also: useBreakpoint hook for programmatic access to breakpoint info.