Theme

Theming is a key element in designing user interfaces (UIs). It enables the application of a consistent aesthetic across your application, enhancing the user experience and maintaining visual uniformity.

In NextUI, we facilitate easy and flexible theme customization using a TailwindCSS plugin. This plugin, which is based on the tw-colors plugin developed by L-Blondy, allows you to customize color schemes, layout configurations, and more, across different components of your application.

What is a Theme?

A theme, in the context of NextUI, is a predefined set of colors, layout attributes, and other UI elements that you can consistently apply across your application. Themes ensure visual consistency, enrich the user experience, and simplify the management and updates of your app's look and feel.

Setup

The first step to using NextUI's theming capability is adding the nextui plugin to your tailwind.config.js file. Below is an example of how to do this:

Note: If you are using pnpm and monorepo architecture, please make sure you are pointing to the ROOT node_modules

Usage

After adding the plugin to your tailwind.config.js file, you can utilize any of the default themes (light/dark) or a custom one. Here's how you can apply these themes in your main.jsx or main.tsx:

Go to the src directory and inside main.jsx or main.tsx, apply the following class names to the root element:

  • light for the light theme.
  • dark for the dark theme.
  • text-foreground to set the text color.
  • bg-background to set the background color.

Note: See the Colors section to learn more about the color classes.

Default Plugin Options

The nextui plugin provides a default structure. It is outlined as follows:

Themes Options

These are the options that you can use to apply custom configurations to your themes.

Nested themes

NextUI supports nested themes, allowing you to apply different themes to different sections of your application:

Theme based variants

NextUI enables you to apply TailwindCSS styles based on the currently active theme. Below are examples of how to do this:

API Reference

The following table provides an overview of the various attributes you can use when working with themes in NextUI:

AttributeTypeDescriptionDefault
prefixstringThe prefix for the css variables.nextui
addCommonColorsbooleanIf true, the common nextui colors (e.g. "blue", "green", "purple") will replace the TailwindCSS default colors.false
defaultThemelight | darkThe default theme to use.light
defaultExtendThemelight | darkThe default theme to extend.light
layoutLayoutThemeThe layout definitions.-
themesConfigThemesThe theme definitions.-

Types

ConfigThemes

LayoutTheme

ThemeColors