# Installation

> Install Cherry Styled Components via npm or by cloning the repository.

Source: https://cherry.al/code/installation

> For the complete documentation index, see [llms.txt](https://cherry.al/llms.txt).

# Installation

There are two main ways to install Cherry Styled Components into your project. You can either clone the main repository and customize the components to your liking, or install the library from npm.

## Implementation Options

<Tabs>
  <TabContent title="NPM">

Install the Cherry library from npm along with its peer dependencies. Import components directly into your project. Perfect for smaller projects or rapid development. The library requires `react` and `react-dom` (^18 or ^19) and `styled-components` (^6) as peer dependencies.

<CodeTabs tabs={[{ label: "npm", code: "npm install cherry-styled-components react react-dom styled-components" }, { label: "pnpm", code: "pnpm add cherry-styled-components react react-dom styled-components" }, { label: "yarn", code: "yarn add cherry-styled-components react react-dom styled-components" }]} />

  </TabContent>
  <TabContent title="Repository">

Clone the main Cherry repository. Dive into the components' code and customize to your heart's content. Ideal for extensive modifications.

```bash
git clone git@github.com:cherry-design-system/styled-components.git
```

  </TabContent>
</Tabs>

## Theme Context

Always wrap your application in the `CherryThemeProvider` component. Ensure that your theme prop is passed down correctly. For server-rendered apps that need flash-free dark mode, use `ClientThemeProvider` instead - see [Dark Mode](/code/dark-mode).

```tsx
import { CherryThemeProvider, theme } from "cherry-styled-components";

export default function App({ children }) {
  return <CherryThemeProvider theme={theme}>{children}</CherryThemeProvider>;
}
```

## Next.js Integration

When integrating into a Next.js app, first install the dependencies:

<CodeTabs tabs={[{ label: "npm", code: "npm install cherry-styled-components react react-dom styled-components" }, { label: "pnpm", code: "pnpm add cherry-styled-components react react-dom styled-components" }, { label: "yarn", code: "yarn add cherry-styled-components react react-dom styled-components" }]} />

Next, enable the styled-components compiler in your `next.config.ts`. This keeps class names deterministic between server and client renders and avoids hydration mismatches:

<Code title="next.config.ts" language="ts" code={`import type { NextConfig } from "next";

  const nextConfig: NextConfig = {
    compiler: {
      styledComponents: true,
    },
  };

  export default nextConfig;`} />

To render the CSS, open your `layout.tsx` and wrap your application. The `StyledComponentsRegistry` component injects the server-rendered styles into the HTML via `useServerInsertedHTML`, so styled-components work with server-side rendering and the App Router.

It is the one export that depends on Next, so it ships from the `cherry-styled-components/next` subpath rather than the package root. Everything else imports from `cherry-styled-components` as usual:

<Code title="app/layout.tsx" language="tsx" code={`import { StyledComponentsRegistry } from "cherry-styled-components/next";
  import { CherryThemeProvider, theme } from "cherry-styled-components";

  export default function RootLayout({
    children,
  }: Readonly<{
    children: React.ReactNode;
  }>) {
    return (
      <html lang="en">
        <body>
          <StyledComponentsRegistry>
            <CherryThemeProvider theme={theme}>{children}</CherryThemeProvider>
          </StyledComponentsRegistry>
        </body>
      </html>
    );
  }`} />

<Callout type="info">
  Next.js requires these additional steps because it uses server-side rendering.
</Callout>
