Adding ClassName to body tag

Hello community. How does someone add ClassName property to <body> tag in dash?

Hi @Gaylord what exactly are you refering to?

Hello @Gaylord,

The only way to do this is via a JavaScript function, a clientside callback can handle it.

If you use pages:

“””function (n) {
return window.dash_clientside.no_update

Or… you could mess with the template. Though I wouldn’t recommend this.

I wish Dash would just easily let you add attributes to the body. It’s not an uncommon thing.

I played with this a little bit and I found the most straightforward way is to just replace the '<body>' string in app.index_string. Little hacky but works:

mybody = '<body class="customclass1 customclass2">'
app.index_string = app.index_string.replace('<body>', mybody)


<!DOCTYPE html>
    <body class="customclass1 customclass2">
        <!--[if IE]><script>
        alert("Dash v2.7+ does not support Internet Explorer. Please use a newer browser.");
1 Like