Skip to main content
Documentation
On this page

Install Cirth for Dioxus

Dioxus collects files declared with the asset!() macro and gives them a URL in the finished application. document::Stylesheet places that URL in the document head, so the CSS applies to the whole page. In a release bundle, Dioxus would also rewrite Cirth's light-dark() colours, so disable minification for this already minified file. Compatibility explains why transforming the compiled stylesheet can change theme regions.

Verified with Dioxus 0.7.10 on

Three steps: add the file, link it and check it.

1 Add the file #

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

In src/main.rs:

use dioxus::prelude::*;

const CIRTH: Asset = asset!("/assets/cirth.min.css", AssetOptions::css().with_minify(false));

fn main() {
    dioxus::launch(App);
}

#[component]
fn App() -> Element {
    rsx! {
        document::Stylesheet { href: CIRTH }
        main { class: "container",
            article {
                h1 { "Hello, Dioxus" }
                button { r#type: "button", "Save" }
            }
        }
    }
}

With with_minify(false), dx bundle --release copies the file byte for byte under a hashed name. Without it, the page still follows the system scheme, but a data-theme subtree stops changing colour.

3 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>

Build for production, 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. If the article follows the surrounding page instead, the build rewrote Cirth's colours: check that minification is off for it.

Customization covers the --cirth-* properties; set yours in a second asset!() 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.