Choose from a variety of themes or develop your own theme easily.
PrimeFaces is a design agnostic library so unlike other UI libraries it does not enforce a certain styling such as material or bootstrap. In order to achieve this, styling has been separated into core and theme. Core resides inside PrimeFaces to implement the structure of the components such as positioning whereas theme brings the colors, paddings and margins.
PrimeFaces ships with the saga-blue theme by default. Additional themes such as aura-light-emerald, aura-dark-emerald, vela-blue, arya-blue, material, bootstrap4, luna and nova are available in the primefaces-themes module at github. For a live preview of themes, use the Themes () menu in the topbar to switch themes.
To use an additional theme, add the primefaces-themes dependency to your project:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces-themes</artifactId>
<version>16.0.2-SNAPSHOT</version>
</dependency>
A theme is configured by setting the primefaces.THEME context parameter.
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aura-light-emerald</param-value>
</context-param>
Themes are created with SASS using the primefaces-themes project available at github. This directory contains all the scss files for the components and the variables of all open source themes so that you may customize an existing theme or create your own.
The easiest way to create your own theme is compiling a theme with sass using the existing files.
The theme scss is available as open source at primefaces-themes directory. The theme-base folder contains the theming structure of the components, themes under themes folder import the base and define the SCSS variables. The themes folder also contains all the built-in themes so you can customize their code as well.
To create your own theme, download the release matching your PrimeFaces version and access the themes/primefaces-mytheme folder. You may also choose another theme like aura, material or bootstrap4 as your base. The sass variables to customize are available under the variables folder. The _fonts file can be used to define a custom font for your project whereas the optional _extensions file is provided to add overrides to the components designs. The theme.scss file imports the theme files along with the theme-base folder at the root to combine everything together. Next step would be compilation of the scss that can either be command line or within your project with a maven plugin.
Once your theme is ready run the following command at the root of the primefaces-themes project to compile it as css.
mvn dart-sass:compile-sass
Give a name to your theme e.g. mycooltheme then copy and import the generated theme.css file in your application to resources/primefaces-mycooltheme/theme.css (or under WEB-INF/resources if configured with the jakarta.faces.WEBAPP_RESOURCES_DIRECTORY context parameter) and finally set the primefaces.THEME context parameter. The primefaces- prefix is required to distinguish the resources as a theme.
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>mycooltheme</param-value>
</context-param>
If you'd like to package the theme in a jar file for reuse it in more projects, the location of the theme should be at the META-INF/resources/primefaces-mycooltheme/theme.css path folder inside a jar.