Form layout

Form layout arranges form fields in one or more columns with consistent spacing between them. It is a layout container only: it does not submit, validate or label anything, and it adds no role or form semantics. The fields inside it keep their own labels and still submit with the surrounding <form>.

When to Use

✅ Use form layout when:

  • A form has several fields that should share the same vertical spacing.
  • Short, related fields (given name and family name, postcode and city) can sit side by side on wide screens.

❌ Don't use form layout when:

  • You need to arrange content that is not form fields; use dap-ds-stack instead.
  • A field should span several columns. Column spanning is not supported; put that field outside the layout or in a separate one-column layout.
Examples Default form layout

By default the fields are in one column, with a gap of --dds-spacing-600 / 24px between them.

Columns

Set columns to 2 or 3 to place the fields in that many equal columns, filled row by row in source order. Values outside 1 to 3 clamp to the nearest bound, and a non-numeric value uses 1.

Narrow containers

The columns follow the width of the form layout itself, not the width of the viewport. When the form layout is narrower than 480px, it shows one column whatever its columns value, so the same form works in a wide page and in a narrow side panel or modal.

The threshold is a fixed size. It cannot be changed with a CSS custom property, because CSS custom properties cannot be used in container query conditions. The form layout is a CSS size container (container-type: inline-size), so it takes its width from its parent and not from its content: inside a flex row, give it a width.

Inside a form

Form layout is not a form element and owns no submission or validation. Put it inside your own <form>; the fields in it submit their values with that form as usual.

Continue
Custom spacing

Set the --dds-form-layout-gap custom property to change the space between the fields. It applies between rows and between columns.

Accessibility
  • Form layout renders no role and is not form-associated, so assistive technology reads the fields as if the layout were not there.
  • Fields are read and focused in source order. On wide screens that order runs row by row, left to right, so put related fields next to each other in the markup.
  • Every DDS field renders its own label above its control; form layout does not move labels beside fields.
Importing Per-component import (Recommended)

Import the component by its own subpath. This registers <dap-ds-form-layout> (and the components it renders internally) and lets your bundler include only what you use:

import 'dap-design-system/components/form-layout'

Need a reference to the class (e.g. to register it manually or extend it)? The same subpath default-exports it:

import DapDSFormLayout from 'dap-design-system/components/form-layout'
Register everything

Register the whole library at once — convenient, but pulls every component into your bundle:

import 'dap-design-system'
Importing React
import { DapDSFormLayoutReact } from 'dap-design-system/react'
Attributes
PropertyTypeDefaultDescription
columns1, 2 , 31The number of columns, from 1 to 3. Values outside that range clamp to the nearest bound; a non-numeric value uses 1. The layout always collapses to one column when the element is narrower than 480px.
ariaLabelstring, nullnullAccessible label for the element. Use this to provide a text alternative
for elements that don't have visible text content.
ariaExpanded'true', 'false'nullIndicates whether the element is expanded or collapsed.
ariaControlsstring, nullnullIdentifies the element that is controlled by this element.
ariaHasPopupstring, nullnullIndicates the availability and type of interactive popup element.
ariaDescribedBystring, nullnullIdentifies the element that describes the current element.
ariaPressed'true', 'false' , 'mixed'nullIndicates the current "pressed" state of toggle buttons.
ariaHidden'true', 'false'nullIndicates whether the element is hidden from accessibility APIs.
customStylesstring, undefinedCustom CSS text to be merged with the component's styles.
This CSS will be injected into the shadow DOM and merged with the component's static styles.
Slots
NameDescription
(default)The form fields to arrange.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe grid container of the fields.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-form-layout::part(base) {
  /* Your custom styles */
}

Example usage:

<dap-ds-form-layout class="my-custom-dap-ds-form-layout">
  Form layout
</dap-ds-form-layout>
.my-custom-dap-ds-form-layout::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-form-layout-gapSpace between the fields, both between rows and between columns (default: var(--dds-spacing-600))
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-form-layout
  style="--dds-form-layout-gap: value; ">
  Form layout
</dap-ds-form-layout>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-form-layout {
  --dds-form-layout-gap: value;
}
<dap-ds-form-layout class="my-custom-dap-ds-form-layout">
  Form layout
</dap-ds-form-layout>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-form-layout {
  --dds-form-layout-gap: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.