Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Blazor
  3. CssBuilder

CssBuilder

C#1.8.0

A Builder pattern for cleanly managing conditional CSS classes in ASP.NET Razor Components.

GitHubGitHub
223 stars26 forks0 contributors

Overview

CssBuilder is a Builder pattern for CSS classes to be used with Razor Components.

Use Cases

Not Ideal For

  • Projects not using ASP.NET Razor Components (Blazor)
  • Very simple components with few or no conditional CSS classes
  • Teams heavily invested in utility-first CSS frameworks like Tailwind CSS
  • Scenarios requiring dynamic inline styles or CSS variable management beyond class strings

Pros & Cons

Pros

Conditional Class Management

Centralizes CSS logic with the AddClass method and boolean conditions, as shown in the README's refactored example where bl-active and bl-disabled are cleanly handled based on component state.

Dynamic Value Support

Enables string interpolation for dynamic class names, such as bl-${SomeValue}, allowing flexible styling based on runtime values without manual concatenation.

Attribute Splatting Integration

The AddClassFromAttributes method merges splatted CSS attributes from AdditionalAttributes, essential for Blazor components that accept arbitrary parameters, as demonstrated in the attribute splatting example.

Prefix Management

SetPrefix method applies a common prefix like bl- to multiple classes, reducing redundancy and errors, illustrated in the refactored code with SetPrefix('bl-').AddClass('nav-link').

Cons

Blazor-Specific Limitation

Tied exclusively to ASP.NET Razor Components, making it irrelevant for other web frameworks like React, Vue, or traditional ASP.NET MVC, which limits its adoption outside the Blazor ecosystem.

Overhead for Simple Use Cases

For components with static or minimal conditional classes, the builder pattern adds unnecessary code complexity compared to inline conditionals or simple string concatenation, as seen in the basic problem example.

Dependency Addition

Introduces an external library dependency for CSS string building, which might conflict with projects aiming for minimal dependencies or those using alternative styling approaches like CSS modules.

Frequently Asked Questions

Quick Stats

Stars223
Forks26
Contributors0
Open Issues0
Last commit4 years ago
CreatedSince 2019

Tags

#razor-components#aspnet-core#frontend-tooling#builder-pattern#css-utilities#clean-code#blazor

Built With

B
Blazor
A
ASP.NET Core
R
Razor Components
C
C++

Included in

Blazor9.3k
Auto-fetched 1 day ago

Related Projects

FluxorFluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.

Stars1,469
Forks163
Last commit5 days ago
Blazored.LocalStorageBlazored.LocalStorage

A library to provide access to local storage in Blazor applications

Stars1,331
Forks133
Last commit1 year ago
bUnit - a testing library for Blazor componentsbUnit - a testing library for Blazor components

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.

Stars1,295
Forks118
Last commit2 days ago
Blazor-StateBlazor-State

A Blazor State management library by TimeWarp.

Stars613
Forks57
Last commit4 months ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub