---
title: "Data Matrix Code"
description: "A small square code for asset tags, marks on parts, and small packs. It holds an ID or a short record in a few millimeters."
url: https://gelatinui.com/components/data-matrix-code
markdown_url: https://gelatinui.com/components/data-matrix-code.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/data-matrix-code"
version: "2026-11-11"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Data Matrix Code

> A small square code for asset tags, marks on parts, and small packs. It holds an ID or a short record in a few millimeters.

Page: https://gelatinui.com/components/data-matrix-code

## When to use it

Best for: A small square code for an ID on a tag, a part, or a pack, that an industrial scanner reads.

- Use it for an asset ID, a part number, or a serial on a small label.
- Use `pixelSize` for the outer width; the code is never wider.
- Use `plate={false}` when the code sits on your own white label.
- Use `onError` to show your own message when the value is too long.

## When not to use it

- For GS1 data (GTIN, lot, expiry, serial), use a [GS1 Data Matrix Code](https://gelatinui.com/components/gs1-data-matrix-code.md).
- For a link that any phone camera opens, use a [QR Code](https://gelatinui.com/components/qr-code.md).
- For a ticket on a phone screen, use an [Aztec Code](https://gelatinui.com/components/aztec-code.md).

## Notes for agents

- `fit` fills the width of the parent, in whole px a module when that loses one module or less.
- The quiet zone is 1 module and is part of `pixelSize`. The default size is 160px.
- Modules are whole px when that loses at most one module; else the code fills `pixelSize` exactly.
- Too much data (about 2,000 characters of text) shows a help line, not a code, and calls `onError`.
- The plate is white in both themes, so the code scans in dark mode.
- `status` sets loading and empty. `labels` changes the words of the empty and error boxes.
- The code never mirrors right to left.

## Anatomy

```text
DataMatrixCode
```

## API reference

### DataMatrixCode

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `aria-label` | `string` |  | Defines a string value that labels the current element. The accessible name. Default the kind ("Data Matrix code"), or "<kind>: <value>" for a link. |
| `value` | `string` |  | The data etiket encodes. The data: text, a link, or an asset ID. Default size 160px. |
| `pixelSize` | `number` |  | The outer width in px, quiet zone included. The height follows the symbol. |
| `fit` | `boolean` |  | Fill the width of the parent, in whole px a module when that loses one module or less (the QR Code rule), else the exact width. Default false. Wide codes (postal, PDF417) on a phone. |
| `plate` | `boolean` |  | The light plate under the code. Default true. |
| `status` | `DataStatus` |  | The load state. Default `ready`. `loading`: the skeleton while the value is not known yet. `empty`: the empty box. `error` shows as `ready`: the error box is for a value the code cannot hold. |
| `labels` | `Partial<CodeSymbolLabels>` |  | The texts of the empty and error states. |
| `onError` | `function` |  | Runs once for each new error (too much data, a character the kind cannot hold), after commit. It does not run again for the same error, and typed values are deferred: a field that shows the error should derive it from the value with the kind's encoder (cached, so free), not clear it on each change. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| DataMatrixCode | `data-matrix-code` |  |  |  |

## Usage

Pass the asset ID or the part mark.

```tsx title="asset-tag-code.tsx"
import { DataMatrixCode } from "@/components/pro/labels/data-matrix-code";

export function AssetTagCode() {
  return <DataMatrixCode value="NW-IT-00318" pixelSize={96} aria-label="Asset code: NW-IT-00318" />;
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/data-matrix-code
```

It adds 17 registry items: 16 files, 2062 lines, and the npm packages `@mantine/hooks`, `clsx`, `etiket`, `tailwind-merge`, `tailwind-variants`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [GS1 Data Matrix Code](https://gelatinui.com/components/gs1-data-matrix-code.md)
- [QR Code](https://gelatinui.com/components/qr-code.md)
- [Aztec Code](https://gelatinui.com/components/aztec-code.md)

## Accessibility

It is an image named "Data Matrix code" by default, or "Data Matrix code: <link>" for a link. Pass `aria-label` to say what the code is for.

Show the ID as text next to the code too, so people can read it.
