Skip to main content
Documentation
On this page

Install Cirth for Yew

Trunk builds a Yew application from its index.html, and copies every stylesheet that file links. Cirth is one file in the project and one <link>.

Verified with Yew 0.23.0 on

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

1 Add the file #

Put the default build next to your index.html, for example in styles/:

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

In index.html, a data-trunk link with rel="css":

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello, Yew</title>
    <link data-trunk rel="css" href="styles/cirth.min.css">
  </head>
  <body></body>
</html>

Trunk copies the file to dist/ under a hashed name, unchanged, and adds an integrity hash to the link it writes. Its optional --minify reformats the file and keeps Cirth's light-dark() colours, so there is no CSS target to set.

3 Write HTML #

The html! macro renders ordinary elements:

use yew::prelude::*;

#[function_component(App)]
fn app() -> Html {
    html! {
        <main class="container">
            <article>
                <header><h1>{ "Hello, Yew" }</h1></header>
                <label>
                    { "Email" }
                    <input type="email" name="email" required=true />
                </label>
                <footer><button type="submit">{ "Subscribe" }</button></footer>
            </article>
        </main>
    }
}

fn main() {
    yew::Renderer::<App>::new().render();
}

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 another Trunk CSS 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.