Your first feature flag
Read time: 4 minutes
Last edited: Mar 24, 2021
Overview
This topic explains how to create feature flags in LaunchDarkly. You can use feature flags in any aspect of your application, from the customer-facing UI to the back end.
In the LaunchDarkly UI, you can create a new flag, clone and modify an existing flag to create new ones, and set default variations for flags.
You can also use the LaunchDarkly API to create and manage feature flags, as well as do many other tasks. LaunchDarkly is an API-first product, so everything you can do in the LaunchDarkly API is also available as an API endpoint. To learn more, read our REST API Documentation.
Creating a feature flag
You can create and modify feature flags from the dashboard.
To learn more about the dashboard, read The dashboard.
To create a feature flag:
- Log into LaunchDarkly. The dashboard appears.
- Click New. The "Create a feature flag" screen appears.
- Enter a unique, human-readable Name.
- Enter a unique flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
- (Optional) Enter a Description of the flag. A brief, human-readable description helps your team members understand what the flag is for.
- (Optional) Click into the Tags dropdown and choose one or more tags for your flag.
Tags are useful for managing flag permissions using custom roles. For example, you can tag a flag as "Marketing" and "DevOps", and then use these tags to determine who has read or write access for the flag. To learn more, read Custom roles.
- (Optional) In the "Client-side SDK flag availability" section, check the SDKs using Mobile Key and/or SDKs using client-side ID boxes to designate which SDKs the flag should be available to. To learn more, read Making flags available to client-side and mobile SDKs.
- Choose an option in the Flag variations dropdown. To learn more, read Flag variations.
- (Optional) Specify details for your Variation. To learn more, read Managing flag variations.
- (Optional) Change the default variations for the flag's on and off states. To learn more about default variations, read Setting default variations.
- (Optional) Select the This is a permanent flag checkbox.
- (Optional) Select the Make this flag available to client-side SDKs checkbox. If you choose this option, the flag will be pushed out to client-side SDKs.
- Click Save Flag.
That's it! You just created a feature flag. You can see it in the dashboard.
Making flags available to client-side and mobile SDKs
When you create a flag, you can choose to expose the flag to SDKs which use client-side ID, SDKs which use mobile keys, or both. By default, flags are only available to server-side SDKs. If you're using a client-side SDK, you must make each flag you wish to appear on the front end available to the client.
Making flags available to client-side SDKs, specifically to SDKs for mobile devices, may have security implications you should consider. SDKs for mobile devices use mobile SDK keys, which are readily available to mobile apps. A leaked mobile SDK key allows a backdoor around JavaScript's SecureMode, which can allow the holder to find out the value of every flag for any user even without knowing the SDK key that is used to hash the user key in Secure Mode.
To learn more, read Client-side and server-side SDKs.
Configuring the same flag in different environments
All environments within a project have the same set of feature flags. When you create a new feature flag, it is created in every environment in your LaunchDarkly project. That flag is scoped to your entire project.
Flag scoping refers to the parts of LaunchDarkly where a flag is available or used. If a flag is scoped at the project level, it is available to all environments within the project, because projects contain environments. To learn more about projects, read Projects.
To learn more about environments, read Environments.
Flag configuration settings are specific to each environment. The changes you make in one environment do not apply to the same flag in any other environment. If you want to, you can configure the same flag in a unique way for every environment you have.
To configure a flag in a different environment:
- Navigate to the dashboard.
- Click the environment name in the top left corner. The Switch environment menu appears.
- Search for the environment you wish to switch to and click on it, or choose it from the list. The dashboard for the new environment appears.
- Find the flag you wish to modify and make whatever changes you like.
Setting default variations
When you create a feature flag, some of its variations are designated as default variations. You can accept the defaults 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 on
and off
values.
To learn more about default flag variations, read Changing default flag variations.
Cloning flags
You can also create new flags by cloning existing flags. Instead of creating an entirely new flag with complicated configuration, you can clone and modify an existing flag with similar configuration.
When you clone a flag, LaunchDarkly makes a new flag and copies the original flag's targeting configuration for all environments, including default variations and whether the flag is toggled on or off.
To clone a flag:
- Navigate to the dashboard.
- Find the flag you wish to clone and click its name. The flag detail page opens.
- Click into the flag's Settings tab. The flag Settings menu opens.
- Click Clone This Flag. The "Clone feature flag" screen appears.
- Enter a unique, human-readable Name.
- Enter a unique flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
- (Optional) Enter a Description of the flag. A brief, human-readable description helps your team members understand what the flag is for.
- (Optional) Click into the Tags dropdown and choose one or more tags for your flag.
Tags are useful for managing flag permissions using custom roles. For example, you can tag a flag as "Marketing" and "DevOps", and then use these tags to determine who has read or write access for the flag. To learn more, read Custom roles.
- Click Save Flag. You are taken to the new flag's details page.
The new flag also appears in the dashboard, where you can search for it or access it any time.