Skip to main content
Documentation
On this page

Install Cirth for htmx

htmx asks the server for HTML and swaps it into the page. Cirth styles elements, not components. Link the stylesheet once in the <head> of the initial full document. Fragments returned later reuse that global CSS and need no stylesheet link of their own.

Verified with htmx 2.0.11 on

Three steps: link it, return plain fragments and check it.

In the layout the server renders, next to htmx:

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="/css/cirth.min.css">
  <script src="/js/htmx.min.js" defer></script>
</head>

Serve the file the way your backend serves static files (see its guide, or the CDN link). With hx-boost, htmx swaps the body and keeps the head, so the stylesheet loads once for the whole visit.

2 Return plain fragments #

A fragment is ordinary HTML, with the states Cirth reads written as attributes:

<article>
  <header>Subscribed</header>
  <label>
    Email
    <input type="email" name="email" aria-invalid="true" aria-describedby="email-error">
  </label>
  <small id="email-error">That address bounced.</small>
</article>

An element with class="htmx-indicator" and aria-busy="true" is Cirth's spinner, and htmx shows it only while a request is in flight.

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>

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.

Swap the same markup in with hx-get: it arrives styled.

Customization covers the --cirth-* properties; set yours in a stylesheet loaded after Cirth's. 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.