Introduction
Filament uses CSS variables to define its color palette. These CSS variables are mapped to Tailwind classes in the preset file that you load when installing Filament. The reason why Filament uses CSS variables is that it allows the framework to pass a color palette from PHP via a<style> element that gets rendered as part of the @filamentStyles Blade directive.
By default, Filament’s Tailwind preset file ships with 6 colors:
primary, which is Tailwind’sambercolor by defaultsuccess, which is Tailwind’sgreencolor by defaultwarning, which is Tailwind’sambercolor by defaultdanger, which is Tailwind’sredcolor by defaultinfo, which is Tailwind’sbluecolor by defaultgray, which is Tailwind’szinccolor by default
How to pass a color to Filament
A registered “color” in Filament is not just one shade. In fact, it is an entire color palette made of 11 shades:50, 100, 200, 300, 400, 500, 600, 700, 800, 900, and 950. When you use a color in Filament, the framework will decide which shade to use based on the context. For example, it might use the 600 shade for a component’s background, 500 when it is hovered, and 400 for its border. If the user has dark mode enabled, it might use 700, 800, or 900 instead.
On one hand, this means that you can specify a color in Filament without having to worry about the exact shade to use, or to specify a shade for each part of the component. Filament takes care of selecting a shade that should create an accessible contrast with other elements where possible.
To customize the color that something is in Filament, you can use its name. For example, if you wanted to use the success color, you could pass it to a color method of a PHP component like so:
Customizing the default colors
From a service provider’sboot() method, or middleware, you can call the FilamentColor::register() method, which you can use to customize which colors Filament uses for UI elements.
There are 6 default colors that are used throughout Filament that you are able to customize:
Color class contains every Tailwind CSS color to choose from.
You can also pass in a function to register() which will only get called when the app is getting rendered. This is useful if you are calling register() from a service provider, and want to access objects like the currently authenticated user, which are initialized later in middleware.
Registering extra colors
You may register a new color to use in any Filament component by passing it to theFilamentColor::register() method, with its name as the key in the array:
secondary as a color in any Filament component.
Using a non-Tailwind color
You can use custom colors that are not included in the Tailwind CSS color palette by passing an array of color shades from50 to 950 in OKLCH format: