Skip to content
Nizivo UI

Container

Centres page content: at most --nz-layout-content-max wide (358, 976, 1280 px by viewport), with the responsive page margin --nz-grid-margin (16, 24, 32 px) on both sides.

Server component, no client JS

Import

import { Container } from '@nizivo/react/container';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/container.css';

Static or interactive

Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build mode; its code is bundled only when a client component (a 'use client' file) imports it. How to choose.

In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.

Examples

Basic

Page content, centred, with the responsive page margin.

import type { JSX } from 'react';
import { Container } from '@nizivo/react/container';

export function ContainerExample(): JSX.Element {
  return (
    <Container render={<main />}>
      <p>Page content, centred, with the responsive page margin.</p>
    </Container>
  );
}

Props

Centres page content: at most --nz-layout-content-max wide (358, 976, 1280 px by viewport), with the responsive page margin --nz-grid-margin (16, 24, 32 px) on both sides.

Server component Renders data-slot="container" with the class nz-container. Props: ContainerProps. Source: src/container/container.tsx.

NameTypeDefaultDescription
renderRenderProp<Record<string, never>>–

Another element, for example render={<main />}.

  • Also takes every attribute of <div>. (ComponentPropsWithRef<"div">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

ContainerProps type

import type { ContainerProps } from '@nizivo/react/container'

The props of Container, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
container
.nz-container
Container
root (takes render)
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

HookDefaultRead as
--nz-container-max-width--nz-layout-content-max
  • max-inline-size on .nz-container
--nz-container-padding-inline--nz-grid-margin
  • padding-inline on .nz-container

Layers: nz.components. Classes: .nz-container.

Tokens this stylesheet reads (2)

--nz-grid-margin, --nz-layout-content-max

Accessibility

Nothing in this component takes focus or keyboard input.

Keyboard

None.

Figma

Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.

  • Canonical: none
  • Ghost masters: none

On this page