Search code examples
reactjstailwind-csscreate-react-app

how to style the body tag with tailwind.css in create-react-app


I recently started with Create-react-app and TailwindCSS and I wanted to change the background of the whole page. couldn't find a way to style the tag

I tried adding my own style in the index.css file like this

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

body{
    background-color: aqua;
}

but still didn't work, seems that it's overriden by tailwinds styles is there some way to style the body tag?


Solution

  • In TailwindCSS you can just edit the styles of the body tag by adding it to @layer base and using the @apply keyword to add styles from TailwindCSS. Example:

    @tailwind base;
    @tailwind components;
    @tailwind utilities;
    
    @layer base {
      body {
        @apply bg-black
      }
    }