Observing how they do it on the website www.primefaces.org/primereact/showcase/, open Developer view: Elements, and one can notice that choosing a different theme changes css file link in HTML header:

<link id="theme-link" rel="stylesheet" href="./themes/bootstrap4-light-blue/theme.css">

becomes

<link id="theme-link" rel="stylesheet" href="./themes/bootstrap4-light-purple/theme.css">

It is fairly easy to switch link element HREF from one to another.

This page talks about primereact theme switching: Switch Your React App Between Material, Bootstrap and Custom Themes at Runtime

But the method it describes is too convoluted, involves ejecting and custom webpack, to bundle all theme CSS files and import them programmatically, like that:

const changeTheme = (theme) => {
  import(`./${theme}.scss`).then((module) => {
    if (selectedThemeModule) {
      selectedThemeModule.unuse();
    }
    module.use();
    setSelectedThemeModule(module);
  });
}

Instead, grab the example repo where they do method of link HREF swap: github.com/mertsincan/primereact-dynamic-theming/

example-1 has code for the convoluted method from the above page, you can skip it and go to example-2, which is much simpler.

In a nutshell, add to 'public/index.html', in <header> section:

<link id="app-theme" rel="stylesheet" type="text/css" href="saga-blue.css">

And use this function:

const changeTheme = (theme) => {
  let themeLink = document.getElementById('app-theme');
  if (themeLink) {
    themeLink.href = theme + '.css';
  }
}

Then just call changeTheme(XXX) when theme XXX is clicked.

Next put .css files into the right place - just copy all node_modules/primereact/themes/*/theme.css files into public folder (giving them corresponding theme names). Some theme.css reference fonts - search for "url" in each file, and if present, copy corresponding fonts/ directory too.

I should mention that benefits of example-1 is using minified and bundled CSS files, so themes will be switching faster. If that's important, then follow the above linked tutorial and example-1. Also note that example-2 has very similar setup to example-1 (eject and custom webpack config), but only to copy css files to the right output folder, which can be skipped in favor of copying files by hand once.

Answer from iva2k on Stack Overflow
๐ŸŒ
PrimeReact
primereact.org โ€บ theming
Theming - PrimeReact
Choose from a variety of themes or develop your own theme easily. Note: In near future, theming architecture of the styled mode will be redesigned to utilize CSS variables instead of SCSS variables in a backward compatible way for a dynamic approach. PrimeReact is a design agnostic library so unlike other UI libraries it does not enforce a certain styling such as material or bootstrap.
Top answer
1 of 4
7

Observing how they do it on the website www.primefaces.org/primereact/showcase/, open Developer view: Elements, and one can notice that choosing a different theme changes css file link in HTML header:

<link id="theme-link" rel="stylesheet" href="./themes/bootstrap4-light-blue/theme.css">

becomes

<link id="theme-link" rel="stylesheet" href="./themes/bootstrap4-light-purple/theme.css">

It is fairly easy to switch link element HREF from one to another.

This page talks about primereact theme switching: Switch Your React App Between Material, Bootstrap and Custom Themes at Runtime

But the method it describes is too convoluted, involves ejecting and custom webpack, to bundle all theme CSS files and import them programmatically, like that:

const changeTheme = (theme) => {
  import(`./${theme}.scss`).then((module) => {
    if (selectedThemeModule) {
      selectedThemeModule.unuse();
    }
    module.use();
    setSelectedThemeModule(module);
  });
}

Instead, grab the example repo where they do method of link HREF swap: github.com/mertsincan/primereact-dynamic-theming/

example-1 has code for the convoluted method from the above page, you can skip it and go to example-2, which is much simpler.

In a nutshell, add to 'public/index.html', in <header> section:

<link id="app-theme" rel="stylesheet" type="text/css" href="saga-blue.css">

And use this function:

const changeTheme = (theme) => {
  let themeLink = document.getElementById('app-theme');
  if (themeLink) {
    themeLink.href = theme + '.css';
  }
}

Then just call changeTheme(XXX) when theme XXX is clicked.

Next put .css files into the right place - just copy all node_modules/primereact/themes/*/theme.css files into public folder (giving them corresponding theme names). Some theme.css reference fonts - search for "url" in each file, and if present, copy corresponding fonts/ directory too.

I should mention that benefits of example-1 is using minified and bundled CSS files, so themes will be switching faster. If that's important, then follow the above linked tutorial and example-1. Also note that example-2 has very similar setup to example-1 (eject and custom webpack config), but only to copy css files to the right output folder, which can be skipped in favor of copying files by hand once.

2 of 4
4

There is an even easier way to do this They do explain it a bit in the docs but it isn't as copy-paste in the docs

Here is what I did in my React app:

This is in my index.html file Define an element with an id to reference later in your code, and them also href to the directory where the styles are.

   <link id="app-theme" rel="stylesheet" href="/themes/lara-dark-blue/theme.css">

The styles should be copied from the node_modules of prime react Copy the dark and light theme from Lara

cp -r ./node_modules/primereact/resources/themes/lara-light-blue ./public/themes/lara-light-blue
cp -r ./node_modules/primereact/resources/themes/lara-dark-blue ./public/themes/lara-dark-blue

You can also just drag and drop them, but terminal is also nice ;)

Now in your React component, import PrimeReact from the api directory and then use the changeTheme utility function to change from dark to light and vice versa

import PrimeReact from 'primereact/api';

function App() {

  const [theme, setTheme] = useState('dark');

  const changeMyTheme = () => {
    const newTheme = theme === 'dark' ? 'light' : 'dark';
    PrimeReact?.changeTheme?.(`lara-${theme}-blue`, `lara-${newTheme}-blue`, 'app-theme', () =>
      setTheme(newTheme)
    );
  };

  return (
    <div>
      <header>
        <button
          className={`p-2 rounded ${theme === 'dark' ? 'bg-gray-100 text-black' : 'bg-gray-700 text-white'}`}
          onClick={() => changeMyTheme()}
        >
          <span className={`pr-1 pi pi-${theme === 'dark' ? 'sun' : 'moon'}`}></span>
         Change Theme
        </button>
      </header>
    </div>
  );
}

Here are the docs if you need to reference some more details as well as other themes available https://primereact.org/theming/

Discussions

PrimeReact Theme Designer is now free and open source
No idea how PrimeReact is not more mainstream than it is atm. While I haven't worked with it recently, it's 100% an S+ tier library in the projects I used it in. This designer looks really cool. More on reddit.com
๐ŸŒ r/reactjs
8
69
March 15, 2023
reactjs - Use PrimeReact Themes with CSS Modules Enabled in React Application - Stack Overflow
I have enabled CSS modules within webpack.config in my React application so that I can locally scope CSS files to individual components. I'm also trying to use the TabView component from PrimeReac... More on stackoverflow.com
๐ŸŒ stackoverflow.com
December 29, 2017
html - Overriding PrimeReact Styling - Stack Overflow
A different solution could be, link the stylesheet with PrimeReact before your own stylesheet (inside of your HTML). This solution will require a deep analysis of the style implementation by the webpack. ... Later CSS imports that come after the theme will override the templates as the last ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
PrimeReact - switch themes without ejecting?
You don't need to eject or use something like craco to be able to change theme. in your index.html add in public folder copy the desired themes from primereact library see my folder structure in index.html we loaded noflash.js here is the content of the file (function () { const darkTheme = 'mdc-dark-indigo'; const lightTheme = 'mdc-light-indigo'; const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; const darkMode = localStorage.getItem('darkMode') === 'true' ?? prefersDarkMode; const themeLink = document.getElementById('app-theme'); if (themeLink) { themeLink.href = \/themes/${darkMode ? darkTheme : lightTheme}/theme.css`;` } })(); now in App component useEffect(() => { let themeLink = document.getElementById('app-theme') as HTMLLinkElement; const darkTheme = 'mdc-dark-indigo'; const lightTheme = 'mdc-light-indigo'; if (themeLink) { themeLink.href = \${process.env.PUBLIC_URL}/themes/${darkMode.value ? darkTheme : lightTheme}/theme.css`;` } }, [darkMode.value]); the useEffect hook expects a value for dark mode which in my case I just use use-dark-mode hook . I just use the mdc themes but you can use as many as you like. more themes can be found here hope this helps you. More on reddit.com
๐ŸŒ r/reactjs
2
2
April 5, 2022
๐ŸŒ
GitHub
github.com โ€บ primefaces โ€บ primereact
GitHub - primefaces/primereact: The Most Complete React UI Component Library ยท GitHub
// theme import 'primereact/resources/themes/lara-light-cyan/theme.css';
Starred by 8.3K users
Forked by 1.2K users
Languages ย  CSS 59.8% | JavaScript 39.7% | SCSS 0.5%
๐ŸŒ
PrimeReact
primereact.org โ€บ templates
PrimeReact | React UI Component Library
The ultimate collection of design-agnostic, flexible and accessible React UI Components.
๐ŸŒ
Primereact
v9.primereact.org โ€บ installation
PrimeReact | React UI Component Library
//theme import "primereact/resources/themes/lara-light-indigo/theme.css"; //core import "primereact/resources/primereact.min.css";
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ primereact
primereact - npm
August 15, 2025 - PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support.
      ยป npm install primereact
    
Published ย  Aug 15, 2025
Version ย  10.9.7
Author ย  PrimeTek Informatics
๐ŸŒ
GitHub
github.com โ€บ primefaces โ€บ primereact-sass-theme
GitHub - primefaces/primereact-sass-theme: PrimeReact Theming with SASS ยท GitHub
Usually you want to update the CSS files in the PrimeReact repository, located in the /primereact/public/themes folder.
Starred by 47 users
Forked by 57 users
Languages ย  SCSS
Find elsewhere
๐ŸŒ
Hashnode
primetek.hashnode.dev โ€บ switch-your-react-app-between-material-bootstrap-and-custom-themes-at-runtime
Switch Your React App Between Material, Bootstrap and Custom Themes at Runtime
August 24, 2021 - PrimeReact provides various themes including Material, Bootstrap, FluentUI and PrimeOne with dark mode alternatives. These are provided at primereact/resources/themes folder so first thing to do it creating an scss file that imports the one ...
๐ŸŒ
PrimeFaces
primefaces.org โ€บ primereact-v8 โ€บ setup
PrimeReact | React UI Component Library
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>SliderDemo</title> <!-- PrimeReact --> <link rel="stylesheet" href="https://unpkg.com/primeicons/primeicons.css" /> <link rel="stylesheet" href="https://unpkg.com/primereact/resources/themes/lara-light-indigo/theme.css" /> <link rel="stylesheet" href="https://unpkg.com/primereact/resources/primereact.min.css" /> <link rel="stylesheet" href="https://unpkg.com/[email protected]/primeflex.min.css" /
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ primereact theme designer is now free and open source
r/reactjs on Reddit: PrimeReact Theme Designer is now free and open source
March 15, 2023 -

Hi all,

As part of the PrimeReact roadmap, we're excited to announce that Theme Designer is now open source and free to use.

For more information, visit the documentation.

P.S. We're now working on the new styling engine that utilizes CSS variables instead of SCSS with support for css-in-js and also the new Unstyled mode so that you can just ignore all this and style the components with Tailwind, Bootstrap or similar.

Happy coding!

Top answer
1 of 2
3

I was able to use CSS modules and selectively apply global scoping to PrimeReact's themes by modifying webpack.config as follows below.

Original:

{
            test: /\.css$/,
            use: [
              require.resolve('style-loader'),
              {
                loader: require.resolve('css-loader'),
                options: {
                  importLoaders: 1,
                  modules: true,
                  localIdentName: '[name]__[local]__[hash:base64:5]'
                },
              },
              {
                loader: require.resolve('postcss-loader'),
                options: {
                  // Necessary for external CSS imports to work
                  // https://github.com/facebookincubator/create-react-app/issues/2677
                  ident: 'postcss',
                  plugins: () => [
                    require('postcss-flexbugs-fixes'),
                    autoprefixer({
                      browsers: [
                        '>1%',
                        'last 4 versions',
                        'Firefox ESR',
                        'not ie < 9', // React doesn't support IE8 anyway
                      ],
                      flexbox: 'no-2009',
                    }),
                  ],
                },
              },
            ],
          },

Modified:

 {
            test: /\.css$/,
            //Exclude 3rd party css that needs to be scoped globally from using
            //css-loader with modules enabled
            exclude: [
              path.resolve('node_modules/primereact/resources/primereact.css'),
              path.resolve('node_modules/primereact/resources/themes/cupertino/theme.css'),
            ],
            use: [
              require.resolve('style-loader'),
              {
                loader: require.resolve('css-loader'),
                options: {
                  importLoaders: 1,
                  modules: true,
                  localIdentName: '[name]__[local]__[hash_base64:5]'
                },
              },
              {
                loader: require.resolve('postcss-loader'),
                options: {
                  // Necessary for external CSS imports to work
                  // https://github.com/facebookincubator/create-react-app/issues/2677
                  ident: 'postcss',
                  plugins: () => [
                    require('postcss-flexbugs-fixes'),
                    autoprefixer({
                      browsers: [
                        '>1%',
                        'last 4 versions',
                        'Firefox ESR',
                        'not ie < 9', // React doesn't support IE8 anyway
                      ],
                      flexbox: 'no-2009',
                    }),
                  ],
                },
              },
            ],
          },
          //Additional css-loader configuration
          {
            test: /\.css$/,
            //Inlcude only 3rd party css that needs to be scoped globally to use
            //css-loader with modules disabled
            include: [
              path.resolve('node_modules/primereact/resources/primereact.css'),
              path.resolve('node_modules/primereact/resources/themes/cupertino/theme.css'),
            ],
            use: [
              require.resolve('style-loader'),
              {
                loader: require.resolve('css-loader'),
                options: {
                  importLoaders: 1
                },
              },
              {
                loader: require.resolve('postcss-loader'),
                options: {
                  // Necessary for external CSS imports to work
                  // https://github.com/facebookincubator/create-react-app/issues/2677
                  ident: 'postcss',
                  plugins: () => [
                    require('postcss-flexbugs-fixes'),
                    autoprefixer({
                      browsers: [
                        '>1%',
                        'last 4 versions',
                        'Firefox ESR',
                        'not ie < 9', // React doesn't support IE8 anyway
                      ],
                      flexbox: 'no-2009',
                    }),
                  ],
                },
              },
            ],
          },
2 of 2
0

Use the below two npm commands to install the CSS and Style loader:

npm install style-loader - You can add the Version of the loaded if required npm install css-loader

You are not required to change anything else.

๐ŸŒ
PrimeFaces
primefaces.org โ€บ designer โ€บ primereact-old
Designer for PrimeReact โ€“ PrimeFaces
August 21, 2020 - Designer API is a SASS based theme engine to create PrimeReact themes easily featuring over 500 variables, a demo application and sample themes including the Nova and Luna theme families.
๐ŸŒ
Primer
primer.style โ€บ react โ€บ theming
Theming | Primer React
April 11, 2024 - Theming in Primer React is made possible by a theme object that defines your application's colors, spacing, fonts, and more.
๐ŸŒ
Made with React.js
madewithreactjs.com โ€บ primereact
PrimeReact - UI Component Library - Made with React.js
August 15, 2023 - "PrimeReact is a UI library for React featuring a rich set of 80+ components, a theme designer, 400+ ready-to-use UI blocks, various theme alternatives, premium create-react-app templates and professional support.
๐ŸŒ
Reddit
reddit.com โ€บ r/reactjs โ€บ primereact - switch themes without ejecting?
r/reactjs on Reddit: PrimeReact - switch themes without ejecting?
April 5, 2022 -

I'm familiar with mui and its ThemeProvider, which is great when you want your user to be able to change the global theme.

Now I'd like to build a new app, but many components/features are not built-in in mui.

I'm trying PrimeReact, which looks perfect for my project. But it seems that to change themes, you have to eject from CRA (see this tutorial)

The ejecting is just for loading different .sass files, but resulted in managing webpack manually?

Is there any way to achieve this without eject?

Will something like craco work?

๐ŸŒ
Plunker
embed.plnkr.co โ€บ ZVee7vqMbJCWgGv6Z5SY
PrimeReact Issue Template - Plunker
<!DOCTYPE html> <html> <head> <title>PrimeReact QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="style.css"> <!-- PrimeReact style dependencies --> <link rel="stylesheet" href="https://unpkg.com/primereact@1.4.0/resources/themes/omega/theme.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /> <link rel="stylesheet" href="https://unpkg.com/primereact@1.4.0/resources/primereact.min.css" /> <!-- Configure SystemJS --> <script src="https://unpkg.com/systemjs@0.20"></script> <script src="systemjs.config.js"></script> </head> <body> <div id="root"></div> </body> </html>