MonorailCss 0.1.1
See the version list below for details.
dotnet add package MonorailCss --version 0.1.1
NuGet\Install-Package MonorailCss -Version 0.1.1
<PackageReference Include="MonorailCss" Version="0.1.1" />
<PackageVersion Include="MonorailCss" Version="0.1.1" />
<PackageReference Include="MonorailCss" />
paket add MonorailCss --version 0.1.1
#r "nuget: MonorailCss, 0.1.1"
#:package MonorailCss@0.1.1
#addin nuget:?package=MonorailCss&version=0.1.1
#tool nuget:?package=MonorailCss&version=0.1.1
MonorailCSS
MonorailCSS is a utility-first CSS library inspired heavily by Tailwind CSS. It's a JIT CSS compiler written in .NET that aims to be Tailwind CSS 4.3 compatible.
Basic Usage
Given a list of CSS classes, MonorailCSS will produce optimized CSS output.
var framework = new CssFramework();
var css = framework.Process("my-4 mx-4 text-red-500");
Will produce:
.mx-4 {
margin-left: 1rem;
margin-right: 1rem;
}
.my-4 {
margin-bottom: 1rem;
margin-top: 1rem;
}
.text-red-500 {
color: var(--color-red-500);
}
You can also process collections of classes:
var classes = new[] { "bg-blue-500", "text-white", "p-4", "rounded-lg" };
var css = framework.Process(classes);
Customizing the Theme
The theme system uses CSS custom properties and can be customized to match your design system:
using System.Collections.Immutable;
// Start with the default theme and customize it
var customTheme = new Theme()
.AddColorPalette("brand", new Dictionary<string, string>
{
{ "50", "#eff6ff" },
{ "100", "#dbeafe" },
{ "200", "#bfdbfe" },
{ "300", "#93c5fd" },
{ "400", "#60a5fa" },
{ "500", "#3b82f6" },
{ "600", "#2563eb" },
{ "700", "#1d4ed8" },
{ "800", "#1e40af" },
{ "900", "#1e3a8a" },
{ "950", "#172554" }
}.ToImmutableDictionary())
.MapColorPalette("sky", "primary") // Map 'sky' palette to 'primary'
.AddFontFamily("display", "'Inter', sans-serif");
var framework = new CssFramework(new CssFrameworkSettings
{
Theme = customTheme
});
// Now you can use: bg-brand-500, text-primary-600, font-display
Component Classes (Apply)
You can create component classes by applying utility classes to selectors:
using System.Collections.Immutable;
var settings = new CssFrameworkSettings
{
IncludePreflight = false,
Applies = new Dictionary<string, string>
{
{ "body", "font-sans text-gray-900" },
{ ".btn", "px-4 py-2 rounded-lg font-semibold" },
{ ".btn-primary", "bg-blue-500 text-white hover:bg-blue-600" },
{ ".card", "bg-white shadow-lg rounded-xl p-6" }
}.ToImmutableDictionary()
};
var framework = new CssFramework(settings);
var css = framework.Process("btn btn-primary");
Merging Conflicting Classes
When you build reusable components, callers inevitably pass classes that conflict with a component's defaults. CssFramework.Merge resolves those conflicts the way tailwind-merge does — later classes win, conflicting earlier ones are dropped, surviving order is preserved:
var framework = new CssFramework();
framework.Merge("px-2 p-4 bg-red-500 hover:p-2 bg-blue-500");
// → "p-4 hover:p-2 bg-blue-500"
// The params overload joins lists, with later lists winning — ideal for caller overrides.
framework.Merge("px-4 py-2 bg-blue-500 text-white", userExtraClasses);
Unlike tailwind-merge's hand-maintained class-group config, MonorailCSS derives conflicts from what each class actually compiles to, so custom utilities participate automatically. Results are cached on the framework and safe for concurrent use. See the Merging Classes guide for the full behavior.
Advanced Features
Custom Variants
Create custom pseudo-classes or selector modifiers:
var settings = new CssFrameworkSettings
{
CustomVariants = new List<CustomVariantDefinition>
{
new() { Name = "scrollbar", Selector = "&::-webkit-scrollbar" },
new() { Name = "scrollbar-track", Selector = "&::-webkit-scrollbar-track" }
}.ToImmutableList()
};
var framework = new CssFramework(settings);
// Use: scrollbar:w-2 scrollbar-track:bg-gray-100
Arbitrary Values
MonorailCSS supports arbitrary values in square brackets:
var framework = new CssFramework();
var css = framework.Process("bg-[#1da1f2] text-[14px] w-[500px]");
Preflight CSS
Control whether to include base/reset styles:
var framework = new CssFramework(new CssFrameworkSettings
{
IncludePreflight = true // Default is true
});
Acknowledgments
- Tailwind CSS — the utility-first design and the CSS output MonorailCSS aims to be compatible with.
- TailwindMerge by Erik Zettersten — the inspiration for
CssFramework.Merge, itself a .NET take on the original tailwind-merge by Dany Castillo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MonorailCss:
| Package | Downloads |
|---|---|
|
MyLittleContentEngine.MonorailCss
MonorailCSS integration for My Little Content Engine providing utility-first CSS framework support |
|
|
Pennington.MonorailCss
MonorailCSS integration for Pennington providing utility-first CSS generation |
|
|
MonorailCss.Discovery
Runtime CSS class discovery for MonorailCSS — scans loaded assembly IL to extract utility classes from .razor, .cs, and compiled NuGet packages without source generators or build tasks. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.2-alpha.0.3 | 0 | 6/23/2026 |
| 0.1.2-alpha.0.2 | 0 | 6/23/2026 |
| 0.1.2-alpha.0.1 | 0 | 6/23/2026 |
| 0.1.1 | 0 | 6/23/2026 |
| 0.1.1-alpha.0.5 | 54 | 6/22/2026 |
| 0.1.1-alpha.0.3 | 51 | 6/22/2026 |
| 0.1.1-alpha.0.2 | 49 | 6/21/2026 |
| 0.1.0 | 100 | 6/21/2026 |
| 0.0.5-alpha.0.175 | 50 | 6/21/2026 |
| 0.0.5-alpha.0.171 | 48 | 6/21/2026 |
| 0.0.5-alpha.0.170 | 51 | 6/20/2026 |
| 0.0.5-alpha.0.169 | 49 | 6/20/2026 |
| 0.0.5-alpha.0.168 | 192 | 6/13/2026 |
| 0.0.5-alpha.0.167 | 72 | 6/12/2026 |
| 0.0.5-alpha.0.166 | 65 | 6/12/2026 |
| 0.0.5-alpha.0.165 | 131 | 6/4/2026 |
| 0.0.5-alpha.0.164 | 61 | 6/4/2026 |
| 0.0.5-alpha.0.163 | 67 | 6/3/2026 |
| 0.0.5-alpha.0.162 | 68 | 5/29/2026 |
| 0.0.5-alpha.0.161 | 70 | 5/29/2026 |