Dark and light mode support has been a recent trend due to the impact on our eyesight caused by the time spent on devices. With Tailwind CSS and the proper Nuxt.js (Nuxt) modules, we can easily enable this feature, with the ability to customize each mode’s look and feel to your taste.
In short, you follow the simple steps below to enable dark/light mode with Tailwind CSS and the Nuxt color mode module:
yarn create nuxt-app <project-name>
and choose Tailwind CSS as a UI framework from the configuration selection. In case of an existing Nuxt project, run yarn add --dev @nuxtjs/tailwindcss
and add the module @nuxtjs/tailwindcss
to the list of buildModules
in nuxt.config.js
.tailwindcss-dark-mode
and @nuxtjs/color-mode
.tailwindcss-dark-mode
as a plugin in the collection of plugins
in tailwind.config.js
. Do the same with @nuxtjs/color-mode
by adding require('tailwindcss-dark-mode')()
to the collection of plugins
in nuxt.config.js
.variants
field in tailwind.config.js
.${dark-mode-variant}:${normal-generated-class-for-css-property}
.Too short to understand? Let’s go through slowly, shall we?
Nuxt.js — or Nuxt for short — is a server-side rendering (SSR) framework based on Vue.js, and it offers developers:
Also, Nuxt is surrounded by a well-maintained ecosystem — the Nuxt community, which provides lots of practical modules, plugins, and support to simplify the development process.
#javascript #nuxtjs #css #tailwind css