Using Toggles With Care

A toggle is a switch that can be either ON or OFF. It is often found in hardware such as keyboard’s Caps Lock and Num Lock buttons. But software developers also use them in options menus and other places where they want to enable or disable features. The idea is to allow users to decide which option they want to use at a given time, and then toggle back and forth between them.

Toggles are very useful, but they can cause problems if they are not used with care. Toggles need to be carefully designed and tested, especially with accessibility in mind. A toggle should have clear labels that describe both its default state and its current state, and it should be visually distinct from other controls such as radio buttons or checkboxes. In order to be accessible, a toggle should not rely on color to convey its state (especially for the ON position). People with color vision deficiency find it very difficult to tell if something is ON or OFF by looking at a toggle. Ideally, a toggle will use high-contrast colors or other visual signifiers to indicate its state.

Another issue with toggles is that they can cause confusion if they are not well-named and have unclear meanings. For example, it’s common to use the word “on” in the name of a toggle, but that can lead to confusion if the user has multiple toggles with identical names. Ideally, a toggle will have a name that clearly indicates its intended function, such as “Airplane Mode”.

In addition to the cognitive issues related to toggles there are a few other things to consider when using them. First, toggles can be a bad choice for settings that require the user to make a decision (e.g., Airplane Mode). A better choice would be a select box or drop-down. Second, while using toggles is often recommended to reduce the amount of screen space required, on mobile devices they tend to consume more screen real estate than other widgets such as checkboxes.

Finally, many teams have found that it is important to test toggle configurations that will be live in production. This typically means testing the toggles that will be flipped On, but it’s also wise to test the fallback configuration where those toggles are flipped Off. This helps to avoid releasing a version with a regression.

A final issue with toggles is that they can slow down validation when used in a Continuous Integration environment. When a toggle is flipped it can require a restart of the service to take effect, and then there’s a delay before the test run can start. This can impact the speed of your CI/CD process and can be an annoying bug for your testers to deal with. If possible, try to minimize the number of toggles in your system and look for ways to improve your CI/CD process to avoid these delays. For example, some teams have found that it is useful to put a task on the team’s backlog for removing old toggles. Other teams have even gone as far as to put “expiration dates” on their toggles, ensuring that the old ones are removed before they become a problem.