What is a Toggle?

November 21, 2023 by No Comments

A toggle (or Toggle Switch) is a control that can be set to one of two states – either ON or OFF. Toggles are often used in software to switch between menu items or options within a screen. It’s also common in hardware, such as the caps lock and num lock keys on a keyboard that toggle between their specific functions. In some cases, a toggle can be used as a replacement for a checkbox or radio button.

Toggle switches should always be labeled and clearly state what the action of switching the switch to a particular state will do. Toggles should be able to show immediate results, and the change in state should happen as soon as the toggle is clicked or activated. If you have a long form that requires a submit button for changes to take effect, use a checkbox instead of a toggle.

The use of a toggle should be limited to features that are transitionary in nature. Savvy teams view Feature Toggles as inventory which comes with a carrying cost and they seek to keep that number low by being proactive in removing toggles when they are no longer needed. Some teams even put an explicit task on their backlog for removing toggles when they are first introduced and some go as far as putting “expiration dates” on toggles to ensure that they get flipped off as quickly as possible.

Toggle configuration typically lives side-by-side with the rest of the codebase in some type of centralized repository. This can be as simple as adding an if statement to the source file or it could involve the use of a distributed configuration system such as a Kubernetes Deployment Pipeline or even a CD/CI server.