---
title: "Center · UI SDK — StyleX Blocks"
description: "Centering layout primitives (Center, Square, and Circle) that align children on both axes with token-sized geometry."
url: "https://stylexblocks.com/components/ui-sdk/center/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Center

Centering layout primitives (Center, Square, and Circle) that align children on both axes with token-sized geometry.

- Behavior engine: UI SDK
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/center.md), [Base UI](https://stylexblocks.com/components/base-ui/center.md)
- Category: Layout
- Used in blocks: [AI Chat Conversation](https://stylexblocks.com/block/ui-sdk/ai-chat.md), [Basic Login](https://stylexblocks.com/block/ui-sdk/basic-login.md), [Canvas Editor](https://stylexblocks.com/block/ui-sdk/canvas-editor.md), [Checkout Form](https://stylexblocks.com/block/ui-sdk/checkout-form.md), [Collapsible Table](https://stylexblocks.com/block/ui-sdk/collapsible-table.md), [Comparison Table](https://stylexblocks.com/block/ui-sdk/comparison-table.md), [Data Dashboard](https://stylexblocks.com/block/ui-sdk/data-dashboard.md), [Documentation Catalog](https://stylexblocks.com/block/ui-sdk/documentation-catalog.md), [Documentation Technical](https://stylexblocks.com/block/ui-sdk/documentation-technical.md), [Executive Dashboard](https://stylexblocks.com/block/ui-sdk/executive-dashboard.md), [File Explorer](https://stylexblocks.com/block/ui-sdk/file-explorer.md), [Filterable Table](https://stylexblocks.com/block/ui-sdk/filterable-table.md), [Inline Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-inline.md), [Vertical Wizard](https://stylexblocks.com/block/ui-sdk/form-wizard-vertical.md), [Grouped Table](https://stylexblocks.com/block/ui-sdk/grouped-table.md), [IDE Workspace](https://stylexblocks.com/block/ui-sdk/ide.md), [Inbox Table](https://stylexblocks.com/block/ui-sdk/inbox-table.md), [Incident Console](https://stylexblocks.com/block/ui-sdk/incident-console.md), [Kanban Board](https://stylexblocks.com/block/ui-sdk/kanban-board.md), [Login Split](https://stylexblocks.com/block/ui-sdk/login-split.md), [Login SSO](https://stylexblocks.com/block/ui-sdk/login-sso.md), [Messaging Shell](https://stylexblocks.com/block/ui-sdk/messaging-shell.md), [Mixed Gallery](https://stylexblocks.com/block/ui-sdk/mixed-gallery.md), [Page Editor](https://stylexblocks.com/block/ui-sdk/page-editor.md), [Settings Dialog](https://stylexblocks.com/block/ui-sdk/settings-dialog.md), [Settings Form](https://stylexblocks.com/block/ui-sdk/settings-form.md), [Shell Nav](https://stylexblocks.com/block/ui-sdk/shell-nav.md), [Theme Showcase](https://stylexblocks.com/block/ui-sdk/theme-showcase.md), [Tree Table](https://stylexblocks.com/block/ui-sdk/tree-table.md)
- HTML page: https://stylexblocks.com/components/ui-sdk/center/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add center
```

Equivalent: `npx shadcn add @stylexblocks/center`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/center.json

## Usage

```tsx
import { Center, Square, Circle } from "#components/ui/ui-sdk/center.tsx";

export function Example() {
  return (
    <>
      <Center>Centered content</Center>
      <Square size="lg">Sq</Square>
      <Circle size="lg">42</Circle>
    </>
  );
}
```

## Source

`components/ui/ui-sdk/center.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ui-sdk/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { radii } from "@stylexblocks/ui/tokens/radii.stylex.ts";
import { sizes } from "@stylexblocks/ui/tokens/sizes.stylex.ts";

const centerStyles = stylex.create({
  base: {
    alignItems: "center",
    justifyContent: "center",
  },
});

const centerDisplays = stylex.create({
  block: { display: "flex" },
  inline: { display: "inline-flex" },
});

const centerRecipe = defineRecipe({
  styles: centerStyles,
  axes: { display: centerDisplays },
  defaultVariants: { display: "block" },
});

/**
 * Center — flex container that centers its children on both axes.
 * Composition via `render`.
 */
export const Center = createComponent("div", centerRecipe, "Center");
export type CenterProps = React.ComponentProps<typeof Center>;

const boxStyles = stylex.create({
  base: {
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center",
    flexShrink: 0,
    flexGrow: 0,
  },
});

const boxSizes = stylex.create({
  xs: { width: sizes._6, height: sizes._6 },
  sm: { width: sizes._8, height: sizes._8 },
  md: { width: sizes._10, height: sizes._10 },
  lg: { width: sizes._12, height: sizes._12 },
  xl: { width: sizes._14, height: sizes._14 },
  "2xl": { width: sizes._16, height: sizes._16 },
});

const squareRecipe = defineRecipe({
  styles: boxStyles,
  axes: { size: boxSizes },
  defaultVariants: { size: "md" },
});

/** Square — fixed-size centered box (`width === height`). */
export const Square = createComponent("div", squareRecipe, "Square");
export type SquareProps = React.ComponentProps<typeof Square>;

const circleStyles = stylex.create({
  base: {
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center",
    flexShrink: 0,
    flexGrow: 0,
    borderRadius: radii.full,
  },
});

const circleRecipe = defineRecipe({
  styles: circleStyles,
  axes: { size: boxSizes },
  defaultVariants: { size: "md" },
});

/** Circle — fixed-size centered circular box (`borderRadius: full`). */
export const Circle = createComponent("div", circleRecipe, "Circle");
export type CircleProps = React.ComponentProps<typeof Circle>;
```
