I have a NextJs v12.3.0 app that use sx in MUI as styling to many of my components. many of my pages are render as SSR.
now i want to know somethings.
- Does MUI render sx styles as inline css?
- If yes, has it a bad impact on SEO?
- What can I do to avoid this bad impact?
- do other libraries like styled-components or css modules solve this problem?
please help me to find the answer of my questions and solve my confusion about this in the major of performance of my website and also the SEO majorities of it.
i’ve just test many aspects of styling and see all of them are rendering my styles as inline in tags
2
Answers
For First Question , Not realy!
with sx props , you can work with The theme , it’s look like MUI System with sx props ,change the theme for that specific component
2- For second Question , MUI Using Utility Classes behind the scenes , you can track them with dev tools , MUI manage almost every thing with Utility Classes , But you must consider that , MUI using React and The React it self is not that SEO friendly!
For Better SEO Compatibility , I recommend to use some framework like Tailwind because this framework it can be only dev-dependency , and the final result is only CSS , of course for more animation you need some other frameworks like motion , but however in animation MUI is not that good
But if for something like first initializing the page , use SSR , SEO of your website will be fine
No, MUI’s
sx
prop does render styles as inline CSS. It renders a random unique class name, which will change if you add or remove some property in thesx
object. Actually, it is better than writing inline-css, because class names are better for SEO and performance. Check the image below where I write styling in a different way, and check its output:No, it won’t affect SEO as long as you use MUI
AppCacheProvider
with NextJs. Check this documentation to implementAppCacheProvider
.There is no bad impact if you config your NexJs app as per the MUI’s NextJs documentation.
These libraries also generate class-based styles or scoped CSS and are excellent for SEO and performance. I think If you’re already using MUI and the
sx
prop, switching libraries isn’t necessary.💡I hope it helps!