
Styled Jsx
Scope React and Next.js component styles with styled-jsx without global CSS leaks or class-name collisions.
Overview
styled-jsx is an agent skill for the Build phase that guides scoped CSS-in-JS in React and Next.js components.
Install
npx skills add https://github.com/vercel-labs/vercel-plugin --skill styled-jsxWhat is this skill?
- Scoped `<style jsx>` blocks with automatic class isolation per component
- Dynamic styles via template literals and JavaScript expressions inside CSS
- Global styles and `styled-jsx/css` for external style definitions
- Bundled with Next.js; install patterns for npm, pnpm, yarn, and bun
- Full CSS syntax (pseudo-classes, media queries) inside components
Adoption & trust: 3 installs on skills.sh; 187 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need component-local CSS in React without global leaks or awkward styling APIs.
Who is it for?
Next.js or React apps that want colocated, collision-free CSS with standard CSS syntax inside components.
Skip if: Projects standardized on Tailwind-only, CSS Modules-only, or non-React stacks where styled-jsx is not in use.
When should I use this skill?
Writing component-scoped styles with the styled-jsx babel plugin, dynamic styles, global styles, or the styled-jsx/css API.
What do I get? / Deliverables
You get correctly scoped `<style jsx>` patterns, dynamic styles, and global/external definitions aligned with Next.js defaults.
- Scoped component style blocks
- Dynamic/global styled-jsx patterns
- Correct install and import usage
Recommended Skills
Journey fit
How it compares
Use for true scoped CSS-in-JS in components—not as a substitute for a design-system or utility-first CSS framework choice.
Common Questions / FAQ
Who is styled-jsx for?
Solo builders and indie devs shipping React or Next.js UIs who want scoped styles written as plain CSS inside components.
When should I use styled-jsx?
During Build when adding component styles, dynamic theming, global styled-jsx blocks, or installing and configuring the styled-jsx babel plugin in a Next.js app.
Is styled-jsx safe to install?
Review the Security Audits panel on this Prism page and verify package versions from the official registry before adding dependencies to your repo.
SKILL.md
READMESKILL.md - Styled Jsx
# styled-jsx — Scoped CSS-in-JS for React You are an expert in styled-jsx, Vercel's CSS-in-JS library that provides full CSS support scoped to React components. styled-jsx is bundled with Next.js by default. ## Overview styled-jsx lets you write CSS directly inside React components using a `<style jsx>` tag. Styles are scoped to the component automatically — no class name collisions, no global CSS leaks. ## Basic Usage ```tsx function Button() { return ( <div> <button>Click me</button> <style jsx>{` button { background: #0070f3; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; } button:hover { background: #0060df; } `}</style> </div> ) } ``` ## Dynamic Styles Use JavaScript expressions inside template literals: ```tsx function Alert({ type }: { type: 'success' | 'error' }) { return ( <div className="alert"> <style jsx>{` .alert { color: ${type === 'success' ? 'green' : 'red'}; padding: 16px; border: 1px solid ${type === 'success' ? 'green' : 'red'}; } `}</style> </div> ) } ``` ## Global Styles Add the `global` attribute to apply styles globally: ```tsx function Layout({ children }: { children: React.ReactNode }) { return ( <div> {children} <style jsx global>{` body { margin: 0; font-family: -apple-system, sans-serif; } * { box-sizing: border-box; } `}</style> </div> ) } ``` ## External Styles with `styled-jsx/css` Extract styles into variables using the `styled-jsx/css` API: ```tsx import css from 'styled-jsx/css' const buttonStyles = css` button { background: #0070f3; color: white; border: none; padding: 8px 16px; } ` function Button() { return ( <button> Click me <style jsx>{buttonStyles}</style> </button> ) } ``` ### Resolved Styles (for child components) Use `css.resolve` to get a `className` and `styles` element you can pass to child components: ```tsx import css from 'styled-jsx/css' const { className, styles } = css.resolve` a { color: #0070f3; text-decoration: none; } a:hover { text-decoration: underline; } ` function Link({ href, children }: { href: string; children: React.ReactNode }) { return ( <> <a href={href} className={className}>{children}</a> {styles} </> ) } ``` ### Global External Styles ```tsx import css from 'styled-jsx/css' const globalStyles = css.global` body { margin: 0; } ` ``` ## Server Components (Next.js App Router) styled-jsx requires a Client Component boundary. In the App Router, add `"use client"` to any component using `<style jsx>`: ```tsx "use client" function StyledComponent() { return ( <div> <style jsx>{`div { color: blue; }`}</style> </div> ) } ``` ## Key Rules 1. **Scoped by default** — styles only apply to the component where they're defined 2. **Use `global` for global styles** — `<style jsx global>` applies styles globally 3. **Template literals required** — styles must be in tagged template literals (backticks) 4. **One `<style jsx>` per component** — multiple style tags work but one is idiomatic 5. **Bundled with Next.