Feature Flags
Feature flags (also called feature toggles) are a software development technique that allows you to enable or disable features in your application without deploying new code.
What are Feature Flags?
A feature flag is a boolean or multi-variant switch that controls the visibility and behavior of features in your application. With Toggly, you can:
- Turn features on or off instantly from the dashboard
- Roll out features gradually to a percentage of users
- Target features to specific user segments
- Run experiments to test feature impact
- Use feature flags as kill switches in emergencies
Types of Feature Flags
Boolean Flags
Simple on/off switches. When enabled, the feature is active; when disabled, it's hidden.
if (await toggly.isFeatureEnabled('new-dashboard')) {
// Show new dashboard
} else {
// Show legacy dashboard
}
Multi-Variant Flags
Feature flags that return different values (variants) instead of just true/false. Useful for A/B testing and gradual rollouts.
const variant = await toggly.getFeatureVariant('checkout-button-color');
// Returns: 'red', 'blue', or 'green'
<Button color={variant}>Checkout</Button>
Creating Feature Flags
- Navigate to Features in the Toggly dashboard
- Click Create Feature Flag
- Enter a feature key (e.g.,
new-checkout-flow) - Add a description
- Choose the flag type (Boolean or Multi-Variant)
- Set the initial state
- Click Create
Use a consistent naming convention like kebab-case (new-checkout-flow), PascalCase (NewCheckoutFlow), or camelCase (newCheckoutFlow). All are valid, but consistency across your organization is key.
Feature Flag States
Enabled
The feature is active and visible to users who match the targeting rules.
Disabled
The feature is inactive and hidden from all users, regardless of targeting rules.
Archived
The feature flag is no longer used but kept for historical reference. Archived flags don't appear in SDK evaluations.
Targeting Rules
Feature flags can be targeted to specific users or segments using rules:
- All Users: Feature enabled for everyone
- Percentage Rollout: Enable for X% of users
- User Segments: Enable for specific user groups
- Custom Rules: Complex conditions based on user attributes
Learn more about Targeting Rules.
Best Practices
1. Use Descriptive Names
Choose feature keys that clearly describe what the feature does:
// Good
'new-payment-gateway'
'enhanced-search-results'
// Bad
'feature-1'
'new-thing'
2. Add Documentation
Always include a description when creating feature flags. This helps team members understand the purpose and context.
3. Clean Up Old Flags
Once you've removed a feature from your codebase, you should remove it from Toggly. Don't remove flags immediately after deploying code—the flags should stay in until the feature is completely sunset and removed from your codebase.
Why keep feature blocks in your code? Having feature flag checks in your code makes it easy to find all the parts of a feature when it's time to remove it. Simply search for the flag key across your codebase.
Toggly helps you identify which flags can be safely removed with automatic tracking:
- First Used: Toggly detects and logs when a feature is checked by your code for the first time
- Stale Detection: If a feature hasn't been checked for a configurable period, Toggly marks it as stale, making it easy to identify flags that are no longer in your code and can be removed
4. Use Environments
Test feature flags in Development and Staging before enabling in Production.
5. Monitor Usage
Track feature flag evaluations, views, and usage to understand adoption and identify issues early. See Feature Usage Tracking for details on measuring the full user journey.
Next Steps
- Learn about Environments
- Explore Targeting Rules
- Read about Experiments