Skip to main content
Documentation
On this page

Install Cirth for ASP.NET Core

wwwroot/ is ASP.NET Core's public directory: files there can be requested by the browser. A shared Razor layout supplies the <head> for every page, so one <link> there makes Cirth global. Since .NET 9, MapStaticAssets also fingerprints and compresses the file.

Verified with .NET SDK 10.0.401 on

Four steps: add the file, link it, write Razor and check it.

1 Add the file #

mkdir -p wwwroot/css
curl -o wwwroot/css/cirth.min.css \
  https://cdn.jsdelivr.net/npm/@cirthcss/cirth@0.17.0/dist/cirth.min.css

In Pages/Shared/_Layout.cshtml (or Views/Shared/_Layout.cshtml for MVC), in place of the template's Bootstrap link:

<link rel="stylesheet" href="~/css/cirth.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />

The published page links /css/cirth.min.<hash>.css, served with a long cache lifetime and a compressed copy beside it. The template's Bootstrap scripts and markup classes can go too; Cirth needs neither.

3 Write Razor #

Tag helpers render ordinary elements, and the validation helpers add the attributes Cirth reads:

<form method="post">
  <label>
    Email
    <input asp-for="Email" type="email" />
  </label>
  <button type="submit">Subscribe</button>
</form>

4 Check it #

Put this forced-dark region in a page or component that uses the global stylesheet:

<section data-theme="dark">
  <article>
    <p>Dark, whatever the system scheme is.</p>
  </article>
</section>

Run the app, then open the page while the system uses a light theme. A dark article proves that Cirth loaded and that data-theme="dark" is working. It remains dark when the system switches to a dark theme.

Customization covers the --cirth-* properties; set yours in site.css, linked after Cirth. Package and builds lists the classless, scoped and print entry points. Return to Framework guides for another stack.

Search documentation

Type at least two characters to search.