Colors
The full Tailwind color palette is available as strongly typed Color values: 22 families, 11 shades each, plus black and white.
Color utilities
Pass a Color value to one of three methods. The color
name becomes part of the generated class.
| Utility | Generated CSS |
|---|---|
Background(Color.Red500) |
background-color: <value> -> bg-red-500 |
Color(Color.Red500) |
color: <value> -> text-red-500 |
BorderColor(Color.Red500) |
border-color: <value> -> border-red-500 |
<div class="@Css.P(4).RoundedMd()
.Background(Color.Red500)
.Color(Color.White).FontBold()">
Red 500
</div>
Reading a color
Each Color exposes the raw value as well, which is useful
when you need the value in your own code.
Color emerald = Color.Emerald500;
string name = emerald.Name; // "emerald-500"
string value = emerald.Value; // "oklch(0.696 0.17 162.48)"
Custom colors
The Tailwind palette is only a starting point. Color
has a public constructor, so you can create any color you need: the first argument is the
name used to build the class, the second is any valid CSS color value (hex,
rgb(), oklch(),
even var(--brand)).
// Color(name, value): the name becomes the class, the value is any CSS color.
Color brand = new("brand-500", "#6366f1");
Css.Background(brand); // -> class: bg-brand-500
Css.Color(brand); // -> class: text-brand-500
Css.BorderColor(brand); // -> class: border-brand-500
<div class="@Css.P(4).RoundedMd()
.Background(MyColors.Brand500)
.Color(Color.White).FontBold()">
Brand 500
</div>
Your own colors class
Group related colors in your own static class, exactly like
FluentCss.Core.Color does. The values are ordinary
Color instances, so they work everywhere a built-in
color is accepted, including Hover, responsive and
theme variants.
public static class MyColors
{
public static readonly Color Brand50 = new("brand-50", "#eef2ff");
public static readonly Color Brand100 = new("brand-100", "#e0e7ff");
public static readonly Color Brand300 = new("brand-300", "#a5b4fc");
public static readonly Color Brand500 = new("brand-500", "#6366f1");
public static readonly Color Brand700 = new("brand-700", "#4338ca");
public static readonly Color Brand900 = new("brand-900", "#312e81");
}
// Then use them like any built-in color, including variants:
Css.Background(MyColors.Brand500).Color(MyColors.Brand50);
Css.Hover(h => h.Background(MyColors.Brand700));
Dark.Color(MyColors.Brand100);
The name is the identity
Name becomes the class
(bg-brand-500), so it must be unique and stable. Two
colors with the same name are treated as the same class, and the first value registered wins.
The palette
Every family runs from shade 50 (lightest) to 950 (darkest). The swatches below are rendered with the builder itself.
amber
blue
cyan
emerald
fuchsia
gray
green
indigo
lime
neutral
orange
pink
purple
red
rose
sky
slate
stone
teal
violet
yellow
zinc