Element “style” not allowed as child of element “div” in this context.
See original GitHub issueDescription
When I use the W3C validator I expect to get no errors but there are many errors with misplaced “style” elements
Link to Reproduction
https://validator.w3.org/nu/?doc=https%3A%2F%2Fchakra-ui.com%2F
Steps to reproduce
- Go to https://validator.w3.org/nu/?doc=https%3A%2F%2Fchakra-ui.com%2F
- Click check the
Element “style” not allowed as child of element “div” in this context.
Chakra UI Version
Latest
Browser
Not applicable
Operating System
- macOS
- Windows
- Linux
Additional Information
As per https://github.com/validator/validator/issues/489, using <style>
tags outside <head>
is not following the HTML5 specifications.
There is a risk that by not following the HTML5 specifications, SEO can be impacted (see https://www.elegantthemes.com/blog/wordpress/how-to-use-w3c-validator-to-improve-seo)
As per Emotion’s documentation, it looks like it is possible to move the <style>
tag inside the <head>
: https://emotion.sh/docs/ssr#nextjs
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:33 (24 by maintainers)
Top Results From Across the Web
Element style not allowed as child of element body in this ...
Alternatively, you can just wrap the style element in a div element: ... The scoped attribute is not valid at all according to...
Read more >Element style not allowed as child of element div in this context.
Error : Element style not allowed as child of element div in this context. (Suppressing further errors from this subtree.) From line 179,...
Read more >Element “style” not allowed as child of element “div” in this ...
Go to https://validator.w3.org/nu/?doc=https%3A%2F%2Fchakra-ui.com%2F; Click check the Element “style” not allowed as child of element “div” ...
Read more >Element <style> not allowed as child of element <div> in this ...
I noticed after check my page code this [style] tag between [div] ... Element <style> not allowed as child of element <div> in...
Read more >W3C Validation error - "Element “style” not allowed as child of ...
Various WordPress plugins are adding style in the body. ... error - "Element “style” not allowed as child of element “div” in this...
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 FreeTop 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
Top GitHub Comments
Let me try to explain what’s happening here:
With our current setup and approach, during SSR, emotion will render
style
tags inline as a sibling of any Chakra component. After hydration, emotion will move the styles to the head as fast as it can to prevent FOUC (flash of unstyled content)If we implemented the SSR setup recommended by emotion docs, we’ll skip that hydration step and extract all the styles to the head ahead of time. I think we should attempt to do this within our docs @nikolovlazar @TylerAPfledderer. If we notice improvements from this, we’ll update our documentation to reflect this.
When you use markup validators, they’ll run against the SSR output of the website and will see inline
style
as invalid, when in fact, that’s not the full story.@segunadebayo : watching this issue. Is there a timeline on a fix from Chakra-UI?
Thanks!