---
title: "Center · Ark UI — 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/ark-ui/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: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/center.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/center.md)
- Category: Layout
- HTML page: https://stylexblocks.com/components/ark-ui/center/

## Install

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

```sh
npx stylexblocks init
```

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/ark-ui/center.json

## Usage

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

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

## Source

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

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/ark-ui/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 `asChild`.
 */
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>;
```
