Creating flag variations
Read time: 3 minutes
Last edited: Oct 26, 2021
This topic explains how to use a flag's Variations tab to create and edit your feature flag's variations and outlines the different types of flag variations.
LaunchDarkly supports boolean and multivariate flags. On the Variations tab, you can add, edit, or delete variations of existing flags:
- Boolean flags have two variations:
- Multivariate flags can have more than two variations. The allowed variations depend on the type of flag. Multivariate flag types are strings, numbers, and JSON. To learn more, read Understanding multivariate flags.
After a feature flag has been created, you cannot change the type of its variations. For example, you can't edit a feature flag that returns numbers to make it return strings instead. To learn more about creating flags, read Creating a feature flag.
Here is an image of a multivariate flag:
When you add, edit, or delete a feature flag's variations, the change impacts environments within the project.
When you delete a variation, custom rules that return that variation are also deleted. If a custom rule has a percentage rollout, the rollout for that variation is set to zero. If the default rule returns the deleted variation, it will be changed to return the
off variation instead.
Multivariate flags let you use one flag to serve multiple variations of a feature simultaneously. There is no limit to the number of variations you can add to a multivariate flag, making it useful for complex use cases and to manage two or more variations of a feature. For example, a multivariate flag that serves strings as variations can be used to enable different customer checkout types, serving a percentage rollout of those types to users.
Multivariate flag variation types include strings, numbers, or JSON. To learn more, read Understanding flag types.
Here is an image of a flag with a percentage rollout:
You can use custom rules to refine a rollout even more. In this example, the first rule serves two-click checkout to all users whose country is
USA. The second rule targets users whose email ends with
example.com and serves one-click checkout to 10%, two-click checkout to 10%, and the original checkout flow to 80% of those users. All users who are not targeted in the custom rules are served the Default rule.
To learn more about targeting rules, read Targeting rules based on user attributes.
Here is an image of a flag with custom rules:
You can also use multivariate flags to perform A/B/n testing with LaunchDarkly's Experimentation feature. To learn more, read Creating Experiments.
When you create a feature flag, some of its variations are designated as default variations. A flag's default variations are the variations that are served when a flag is on or off unless you specify otherwise.
For example, a boolean flag could have
false set as its default off variation and
true set as its default on variation. A multivariate flag could have
variation 1 set as its default off variation and
variation 2 set as its default on variation, with
variation 3 and
variation 4 configured to appear in other, more specific circumstances, such as when a user is based in a specific region or has a certain email address.
Default variations are designated automatically every time you create a feature flag. You can accept the default variations or change them. When you do this and click Save Flag, the flag is created across all environments in your project with these variations set as its
Here is an image of a flag's default variation options:
You can change a flag's default variations from the Variations tab. Update the default variations in the "Defaults for new environments" section. Subsequent environments you create also use the flag's default values. If you change the default variations and then create a new environment, however, the environment you create will use the updated default variations.
If you modify a flag's default variations, the updated default variations only apply to new environments. You can not change the default variations in environments that already exist.