Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change Next.js background color with TailwindCSS

I recently started with Next.js and TailwindCSS and I wanted to change the background of my page. It is probably a really simple thing to do but I can’t figure it out how to do. You can’t add classes to the body tag in Next.js right? I tried to wrap the Component in the _app.tsx with a div but that is also wrapped inside a different div, so the background color isn’t the full height.

How should I set the background color for my application and is it also possible to overrule it for a single page?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Add it using your stylesheet (styles/globals.css in case of the official example):

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  body {
    @apply bg-slate-900;
  }
}

If you want to do it on per-page basis, refer this: vercel/next.js#12325 (comment)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading