You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

next-themes

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-themes

An abstraction for themes in your React app.

0.4.6
latest
Source
npmnpm
Version published
Weekly downloads
3.5M
3.56%
Maintainers
2
Weekly downloads
 
Created

What is next-themes?

The next-themes package is a utility for managing themes in Next.js applications. It provides a simple and efficient way to implement dark mode, light mode, and custom themes with minimal configuration.

What are next-themes's main functionalities?

Theme Provider

The ThemeProvider component wraps your application and provides the context for theme management. The `attribute` prop specifies how the theme is applied, such as using a class or data attribute.

```jsx
import { ThemeProvider } from 'next-themes';

function MyApp({ Component, pageProps }) {
  return (
    <ThemeProvider attribute="class">
      <Component {...pageProps} />
    </ThemeProvider>
  );
}

export default MyApp;
```

Use Theme Hook

The `useTheme` hook allows you to access and manipulate the current theme. You can use it to create theme switchers or to apply theme-specific logic in your components.

```jsx
import { useTheme } from 'next-themes';

function ThemeSwitcher() {
  const { theme, setTheme } = useTheme();

  return (
    <div>
      <button onClick={() => setTheme('light')}>Light Mode</button>
      <button onClick={() => setTheme('dark')}>Dark Mode</button>
      <button onClick={() => setTheme('system')}>System Default</button>
    </div>
  );
}
```

Custom Themes

You can define custom themes and pass them to the ThemeProvider. This allows you to have more control over the appearance of your application and to create unique themes beyond just light and dark modes.

```jsx
import { ThemeProvider } from 'next-themes';

const customThemes = {
  light: {
    background: '#ffffff',
    color: '#000000'
  },
  dark: {
    background: '#000000',
    color: '#ffffff'
  }
};

function MyApp({ Component, pageProps }) {
  return (
    <ThemeProvider themes={customThemes} attribute="class">
      <Component {...pageProps} />
    </ThemeProvider>
  );
}

export default MyApp;
```

Other packages similar to next-themes

FAQs

Package last updated on 11 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts