# Density settings

With the density settings pattern, users can define the preferred density level of the content visible within the interface.

 [View demo](/examples/react/dashboard.html?awsui-density=compact)
## Objectives

### Service level settings

When implementing [density modes](/foundation/visual-foundation/content-density/index.html.md) in your service, you must provide users with a mechanism to choose between comfortable and compact mode. With this pattern, you can set up service-level settings for density modes. Make sure when you use this pattern, you store the user's preference across all pages within your service.

## Building blocks

A B C D E F
#### A. Density settings link

Use a [side navigation link](/components/side-navigation/index.html.md) to trigger a modal. Place the link as last item in your side navigation and separate it from the other links with a divider. If your service already has a settings area include the content density selection there.

#### B. Modal

Use a modal to display the appearance settings.

#### C. Form field label

Include a form field label and description to provide context to users.

#### D. Tiles

Use tiles so that users can select a mode. Include label, description, and image in both options.

#### E. Form actions

Include form actions so that users can confirm or cancel their choice.

#### F. Dismiss button

Include a dismiss button to close the modal. Upon dismiss no changes are applied.

## Scenarios

### Full implementation

When compact mode is fully available in your service implement the density settings and provide context to your users via form field description.

Content density Choose the preferred level of content density for this console. Comfortable Compact
```density-settings.tsx
import React, { useState } from 'react';
import { FormField, Tiles } from '@cloudscape-design/components';
import {
  colorBackgroundButtonPrimaryDefault,
  colorBackgroundButtonPrimaryDisabled,
  colorBackgroundContainerContent,
  colorBackgroundControlDisabled,
  colorBackgroundHomeHeader,
  colorBackgroundLayoutMain,
  colorBorderDividerDefault,
  colorTextBodyDefault,
  colorTextBodySecondary,
  colorTextInputDisabled,
} from '@cloudscape-design/design-tokens/index.js';

/** Colors of the density preview illustration, taken from design tokens so they follow the theme. */
const svgStyles = {
  window: { stroke: colorBackgroundHomeHeader, fill: colorBackgroundContainerContent },
  topNavigation: { fill: colorBackgroundButtonPrimaryDisabled },
  header: { fill: colorBackgroundLayoutMain },
  default: { fill: colorTextBodyDefault },
  primary: { fill: colorBackgroundButtonPrimaryDefault },
  disabled: { fill: colorBackgroundControlDisabled },
  columnHeader: { fill: colorTextInputDisabled },
  secondary: { fill: colorTextBodySecondary },
  separator: { stroke: colorBorderDividerDefault },
} satisfies Record<string, React.CSSProperties>;

const WindowPath = () => (
  <path
    d="M24 1.00006H211C211.552 1.00006 212 1.44778 212 2.00006V105C212 105.552 211.552 106 211 106H24C23.4477 106 23 105.552 23 105V2.00006C23 1.44778 23.4477 1.00006 24 1.00006Z"
    style={svgStyles.window}
    strokeWidth="2"
  />
);
const TopNavigation = () => (
  <g className="awsui-context-top-navigation">
    <rect x="24" y="2" width="187" height="6" style={svgStyles.topNavigation} />
  </g>
);

interface TableRowProps {
  offset: number;
  separator?: boolean;
  compact?: boolean;
  isHeader?: boolean;
}

const TableRow = ({ offset, separator = true, compact = false, isHeader = false }: TableRowProps) => {
  const offsetTop = 0.4482;
  const offsetBottom = 3.4482;
  const separatorDistance = compact ? 7 : 8;
  return (
    <g transform={`translate(0, ${offset})`} style={isHeader ? svgStyles.columnHeader : svgStyles.disabled}>
      <path d={`M53 ${offsetTop}H56V${offsetBottom}H53V${offsetTop}Z`} />
      <path
        d={`M61 ${offsetTop}H85V${offsetBottom}H61V${offsetTop}Z`}
        style={isHeader ? undefined : svgStyles.secondary}
      />
      <path d={`M138 ${offsetTop}H118V${offsetBottom}H138V${offsetTop}Z`} />
      <path d={`M185 ${offsetTop}H141V${offsetBottom}H185V${offsetTop}Z`} />
      {separator && <path d={`M48 ${separatorDistance}H187.387`} style={svgStyles.separator} strokeLinecap="square" />}
    </g>
  );
};

interface TableRowsProps {
  offsetTop: number;
  rows: number;
  compact?: boolean;
}

const TableRows = ({ offsetTop, rows, compact = false }: TableRowsProps) => {
  const distance = compact ? 10 : 13;
  return (
    <g>
      {[...Array(rows)].map((_, index) => (
        <TableRow key={index} offset={offsetTop + index * distance} compact={compact} separator={index + 1 !== rows} />
      ))}
    </g>
  );
};
const comfortableImage = (
  <svg viewBox="0 0 230 107" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden={true}>
    <WindowPath />
    <TopNavigation />
    <g>
      <path style={svgStyles.header} d="M24 8.00006H211V28.0001H24V8.00006Z" />
      <g style={svgStyles.default}>
        <circle cx="29" cy="17.5001" r="2.5" style={svgStyles.disabled} />
        <path d="M47 16.0001H77.1484V19.0001H47V16.0001Z" />
        <path d="M121 17.5C121 15.567 122.567 14 124.5 14H137.86C139.793 14 141.36 15.567 141.36 17.5V17.5C141.36 19.433 139.793 21 137.86 21H124.5C122.567 21 121 19.433 121 17.5V17.5Z" />
        <path d="M145 17.5C145 15.567 146.567 14 148.5 14H161.86C163.793 14 165.36 15.567 165.36 17.5V17.5C165.36 19.433 163.793 21 161.86 21H148.5C146.567 21 145 19.433 145 17.5V17.5Z" />
        <path
          d="M168 17.5C168 15.567 169.567 14 171.5 14H184.86C186.793 14 188.36 15.567 188.36 17.5V17.5C188.36 19.433 186.793 21 184.86 21H171.5C169.567 21 168 19.433 168 17.5V17.5Z"
          style={svgStyles.primary}
        />
        <circle cx="206.5" cy="17.5001" r="2.5" style={svgStyles.disabled} />
      </g>
    </g>
    <TableRow offset={32} isHeader={true} />

    <TableRows offsetTop={45} rows={5} />
  </svg>
);
const compactImage = (
  <svg viewBox="0 0 230 107" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden={true}>
    <WindowPath />
    <TopNavigation />
    <g>
      <path style={svgStyles.header} d="M24 8.00006H211V24.0001H24V8.00006Z" />
      <g style={svgStyles.default}>
        <circle cx="29" cy="15.5001" r="2.5" style={svgStyles.disabled} />
        <path d="M47 14H77.1484V17H47V14Z" />
        <path d="M121 15C121 13.8954 121.895 13 123 13H139.36C140.465 13 141.36 13.8954 141.36 15V15C141.36 16.1046 140.465 17 139.36 17H123C121.895 17 121 16.1046 121 15V15Z" />
        <path d="M145 15C145 13.8954 145.895 13 147 13H163.36C164.465 13 165.36 13.8954 165.36 15V15C165.36 16.1046 164.465 17 163.36 17H147C145.895 17 145 16.1046 145 15V15Z" />
        <path
          d="M168 15C168 13.8954 168.895 13 170 13H186.36C187.465 13 188.36 13.8954 188.36 15V15C188.36 16.1046 187.465 17 186.36 17H170C168.895 17 168 16.1046 168 15V15Z"
          style={svgStyles.primary}
        />
        <circle cx="206.5" cy="15.5001" r="2.5" style={svgStyles.disabled} />
      </g>
    </g>
    <TableRow offset={27} compact={true} isHeader={true} />
    <TableRows offsetTop={37} compact={true} rows={7} />
  </svg>
);

export const comfortableModeImage = comfortableImage;

export const compactModeImage = compactImage;

interface DensitySettingsBuilder {
  description: string;
}
export default function DensitySettingsBuilder({ description }: DensitySettingsBuilder) {
  return function Component() {
    const [value, setValue] = useState<string>('item1');
    return (
      <FormField description={description} label="Content density">
        <Tiles
          value={value}
          onChange={e => setValue(e.detail.value)}
          columns={4}
          items={[
            {
              label: 'Comfortable',
              image: comfortableImage,
              value: 'item1',
            },
            {
              label: 'Compact',
              image: compactImage,
              value: 'item2',
            },
          ]}
        />
      </FormField>
    );
  };
}
```

### Partial implementation

When compact mode is partially available in your service, for example due to version migration strategies or rollout in only some sub-services, include additional information in the form field description to set expectations for users.

Content density Choose the preferred level of content density of this console. The compact experience is available for some features in this console. Comfortable Compact
```density-settings-partial.tsx
import React, { useState } from 'react';
import { FormField, Tiles } from '@cloudscape-design/components';
import {
  colorBackgroundButtonPrimaryDefault,
  colorBackgroundButtonPrimaryDisabled,
  colorBackgroundContainerContent,
  colorBackgroundControlDisabled,
  colorBackgroundHomeHeader,
  colorBackgroundLayoutMain,
  colorBorderDividerDefault,
  colorTextBodyDefault,
  colorTextBodySecondary,
  colorTextInputDisabled,
} from '@cloudscape-design/design-tokens/index.js';

/** Colors of the density preview illustration, taken from design tokens so they follow the theme. */
const svgStyles = {
  window: { stroke: colorBackgroundHomeHeader, fill: colorBackgroundContainerContent },
  topNavigation: { fill: colorBackgroundButtonPrimaryDisabled },
  header: { fill: colorBackgroundLayoutMain },
  default: { fill: colorTextBodyDefault },
  primary: { fill: colorBackgroundButtonPrimaryDefault },
  disabled: { fill: colorBackgroundControlDisabled },
  columnHeader: { fill: colorTextInputDisabled },
  secondary: { fill: colorTextBodySecondary },
  separator: { stroke: colorBorderDividerDefault },
} satisfies Record<string, React.CSSProperties>;

const WindowPath = () => (
  <path
    d="M24 1.00006H211C211.552 1.00006 212 1.44778 212 2.00006V105C212 105.552 211.552 106 211 106H24C23.4477 106 23 105.552 23 105V2.00006C23 1.44778 23.4477 1.00006 24 1.00006Z"
    style={svgStyles.window}
    strokeWidth="2"
  />
);
const TopNavigation = () => (
  <g className="awsui-context-top-navigation">
    <rect x="24" y="2" width="187" height="6" style={svgStyles.topNavigation} />
  </g>
);

interface TableRowProps {
  offset: number;
  separator?: boolean;
  compact?: boolean;
  isHeader?: boolean;
}

const TableRow = ({ offset, separator = true, compact = false, isHeader = false }: TableRowProps) => {
  const offsetTop = 0.4482;
  const offsetBottom = 3.4482;
  const separatorDistance = compact ? 7 : 8;
  return (
    <g transform={`translate(0, ${offset})`} style={isHeader ? svgStyles.columnHeader : svgStyles.disabled}>
      <path d={`M53 ${offsetTop}H56V${offsetBottom}H53V${offsetTop}Z`} />
      <path
        d={`M61 ${offsetTop}H85V${offsetBottom}H61V${offsetTop}Z`}
        style={isHeader ? undefined : svgStyles.secondary}
      />
      <path d={`M138 ${offsetTop}H118V${offsetBottom}H138V${offsetTop}Z`} />
      <path d={`M185 ${offsetTop}H141V${offsetBottom}H185V${offsetTop}Z`} />
      {separator && <path d={`M48 ${separatorDistance}H187.387`} style={svgStyles.separator} strokeLinecap="square" />}
    </g>
  );
};

interface TableRowsProps {
  offsetTop: number;
  rows: number;
  compact?: boolean;
}

const TableRows = ({ offsetTop, rows, compact = false }: TableRowsProps) => {
  const distance = compact ? 10 : 13;
  return (
    <g>
      {[...Array(rows)].map((_, index) => (
        <TableRow key={index} offset={offsetTop + index * distance} compact={compact} separator={index + 1 !== rows} />
      ))}
    </g>
  );
};
const comfortableImage = (
  <svg viewBox="0 0 230 107" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden={true}>
    <WindowPath />
    <TopNavigation />
    <g>
      <path style={svgStyles.header} d="M24 8.00006H211V28.0001H24V8.00006Z" />
      <g style={svgStyles.default}>
        <circle cx="29" cy="17.5001" r="2.5" style={svgStyles.disabled} />
        <path d="M47 16.0001H77.1484V19.0001H47V16.0001Z" />
        <path d="M121 17.5C121 15.567 122.567 14 124.5 14H137.86C139.793 14 141.36 15.567 141.36 17.5V17.5C141.36 19.433 139.793 21 137.86 21H124.5C122.567 21 121 19.433 121 17.5V17.5Z" />
        <path d="M145 17.5C145 15.567 146.567 14 148.5 14H161.86C163.793 14 165.36 15.567 165.36 17.5V17.5C165.36 19.433 163.793 21 161.86 21H148.5C146.567 21 145 19.433 145 17.5V17.5Z" />
        <path
          d="M168 17.5C168 15.567 169.567 14 171.5 14H184.86C186.793 14 188.36 15.567 188.36 17.5V17.5C188.36 19.433 186.793 21 184.86 21H171.5C169.567 21 168 19.433 168 17.5V17.5Z"
          style={svgStyles.primary}
        />
        <circle cx="206.5" cy="17.5001" r="2.5" style={svgStyles.disabled} />
      </g>
    </g>
    <TableRow offset={32} isHeader={true} />

    <TableRows offsetTop={45} rows={5} />
  </svg>
);
const compactImage = (
  <svg viewBox="0 0 230 107" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden={true}>
    <WindowPath />
    <TopNavigation />
    <g>
      <path style={svgStyles.header} d="M24 8.00006H211V24.0001H24V8.00006Z" />
      <g style={svgStyles.default}>
        <circle cx="29" cy="15.5001" r="2.5" style={svgStyles.disabled} />
        <path d="M47 14H77.1484V17H47V14Z" />
        <path d="M121 15C121 13.8954 121.895 13 123 13H139.36C140.465 13 141.36 13.8954 141.36 15V15C141.36 16.1046 140.465 17 139.36 17H123C121.895 17 121 16.1046 121 15V15Z" />
        <path d="M145 15C145 13.8954 145.895 13 147 13H163.36C164.465 13 165.36 13.8954 165.36 15V15C165.36 16.1046 164.465 17 163.36 17H147C145.895 17 145 16.1046 145 15V15Z" />
        <path
          d="M168 15C168 13.8954 168.895 13 170 13H186.36C187.465 13 188.36 13.8954 188.36 15V15C188.36 16.1046 187.465 17 186.36 17H170C168.895 17 168 16.1046 168 15V15Z"
          style={svgStyles.primary}
        />
        <circle cx="206.5" cy="15.5001" r="2.5" style={svgStyles.disabled} />
      </g>
    </g>
    <TableRow offset={27} compact={true} isHeader={true} />
    <TableRows offsetTop={37} compact={true} rows={7} />
  </svg>
);

export const comfortableModeImage = comfortableImage;

export const compactModeImage = compactImage;

interface DensitySettingsBuilder {
  description: string;
}
export default function DensitySettingsBuilder({ description }: DensitySettingsBuilder) {
  return function Component() {
    const [value, setValue] = useState<string>('item1');
    return (
      <FormField description={description} label="Content density">
        <Tiles
          value={value}
          onChange={e => setValue(e.detail.value)}
          columns={4}
          items={[
            {
              label: 'Comfortable',
              image: comfortableImage,
              value: 'item1',
            },
            {
              label: 'Compact',
              image: compactImage,
              value: 'item2',
            },
          ]}
        />
      </FormField>
    );
  };
}
```

## Feature announcement

- Customize your view experience   You can now customize the level of content density for CloudFront console density settings. [Let us know what you think](about:blank/index.html.md)  .   Open density settings

```density-settings-flashbar.tsx
import React from 'react';
import { Flashbar, FlashbarProps } from '@cloudscape-design/components';

export default function FlashbarBuilder(props: FlashbarProps) {
  return function Component() {
    return <Flashbar {...props} />;
  };
}
```

We recommend communicating the release of the compact mode to your users, for example by using a [flash message](/components/flashbar/index.html.md) . Include information about compact mode release, and an [action button](/components/button/index.html.md) to choose the preferred density level via density settings modal.
You can optionally include a link to allow users to provide feedback, via the feedback mechanism found in the global footer.

## General guidelines

### Do

- Always provide comfortable mode as default. Compact mode reduced spacing can hinder readability of content for users with vision impairment, and interactivity with close targets for users with physical disability.
- Store users preferences when they select the preferred density mode, and display the corresponding selection in the density settings.
- Apply the mode selection at submission via the confirm button.
- In case you already have a settings area in your service, implement the density settings  within that space.

### Don't

- Don't use the density settings pattern for generic service-level settings.

## Writing guidelines

### General writing guidelines

- Use sentence case, but continue to capitalize proper nouns and brand names correctly in context.
- Use end punctuation, except in [headers](/components/header/index.html.md)   and [buttons](/components/button/index.html.md)   . Don't use exclamation points.
- Use present-tense verbs and active voice.
- Don't use *please*   , *thank you*   , ellipsis ( *...*   ), ampersand ( *&*   ), *e.g.*   , *i.e.*   , or *etc.*   in writing.
- Avoid directional language.  

  - For example: use *previous*     not *above*     , use *following*     not *below*    .
- Use device-independent language.  

  - For example: use *choose*     or *select*     not *click*    .

### Component-specific guidelines

#### Modal

- For the header, use this text: *Density settings*
- For the primary action button, use this text: *Confirm*

#### Label

- **Form field label:**  

  - For the tiles group label, use this text: *Content density*
- **Tiles label: **  

  - The tile label describes the density level applicable. For the labels, use this text: *comfortable and compact*

#### Description

- **Form field description: **  

  - For the tiles group description, use this text: *Choose the preferred level of content density for this \[service\].*
  - In case of partial implementation, include additional details.    

    - For example: *The compact experience is available for some features in this service.*

- **Tiles description: **  

  - The tile description provides additional information about the option.
  - For comfortable mode, use this text: *Default spacing that optimizes information consumption.*
  - For compact mode, use this text: *Reduced spacing that provides more visibility over content. *

## Accessibility guidelines

### General accessibility guidelines

- Follow the guidelines on alternative text and Accessible Rich Internet Applications (ARIA) regions for each component.
- Make sure to define ARIA labels aligned with the language context of your application.
- Don't add unnecessary markup for roles and landmarks. Follow the guidelines for each component.
- Provide keyboard functionality to all available content in a logical and predictable order. The flow of information should make sense.

### Component-specific guidelines

#### Modal

- Follow the accessibility guidelines for [modal](/components/modal/index.html.md)  .

#### Tiles

- Follow the accessibility guidelines for [tiles](/components/tiles/index.html.md)  .

## Related patterns and components

### Content density

Content density is defined by the ratio of information visible compared to the space available in the interface.

[View Documentation](/foundation/visual-foundation/content-density/index.html.md)

### Tiles

Tiles enable users to choose one of a predefined set of options, including additional metadata to facilitate comparisons or progressive disclosure.

[View Documentation](/components/tiles/index.html.md)

### Modal

A user interface element subordinate to an application's main window. It prevents interaction with the main page content, but keeps it visible with the modal as a child window in front of it.

[View Documentation](/components/modal/index.html.md)

### Flashbar

Flashbar - Displays one or more status notifications that communicate critical task operation status - errors, success, in-progress, and info. The info flashbar also announces entire service launch in beta or preview.---

[View Documentation](/components/flashbar/index.html.md)

## Search Cloudscape