Switch
ic.Switch is a toggle control that stores its state as "on" or "off". It works well for binary settings where the effect is immediate, like enabling a feature or toggling a mode. You can choose between sharp industrial edges or a rounded pill shape, and optionally show an ON/OFF label next to the track.
Variants
Variant controls the track color when the switch is on. Use primary for standard toggles, secondary when the switch lives in a dense layout and should draw less attention, and destructive when the toggle controls something irreversible or high-risk. All three variants look identical in the off state.
Shape and size
Shape controls the geometry of the track and thumb. The default square shape uses sharp 3px radii that fit the industrial flat design language, while pill gives you fully rounded ends for a softer look. Size scales both the track and the label text proportionally.
Label
Setting ShowLabel to true displays an ON or OFF text label next to the switch track. The label color changes to match the switch state, making it easy to confirm the current value at a glance even for users who have difficulty distinguishing the track colors.
Events
Switch fires a ValueChanged event each time the user toggles it, carrying the new value ("on" or "off") in the payload. In MATLAB, attach a listener with addlistener and read the value from evt.Data.value.
Custom styling
Every component exposes a .css property that lets you inject instance-level CSS directly from MATLAB. Here is a green pill switch with a glow effect when on. The selectors target the track in its on state and the thumb to override the shape and color.
s = ic.Switch("Shape", "pill", "Size", "lg");
s.css.style(".ic-switch__track--primary.ic-switch__track--on", ...
"background_color", "#16a34a", ...
"box_shadow", "inset 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 8px rgba(22, 163, 74, 0.35)");
s.css.style(".ic-switch__thumb", ...
"border_radius", "50%");linear-gradient, backdrop-filter, or newer color functions may not work everywhere. For reference, MATLAB R2024b uses Chromium 104.
Always test your custom styles in the MATLAB version you are targeting, and use canIuse to check compatibility of specific CSS features if you know the browser version MATLAB is using.
Use the Developer Tools component to inspect the DOM structure of each component and find the right selectors for styling.