This is the syntax of a standard library of Nextjs, this is called Styled JSX, and the fact that it is used <style jsx>
is not to be confused with the tag itself <style>
of HTML.
What’s special about it is that it encapsulates and maintains the scope of style in its component, without affecting other components, which allows you to change/delete/create style codes without worrying about side effects.
<style jsx>
is the tag that indicates the start of the scope and stylization. Example:
// pages/index.js
function Home() {
return (
<div className="container">
<h1>Hello Next.js</h1>
<p>Let's explore different ways to style Next.js apps</p>
<style jsx>{`
.container {
margin: 50px;
}
p {
color: blue;
}
`}</style>
</div>
)
}
export default Home
The style code above applies only to the component Home()
, that is, only the <p>
and the div
class container
shall be affected by the stylisation rules and even if other components have this element <p>
or class container
, they will not be affected.
You can create global styles with this tag, just pass the attribute global
:
// pages/index.js
function Home() {
return (
<div className="container">
<h1>Hello Next.js</h1>
<p>Let's explore different ways to style Next.js apps</p>
<style jsx global>{`
.container {
margin: 50px;
}
p {
color: blue;
}
`}</style>
</div>
)
}
export default Home
This applies stylizations to all elements p
or class container
on this page.
I think this article can help you - https://nextjs.org/blog/styling-next-with-styled-jsx
– Vitorio Aragão