Yak

Getting started

How to get started with next-yak

next-yak

next-yak is a CSS-in-JS solution tailored for Next.js that seamlessly combines the expressive power of styled-components syntax with efficient build-time extraction of CSS using Next.js's built-in CSS configuration.

next-yakNext.jsreactswc_core
4.x>= 15.0.419.x5.0.1
3.x15.x18.x / 19.x3.0.2
2.x14.x18.x / 19.x0.279.0

Installation

Install the package

Install next-yak dependency using your favorite package manager.

# For Next.js >= 15.0.4
npm i next-yak@4
 
# For Next.js 14.x
npm i next-yak@2

Enable next-yak

Add next-yak to your next configuration file:

import type { NextConfig } from 'next'
import { withYak } from "next-yak/withYak";
 
const nextConfig: NextConfig = {
  // your next.js config
}
 
export default withYak(nextConfig);

Start using next-yak

With the installation and configuration done, you can now use next-yak directly in your components. If you used styled-components before, you'll feel right at home.

Here's a simple example:

app/page.tsx
import { styled } from 'next-yak';
 
const StyledDiv = styled.div`
  color: #333;
  padding: 16px;
  background-color: #f0f0f0;
`;
 
function HomePage() {
  return <StyledDiv>Hello, next-yak!</StyledDiv>;
}
 
export default HomePage;

You're now ready to use next-yak in your Next.js project and if you need to migrate from styled-components, you can follow the migration guide.

On this page