Skip to main content

Color schemed images for Sphinx tests

An extension for Sphinx that adds support for color-scheme aware images. This README.md is also used for the NodeJS package. The NodeJS package contains only the JavaScript module. See below the paragraph about the JavaScript plugin.

Tested

Description

Sphinx Color Schemed Images is an extension that makes available two new image directives to your project:

  • cs_image extends the image directive, and
  • cs_figure extends the figure directive.

These new directives add data attributes to the HTML <img> tag to help web browsers to automatically transition between light and dark color schemes. The extension adds a bit of JavaScript code to trigger an image update when the user switches the color scheme.

Usage

Install the package:

pip install sphinx-colorschemed-images

Add sphinx_colorschemed_images to the extensions setting, in your project's conf.py file.

As an example, download the following files and place them in the source directory of your Sphinx project, inside the image directory. I assume the sources are in the docs/ directory, and the image directory is docs/img/:

Now edit your index.rst or index.md file, and add a cs_image directive. For index.rst, add:

.. cs_image:: img/balloon.png
   :alt: A balloon icon
   :align: center
   :width: 200

If it is an index.md, add the following instead:

```{cs_image} img/balloon.png
:alt: A balloon icon
:align: center
:width: 200
```

Build your Sphinx project and serve it. You should see either the image for the light color scheme, balloon.light.png, or the image for the dark color scheme, balloon.dark.png. Switch your operating system settings and the image should update automatically.

JavaScript plugin

When using the extension Sphinx adds a script to your HTML output, sphinx-colorschemed-images.js, that listens for changes on the user's preferred color-scheme and switches between the images accordingly. It works in all Sphinx themes regardless of whether they have support for light/dark color schemes.

If you have your own theme and it offers the user control over the color-scheme, you can use the NPM package sphinx-colorschemed-images and its class SphinxColorschemeImageHandler when building your own plugin.

The source code is rather small, so it is better to look into it than to explain it here. If your theme already listens for changes in prefers-color-scheme, pass {auto: false} to the constructor, to avoid adding the listeners again. To switch between light and dark images, call the activate method with either light or dark.

Contributing

The Makefile is the lead for all development tasks. Mind the tests in Python and JavaScript.

Appropriate documentation will come soon.

Metadata

Release files for sphinx-colorschemed-images 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-colorschemed-images 0.3.0
File Size Uploaded
sphinx_colorschemed_images-0.3.0.tar.gz 15.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-colorschemed-images 0.3.0
File Interpreter ABI Platform
sphinx_colorschemed_images-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.5 kB

Release files / sphinx_colorschemed_images-0.3.0.tar.gz

Download URL sphinx_colorschemed_images-0.3.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c46e8e37635b97d3d50d6aad025570a9dc237f71d0d2089d64b201518f23917d
BLAKE2b-256 checksum
How to use checksums
d5ab0641eb870c772bed0b920becdcad1ff60d188adfc43bdd1c11243444744f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release files / sphinx_colorschemed_images-0.3.0-py3-none-any.whl

Download URL sphinx_colorschemed_images-0.3.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d478ed44eb265b6ff35ab6eb914a7b11b4f8e34b2e8f57c55d332749edf94bc8
BLAKE2b-256 checksum
How to use checksums
bb2d96aefd687a69a960455f50e1c0354005d0ab215b6f573ef14ef4f5410877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page