- Instant help with your JavaScript coding problems

Add CSS class to body with JavaScript

Question:
How to add CSS class to body with JavaScript?
Answer:
document.body.classList.add('body-style');
Description:

To add a CSS class to the HTML body element you can use the document.body to get the body tag. Then use the add method on the classList property and you are done.

document.body.classList.add('body-style');
Share "How to add CSS class to body with JavaScript?"