Styling <body> tag in _document - nextjs not working
See original GitHub issueHello Ben, Styling the custom body tag in nextjs doesn’t seem to work. added this in _document.tsx file
//_document.tsx
import Document, { Html, Head, Main, NextScript } from 'next/document'
import tw from 'twin.macro'
...
render() {
return (
<Html>
<Head />
<body tw="antialiased bg-black">
<Main />
<NextScript />
</body>
</Html>
)
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Next.js custom class on body using _document.js
The work around I suggest is to access the body tag from the component directly. Example: const handleClick = (e) => { document....
Read more >Advanced Features: Custom `Document` - Next.js
A custom Document can update the <html> and <body> tags used to render a Page. This file is only rendered on the server,...
Read more >How to add a class to the body tag in Next.js - smnh
The problem is that the _document.js is only rendered on the server. When the browser loads the first page, it will get the...
Read more >Add custom attributes to the <body> tag #12325 - GitHub
As the question mentioned to "add a custom className to tag dynamically", I don't think the _document is the good place for that....
Read more >How to add JavaScript tags in the body of a Next.js App
js located under the pages directory import Document, { Html, Head, Main, NextScript } from 'next/document'; class OverriddenDocument extends ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’ll need to add the body within the stylesheet collection area instead:Edit: This isn’t a good solution - it will duplicate the body tag 😦
For some reason, I thought you needed to add the styling within _document.js, must have been before my morning coffee.
Yes,
createGlobalStyle
is how I would style the body too.GlobalStyles
doesn’t accept custom styling, perhaps in the future but adding that feature is not as easy as would seem.