---
title: Form container
description: FormContainer lays out a label, a custom control and an error message the same way as the built-in form fields.
category: Forms
related: [Label, GenericLabel, TextField]
---

Source: https://clickhouse.design/click-ui/formcontainer

# Form container

FormContainer wraps a control with a label and an optional error message, using the same layout as TextField, Select and the other form fields. Use it when you place a custom control in a form and want it to line up with the rest.

## Example

## Props

FormContainer also accepts the attributes of a `div`.

| Prop            | Type                         | Default value | Description                                                                           |
| --------------- | ---------------------------- | ------------- | ------------------------------------------------------------------------------------- |
| htmlFor \*      | `string`                     | `required`    | The id of the control the label belongs to                                            |
| children \*     | `ReactNode`                  | `required`    | The control to lay out                                                                |
| label           | `ReactNode`                  | `undefined`   | The label text                                                                        |
| orientation     | `"vertical" \| "horizontal"` | `undefined`   | Whether the label sits above or beside the control                                    |
| dir             | `"start" \| "end"`           | `undefined`   | Which side of the control the label sits on                                           |
| error           | `ReactNode`                  | `undefined`   | Error message shown with the control. The label takes the error colour                |
| addLabelPadding | `boolean`                    | `undefined`   | Adds padding to the label so it lines up with a taller control in a horizontal layout |

```tsx
import { FormContainer } from '@clickhouse/click-ui'

<FormContainer htmlFor="cluster-name" label="Cluster name">
  <input id="cluster-name" />
</FormContainer>
```

## Quick start

```tsx
import { FormContainer } from '@clickhouse/click-ui'

function ClusterName({ error }: { error?: string }) {
  return (
    <FormContainer htmlFor='cluster-name' label='Cluster name' error={error}>
      <input id='cluster-name' aria-invalid={!!error} />
    </FormContainer>
  )
}
```

## Accessibility

The label is connected to the control through `htmlFor`, so the control inside must have the matching `id` and must be a labelable element such as `input`, `select` or `textarea`.

## Related components

- **Label**: The label element FormContainer renders.
- **GenericLabel**: A label for checkboxes, radios and switches.
- **TextField**: A text input that already includes this layout.

## Common use cases

### Horizontal layout with an error
