> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Switch – Design

> Switches toggle between two states, providing immediate user feedback.

export const CodePreviewPlaceholder = ({double, fullWidth}) => {
  const single = <div style={{
    width: fullWidth ? "100%" : "50%",
    borderRadius: "1rem",
    display: "flex",
    padding: "1rem",
    flexDirection: "column",
    gap: "0.5rem",
    height: "10rem",
    marginBlockEnd: "1rem"
  }} className="border-width-default border-color-subdued">
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
      <div className="bg-strong border-radius-large" style={{
    width: "100%",
    flexGrow: "1"
  }} />
    </div>;
  return double ? <div style={{
    display: "flex",
    gap: "1rem"
  }}>
      {single}
      {single}
    </div> : single;
};

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img noZoom src="https://mintcdn.com/servicetitan/H5FwKyiqhPVZ1UJQ/images/docs/web/components/shared/switch-selection-option.png?fit=max&auto=format&n=H5FwKyiqhPVZ1UJQ&q=85&s=0ca859fec9f24db60657648abc6de3f0" width="466" height="129" data-path="images/docs/web/components/shared/switch-selection-option.png" />
  </div>
</Frame>

## Anatomy

The Switch consists of three primary elements that work together to toggle between two states.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-anatomy.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=678cbde4d8822ad6f2c9f6cd48e3e312"
      alt="Switch
anatomy"
      width="866"
      height="129"
      data-path="images/docs/web/components/switch/design/switch-anatomy.png"
    />
  </div>
</Frame>

1. Unselected
2. Selected
3. Label

## Options

The Switch supports label and selection configurations to accommodate various toggle scenarios.

### Label

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-options-label.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=312e09d2b83084e36cd8683e10f49ec1"
      alt="Switch options
label"
      width="446"
      height="145"
      data-path="images/docs/web/components/switch/design/switch-options-label.png"
    />
  </div>
</Frame>

Generally, Switches should have labels that clearly describe the intent of the Switch. A Switch can also have no label when the context of what it turns on or off can be clearly understood.

### Selection

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/H5FwKyiqhPVZ1UJQ/images/docs/web/components/shared/switch-selection-option.png?fit=max&auto=format&n=H5FwKyiqhPVZ1UJQ&q=85&s=0ca859fec9f24db60657648abc6de3f0"
      alt="Switch selection
option"
      width="466"
      height="129"
      data-path="images/docs/web/components/shared/switch-selection-option.png"
    />
  </div>
</Frame>

Switches can be selected or unselected. If a Switch is used to represent multiple mixed values, it should be set to unselected.

## Behavior

The Switch responds to user interaction with distinct visual states for different selection states.

### Visual States

#### Default

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-state-default.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=6c0f1474d171f03547bb210b58204fa2"
      alt="Switch state
default"
      width="466"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-state-default.png"
    />
  </div>
</Frame>

#### Selected

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-state-selected.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=ee30714e682ec2cdd6a399993db38b8f"
      alt="Switch state
selected"
      width="466"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-state-selected.png"
    />
  </div>
</Frame>

#### Disabled

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-state-disabled.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=0eb000607351b00c7b72887d1ac34d91"
      alt="Switch state
disabled"
      width="466"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-state-disabled.png"
    />
  </div>
</Frame>

## Usage Guidelines

Use the Switch when allowing users to choose between two mutually exclusive options with immediate results.

### Alternatives

#### Switch vs Checkbox

Switches are used for making a selection between two mutually exclusive options and have an immediate effect. Checkboxes allow users to make zero to many choices from available options and changes are not immediate.

#### Switch vs Radio

Where the Switch is used to toggle between two options, Radio buttons can be used to choose from two or more options. Additionally, a Switch is primarily used for enabling or disabling features or settings and has an immediate effect. Radio buttons are common in form layouts when selecting between multiple options.

#### Switch vs Checkbox vs Radio

Radio buttons are used to select a single option from a set of mutually exclusive options. Checkboxes are best used to make zero to many selections from available options.

|                                                                              | Checkbox                            | Switch                    | Radio                               |
| ---------------------------------------------------------------------------- | ----------------------------------- | ------------------------- | ----------------------------------- |
| When is the selection executed?                                              | After a user clicks a submit button | Immediately               | After a user clicks a submit button |
| How many options are available?                                              | 1 or more                           | 1                         | 2 or more                           |
| Must an option be reducible to an on or off context?                         | No, it can be other things.         | Yes                       | No, it can be other things.         |
| If I had a group of this UI, what is the relation of each item in the group? | Independent of each other           | Independent of each other | Mutually exclusive                  |
| Indeterminate state possible?                                                | Yes                                 | No                        | No                                  |

### How to Use

#### Labels

Switch labels should describe the effect when the Switch is "on," e.g., "Enable notifications". The text label for a Switch should never change based on the state of the Switch. For example, you would not change a label from "Enabled" to "Disabled" or vice versa.

Additionally, a Switch can also have no label when the context of what it turns on or off can be clearly understood. A tooltip can also be applied to describe the toggle's current state.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-labels-do.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=ee692e5724d93aff182aa7cf03e6538c"
      alt="Switch labels
do"
      width="466"
      height="129"
      data-path="images/docs/web/components/switch/design/switch-labels-do.png"
    />
  </div>
</Frame>

<Check>**Do**</Check>

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/H5FwKyiqhPVZ1UJQ/images/docs/web/components/switch/shared/switch-labels-dont.png?fit=max&auto=format&n=H5FwKyiqhPVZ1UJQ&q=85&s=4479d82a3de1d95cc74d104e77ac8a68"
      alt="Switch labels
don't"
      width="494"
      height="129"
      data-path="images/docs/web/components/switch/shared/switch-labels-dont.png"
    />
  </div>
</Frame>

<Danger>**Don't**</Danger>

#### Immediate Effect

Switches should have an immediate effect when its state changes and not require a save action.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-immediate-effect-do.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=7ef469e4c779ee31f7c36297bf830891"
      alt="Switch immediate effect
do"
      width="1136"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-immediate-effect-do.png"
    />
  </div>
</Frame>

<Check>**Do**</Check>

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-immediate-effect-dont.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=1e513e70aa90d0677781bb68d4334753"
      alt="Switch immediate effect
don't"
      width="1136"
      height="181"
      data-path="images/docs/web/components/switch/design/switch-immediate-effect-dont.png"
    />
  </div>
</Frame>

<Danger>**Don't**</Danger>

#### Form usage

Assuming that your Switch still matches the pattern of an off/on, it can be used in a Form to disclose additional options.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-form-usage.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=b5a05a1af9e713b2f4bf0cfc5891d594"
      alt="Switch form
usage"
      width="1104"
      height="498"
      data-path="images/docs/web/components/switch/design/switch-form-usage.png"
    />
  </div>
</Frame>

## Content

Content within the Switch should clearly communicate the effect when the Switch is turned on.

### Give a descriptive, direct label

The toggle switch label should describe what the control does when it is turned on. Rule of thumb: say the label name and add an "on/off".

Use sentence case (capitalize only the first word and proper nouns) so control labels are easy to scan. Do not use periods for short phrases or single sentences.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-label-do.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=15756bd47296906283ad1cef93209018"
      alt="Switch label
do"
      width="378"
      height="241"
      data-path="images/docs/web/components/switch/design/switch-label-do.png"
    />
  </div>
</Frame>

<Check>**Do**</Check>

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-label-dont.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=7758298e3e1de8a62748d814d85f148d"
      alt="Switch label
don't"
      width="230"
      height="241"
      data-path="images/docs/web/components/switch/design/switch-label-dont.png"
    />
  </div>
</Frame>

<Danger>**Don't**</Danger>

### Positive label wording

Labels in general should be positive. Since the label and Switch are generally thought of as turning something on, labels should reinforce this.

Examples include: "Show", "Hide", "Activate", "Group \[by]", "Track", and "Activate". Negative labeling can be used with caution, if it makes sense to a user to perform a negative action.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-positive-label-do.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=1e2cab0274f89f2a19860ef1707aca6f"
      alt="Switch positive label
do"
      width="1136"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-positive-label-do.png"
    />
  </div>
</Frame>

<Check>**Do**</Check>

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-positive-label-dont.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=f25764778176aceef659d53a65f8adda"
      alt="Switch positive label
don't"
      width="1136"
      height="49"
      data-path="images/docs/web/components/switch/design/switch-positive-label-dont.png"
    />
  </div>
</Frame>

<Danger>**Don't**</Danger>

### Give the user the information they need to make an informed decision

When a toggle switch label does not provide sufficient information and context for users to make an informed decision about the option, use inline help.

Inline help is the best option for this situation because it requires no user interaction and is always visible. Keep inline help to 1-2 sentences. Use the content guidelines for inline help.

Avoid using a tooltip to communicate this kind of information about an option. It's an additional step for users to mouse over the tooltip to reveal its information, and users can't refer to the tooltip content and take action at the same time.

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/usDdQzJfkl6jYYLR/images/docs/web/components/switch/design/switch-informed-decision.png?fit=max&auto=format&n=usDdQzJfkl6jYYLR&q=85&s=c33e038018b5db3b8a8fd89a7ec3963a"
      alt="Switch informed
decision"
      width="1136"
      height="105"
      data-path="images/docs/web/components/switch/design/switch-informed-decision.png"
    />
  </div>
</Frame>

## Keyboard Interaction

Users can navigate the Switch using standard keyboard controls.

| Key   | Description                             |
| ----- | --------------------------------------- |
| Space | Enables or disables the selected Switch |

### Accessibility

The label should clearly describe the Switch intent

#### Switch Labels

<Frame>
  <div className="w-full h-full bg-[#FFFFFF] p-2 rounded flex items-center justify-center">
    <img
      src="https://mintcdn.com/servicetitan/H5FwKyiqhPVZ1UJQ/images/docs/web/components/switch/shared/switch-labels-dont.png?fit=max&auto=format&n=H5FwKyiqhPVZ1UJQ&q=85&s=4479d82a3de1d95cc74d104e77ac8a68"
      alt="Switch labels
don't"
      width="494"
      height="129"
      data-path="images/docs/web/components/switch/shared/switch-labels-dont.png"
    />
  </div>
</Frame>

<Danger>**Don't**</Danger>

The label for a Switch should not change as the state of the Switch changes. [Refer to W3C's Switch pattern for more details](https://www.w3.org/WAI/ARIA/apg/patterns/switch/).

For more guidance on form field labels and context, see [input field context association best practices](/docs/accessibility/labels-and-ctas#input-field-context-association).
