On this page
Quick steps
Create a Boolean variable
Open the Variables tab in the left navigation, click + Create variable, choose Boolean and name it, for example menuOpen. Set the default value to false.
Bind it to the layer's visibility
Select the layer to show or hide. In the Appearance section of the right sidebar, right-click the eye icon and pick the boolean variable.
Select the trigger layer
Switch to the Prototype tab and select the button or icon that should do the toggling.
Add a Set variable action
Add an interaction with the On click trigger and the Set variable action. Pick menuOpen as the variable to change.
Enter the toggle expression
In the 'to' field, type the expression ! menuOpen (or not menuOpen) and press Enter or Return. Each click now sets the variable to the opposite of its current value.
Preview the prototype
Press Shift+Space to preview, or present the prototype, and click the trigger a few times to check the layer appears and disappears.
How does a boolean variable control visibility?
Figma's help center defines it directly: "If the value of the boolean variable is true then the layer will be visible. If the value of the boolean variable is false then the layer will be hidden." You bind it by right-clicking the visibility (eye) icon in the Appearance section. The normal variable picker on fills and text won't list boolean variables, which is the first thing that trips people up.
Because the value lives in a variable, several layers can share it. Bind a dropdown panel and a dimmed backdrop to the same menuOpen variable and one click shows or hides both. If you haven't created a variable before, start with how to create variables in Figma.
How to set a variable in a Figma prototype
The Set variable action changes a variable's value when the trigger fires. For a boolean you can enter true or false, pick another boolean variable, or write an expression. To toggle, the expression negates the current value. Figma's expressions support ! or not for negation, so ! menuOpen and not menuOpen both work. You can type the expression in the field or build it from the selection panel of suggested variables and operators.
A forum thread on exactly this question ("on click toggle boolean variable to show/hide elements") has over 33,000 views, so if you got stuck here, you're in good company.
Example: an accordion with one variable per row
Create a boolean for each row, such as faq1Open and faq2Open, all set to false. Bind each answer layer's visibility to its row's variable. On each question, add On click → Set variable → ! faq1Open (and so on). Put the rows in a vertical auto layout frame, so when an answer is hidden the rows below move up and close the gap. The same pattern covers a password field's show/hide icon or a settings toggle.
Conditional prototypes: if/else with booleans
When one click should do different things depending on state, use a Conditional action instead of a plain toggle. Set the condition to the boolean, for example menuOpen == true, then add the actions to run when it's true and a different set under else. Expressions also support and, or, == and !=, so you can check two variables at once, such as whether a user is logged in and a form is complete.
- Use Set variable alone for simple toggles: menus, accordions, checkboxes, a password eye icon.
- Use Conditional when the click should branch: navigate to one screen if a checkbox is ticked, show an error overlay if not.
- Use Set variable mode when you want to switch a whole theme, like light to dark. See variable modes and dark mode.
Figma boolean variable not working: common causes
- The variable is bound to the wrong thing. A boolean variable only controls visibility through the eye icon. Right-click the eye icon in the Appearance section and confirm the variable is selected there.
- The action sets a fixed value. If the Set variable action says
true, the first click shows the layer and later clicks do nothing. Replace it with! menuOpenso it flips each time. - You're on a free plan. Using variables in prototypes, including Set variable, conditionals and expressions, is available on paid plans only.
- The default value hides the trigger. If the button itself is bound to the variable, setting it to false hides the button too. Bind only the content that should appear and disappear.
Frequently asked questions
How do I toggle a boolean variable in Figma?
Add an On click interaction with the Set variable action, pick the boolean variable, and set it to the expression ! yourVariable (or not yourVariable). Each click sets it to the opposite of its current value.
Why can't I apply a boolean variable to my layer?
Boolean variables only bind to layer visibility. Right-click the eye icon in the Appearance section of the right sidebar instead of using the fill or text variable picker.
Do variables in prototypes work on the free plan?
No. Figma lists prototyping with variables as available on any paid plan. You can still create boolean variables and bind them to visibility on Starter, but the prototype actions need a paid plan.
What is a conditional prototype in Figma?
It's a Conditional action that checks an expression, such as menuOpen == true, and runs one set of actions if it's true and another under else. It lets a single click branch based on the state stored in variables.
More in Variables & styles
- How to Export Figma Variables to JSON (and CSS, Tailwind or CSV)Export Figma variables to JSON natively, convert them to CSS or Tailwind with Style Dictionary, and move variables between files with Variable Master.
- Figma Variables Not Showing? Here's Why and How to Fix ItFigma variables now open from the Variables tab in the left nav. If one won't appear in a picker, check its type, scoping and library. Mode switch fixes too.
- How to Change Variable Modes in Figma and Build Dark ModeSet up Light and Dark modes in one Figma color collection, switch a frame or page with Apply variable mode, and fix modes that won't change in prototypes.
- How to Create Text Styles and Color Styles in FigmaCreate text and color styles in Figma, organise them into folders, edit or delete them, fix styles not showing in other files, and know when to use variables.
- How to Create Variables in FigmaCreate Figma variables from the Variables tab, pick the right type, group and duplicate them, delete the ones you don't need and clear leftover used variables.
- How to make a GIF in FigmaMake a GIF in Figma from frames with a plugin, export a Figma Motion animation as GIF, or record a prototype. Steps, loop and timing settings, and trade-offs.
- How to Make a Skeleton Loader in FigmaHow to design a skeleton loader in Figma: grey blocks with auto layout, a component with variants, a Smart Animate shimmer, and a plugin that converts frames.
- How to Make Flow Arrows in FigmaFigma Design has no connector tool, but you can still draw flow arrows that stick to frames. The native options, the FigJam copy trick, and plugins, explained.
- Why Is "Fixed" Greyed Out in My Figma Prototype?Fixed (stay in place) is disabled when the layer sits in an auto layout frame. Turn on Ignore auto layout or remove auto layout, then set the layer to Fixed.
