In which situation would it be better to use one or the other?
For example:
Vs:
User Experience Stack Exchange is a question and answer site for user experience researchers and experts. It only takes a minute to sign up.
Sign up to join this communityYes they are, also from an accessibility perspective.
If you need a larger target size, go with toggle buttons. It's also easier to arrange them in a horizontal space.
Checkboxes are more suitable for a vertical space and are a standard in forms.
It depends, but from my experience I would lean towards no. A toggle usually means on or off, not option 1 or option 2. If you label the toggle properly then it could work.
If the list of options is short and consistent (not going to change based on another variable), they can be a nice choice aesthetically.
Some real estate search sites use this approach for defining what type of property you want. When successfully done, it is usually treated a bit differently than a list of toggles.
Wording is key. For example, assuming at least one selection is required, instead of:
Select the applicable categories
use
Select one or more applicable categories
The original text has only the plural "categories" to indicate that "more than one is allowed", which is (a) easy to miss and (b) there are so many systems which get this wrong (e.g., "category" when more than one is allowed or "categories" but actually only one is allowed at a time) that text which makes it 100% clear is a big improvement.