How to put lable on top of the switch in dmc Switch

Is there a way to get the label on top in Dash Mantine Components Switch?

hi @Brent
I think you would have to use CSS for that. I don’t see any prop in DMC that controls the position of the label.

That is what I thought too. People on this list surprise me a lot of the time though.

I would actually just use a html.Div() or dmc.Paper() component to fake the label. The Label is a div, so you would have to move around the div via css. The commented out className got assigned to the mentioned div, but I think the first class changes.

app.layout = dmc.Stack(
        dmc.Paper(dmc.Text('Fake label')),
            label="Enable this option",
# className='mantine-1qfqb46 mantine-Switch-labelWrapper'

Or, you could use the styles API:


Should be like this:
styles = {'body': {"flexDirection": "column-reverse"}}

1 Like

Thank you. That works. I also added onLabel and offLabel. So now I have a label on the top of the switch and a label inside the switch that corresponds to on or off. It makes a very nice switch.

1 Like