How do I add custom CSS at the end of the <head> ? #13533
Replies: 9 comments 7 replies
-
I've tried adding custom CSS in _document.js as well but the same results (custom CSS coming before other styles which are imported in _app.js).
|
Beta Was this translation helpful? Give feedback.
-
Still stuck with this issue. Any help would be much appreciated. |
Beta Was this translation helpful? Give feedback.
-
Just bumping this thread so someone can point me in the right direction. |
Beta Was this translation helpful? Give feedback.
-
As far as I know there is not way to specify the order an element gets added to const SiteHead = (props) => {
React.useEffect(() => {
const style = document.createElement('style');
style.innerText = 'body { color: green; }'
const head = document.getElementsByTagName('head')[0];
head.appendChild(style);
}, [])
return ( ... |
Beta Was this translation helpful? Give feedback.
-
You can try adding this to
|
Beta Was this translation helpful? Give feedback.
-
If anyone arrives here from Google: use <style jsx global>{`
body {
background: #000;
}
`}</style> |
Beta Was this translation helpful? Give feedback.
-
@srikanth912 i think the solution in the following example would solve your case: https://github.com/ben-rogerson/twin.examples/blob/b52ac511ebf221471a01fea1c77d90b19a6eb5dc/next-stitches-typescript/pages/_document.tsx |
Beta Was this translation helpful? Give feedback.
-
In case people are looking for an Next JS 13 App Directory solution, I ended up having to use a Script tag and wrote an inline script to add link tag that applied my CSS on hydration |
Beta Was this translation helpful? Give feedback.
-
I'm quite late to the party and this might already have been solved, but try using CSS cascade layers and add customCSS to a layer that is defined as last in the specificity order. https://developer.mozilla.org/en-US/docs/Web/CSS/@layer. Let me know if it works. |
Beta Was this translation helpful? Give feedback.
-
Hello All,
We are building a multitenant application and would like to allow customers to overwrite the default theme CSS. For this we allow customers to add their own CSS which is retrieved via API as a variable (let's say
customCSS
).We would like to insert this at the end of the
<head>
tag like<style>{customCss}</>
after next.js generated styles (which is the default theme CSS).Tried below but it's not coming at the end (Stripped irrelevant meta tags).
Beta Was this translation helpful? Give feedback.
All reactions