Skip to content

Toggles for Power Apps

A toggle is a switch with two states, on and off, that changes the moment it is tapped, with no Save button. The PowerLibs toggles are not the built-in Toggle control: each one is an image whose picture is an SVG written as a formula, with a transparent button on top. That is why the knob slides smoothly and the colors are yours. The state lives in a variable, not in a Value property. Toggle is free; the other variants need a paid plan.

Pick a variant

  • ToggleFreeClassic, Modern

    The standard switch with a label, brand color when on

    Settings: Label beside the switch (on or off), Text, Starts on, Size, Color when on

  • Toggle On/OffPaidClassic, Modern

    ON and OFF written inside the track, for states that must read without color

    Settings: The same as Toggle

  • Toggle SquarePaidClassic, Modern

    Squared track and knob for squarer apps

    Settings: The same as Toggle

  • Toggle LockPaidClassic, Modern

    A padlock in the knob that closes when on: locked records, read-only modes

    Settings: The same as Toggle

  • Toggle Check/XPaidClassic, Modern

    Green with a check when on, red with an X when off: inspections, checklists

    Settings: The same as Toggle, plus Color when off

  • Toggle OutlinePaidClassic, Modern

    A hollow track with a filled knob, lighter in dense forms

    Settings: The same as Toggle

  • Settings Row TogglePaidClassic, Modern

    Title, explanation and the switch on the right; the whole row taps

    Settings: Explanation under the title (on or off), Title, Explanation, Starts on, Size, Color when on

  • Toggle ListPaidClassic, Modern

    A card with several switch rows, backed by a collection of ids

    Settings: Reset to defaults button (on or off), Heading, Rows (up to 8): Title, Explanation, On, Size, Color when on

  • Favorite TogglePaidClassic, Modern

    A heart, star or bookmark that fills with a pop, optional count

    Settings: Count beside the icon (on or off), Shape (Heart, Star, Bookmark), Color when on, Count, Tooltip

Paid means any paid plan (which plan do I need?). Classic and Modern are the two Power Apps control sets you can pick from the Copy YAML button. Open the category in the library: Toggles.

To copy a variant into Power Apps Studio, follow Getting Started.

After you paste

Each toggle keeps its state in its own context variable, named after the toggle: varToggle, varToggleOnOff, varToggleSquare, varToggleOutline, varToggleLock, varToggleCheckX, varSettingRow, varFavorite. The Toggle List keeps only the rows someone switched, as { id, on }, in the collection colToggleListState; a row without an entry shows its On setting from Settings (the defaultOn column of the gallery's Items). Names use your prefix settings. A second stamp variable, for example varToggleRun, makes the picture reload so the slide plays on every tap; you never touch it. The Toggle List also stores the tapped row in varToggleListTapped, so only that row slides.

Read the state anywhere on the screen:

// Visible of a section
varToggle

// A row of the Toggle List
Coalesce(LookUp(colToggleListState, id = 2).on, true)  // true = that row's default

Start on: switch Starts on in Settings, and the formulas read Coalesce(varToggle, true), so the switch shows on before the first tap. The variable itself is still blank until that tap, so read it as Coalesce(varToggle, true) in your own formulas too. Toggle Check/X and Settings Row Toggle start on unless you switch that off. To bind to a record, set the variable in the screen's OnVisible:

UpdateContext({ varToggle: LookUp(Preferences, User = User().Email).DarkMode })

Save each change in the OnSelect of the tap button, such as btnToggle, after the line that flips the variable:

Patch(Preferences, LookUp(Preferences, User = User().Email), { DarkMode: varToggle })

The Toggle List shows the rows marked On in Settings as on right after pasting: its collection starts empty, and an empty collection means every row shows its default. The Reset to defaults button, btnToggleListSeed, runs Clear(colToggleListState); delete it if you do not need it. To load saved choices, fill the collection in the screen's OnVisible:

ClearCollect(colToggleListState, ForAll(Filter(UserPrefs, User = User().Email), { id: SettingId, on: On }))

Good to know

  • Two copies of the same toggle on one screen share both variables. Paste the second, then rename the state and the stamp variable (varToggle and varToggleRun) in its two formulas, the Image and the button's OnSelect. If the stamp stays shared, a tap on one copy replays the slide on the other.
  • A context variable belongs to its screen. For a value other screens read, change UpdateContext to Set and give it a global name.
  • Sizes are Small (36 by 20), Medium (44 by 24) and Large (56 by 30). Toggle On/Off needs Medium or Large for the words to fit.
  • The on color is your brand color until you pick one; Check/X defaults to green and red on purpose, and the Favorite Toggle to a red heart, an amber star or a brand-colored bookmark. The off track is grey on the light theme and navy grey on the dark one.
  • Inside a gallery use the Toggle List pattern: one collection keyed by id and Coalesce(LookUp(colToggleListState, id = ThisItem.id).on, ThisItem.defaultOn), not one variable per row. The Favorite Toggle's instructions show the same for hearts in a gallery.
  • The Toggle List rows are a Table in the Items of galToggleListRows. Replace it with your own list and keep the columns id, title, subtitle and defaultOn.
  • The number in lblFavoriteCount is the Count from Settings, plus 1 while the toggle is on. Replace the fixed number in its Text with your own count.
  • Every toggle offers Classic and Modern YAML with the same layout and the same control and variable names, so the formulas here work for both.

Open the family in the library at Toggles. Related guides: Input Fields and Buttons.

Toggles for Power Apps | PowerLibs