Skip to main content
Documentation
On this page

Install Cirth for Django

Django serves CSS as a static file, and nothing in its pipeline rewrites it. Cirth goes in an app's static folder and is linked from your base template.

Verified with Django 6.1.1 on

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

1 Add the file #

Put the default build in your app's static directory, inside a folder named after the app, which is how Django tells apart two apps' files with the same name. For an app called pages:

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

The app has to be in INSTALLED_APPS, and django.contrib.staticfiles already is in a new project. If the project uses npm, copy node_modules/@cirthcss/cirth/dist/cirth.min.css instead. To skip the file altogether, put the CDN link in the template.

In your base template, load the static tag and link the file:

{% load static %}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}My site{% endblock %}</title>
    <link rel="stylesheet" href="{% static 'pages/css/cirth.min.css' %}">
  </head>
  <body>
    <main class="container">
      {% block content %}{% endblock %}
    </main>
  </body>
</html>

Link a stylesheet of your own after it to override --cirth-* properties (Customization).

3 Write templates #

A Django form renders labels and inputs, which Cirth styles as they are:

{% extends "pages/base.html" %}

{% block content %}
  <article>
    <header><h1>Hello, Django</h1></header>
    <form method="post">
      {% csrf_token %}
      <label>
        Email
        <input type="email" name="email" required>
      </label>
      <button type="submit">Subscribe</button>
    </form>
  </article>
{% endblock %}

Deploying #

python manage.py collectstatic copies the file into STATIC_ROOT with everything else. With ManifestStaticFilesStorage, the copy gets a hashed name that the static tag resolves, and its content stays as it was: Cirth's icons are data: URLs, which the storage leaves alone. See Django's static files deployment guide.

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 a stylesheet 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.