Skip to main content

CSS-only icon system for Django

Project description

django-iconx

PyPI version Python versions CI

CSS-only icon system for Django.

Generates a single CSS file from SVG icon sources (e.g. Lucide, Heroicons, or your own SVGs). Icons are rendered purely via CSS — no JavaScript, no icon fonts, no template tags needed.

Usage

<!-- basic icon -->
<i class="icon icon-search" aria-hidden="true"></i>

<!-- sized via Tailwind text-* (width/height = 1em, so font-size controls size) -->
<i class="icon icon-check text-2xl" aria-hidden="true"></i>

<!-- colored via Tailwind text-* (mono icons only, via currentColor mask trick) -->
<i class="icon icon-check text-2xl text-green-500" aria-hidden="true"></i>

<!-- multi-color icon (preserves original SVG colors) -->
<i class="icon icon-logo text-4xl" aria-hidden="true"></i>

How it works

Mono icons use mask-image + background-color: currentColor — the SVG acts as a mask, so the icon inherits text color. Multi-color icons use background-image to render the SVG as-is.

/* base: all icons */
.icon { display: inline-block; width: 1em; height: 1em; }

/* mono icons: grouped selector */
.icon-search, .icon-check, ... {
  background-color: currentColor;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  mask-mode: alpha;
}

/* individual mask per icon */
.icon-search { mask-image: url("/static/icons/search.svg"); }

/* multi-color icons: grouped selector */
.icon-logo, .icon-badge, ... {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.icon-logo { background-image: url("/static/logos/logo.svg"); }

Key design choices:

  • currentColor — mono icons inherit text color automatically
  • 1em sizing — icons scale with font size via Tailwind text-* classes
  • mask-mode: alpha — SVG alpha channel drives the mask, fill colors are irrelevant
  • Direct element styling — no ::before pseudo-element, simpler CSS
  • Tree-shakeable — PurgeCSS strips unused .icon-* rules from the generated CSS

Browser support

django-iconx uses CSS mask-image, which is supported unprefixed in all modern browsers since December 2023 (~97% global coverage). Older browsers (Chrome < 120, Safari < 15.4) need the -webkit-mask-image prefix.

Tailwind v4 handles vendor prefixing automatically — just @import the generated CSS file in your Tailwind entry point:

@import "tailwindcss";
@import "./static/iconx/icons.css";

With vendor prefixes applied, the only unsupported browsers are pre-Chromium Edge (≤ 18) and Internet Explorer.

Installation

pip install django-iconx

Documentation

Full documentation at oliverhaas.github.io/django-iconx

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_iconx-0.1.0a2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_iconx-0.1.0a2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file django_iconx-0.1.0a2.tar.gz.

File metadata

  • Download URL: django_iconx-0.1.0a2.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_iconx-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 148a4e1d329cf4c7ff8692799a17dc29dda25430dc476f7f8cab0765adcdf0ec
MD5 7f987ad162801f5e446ec87c5e73162e
BLAKE2b-256 18c33d3244ecb723d39f29a7571d0c4f8c8c31a0a4022fb7b1db1b87ca20852f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_iconx-0.1.0a2.tar.gz:

Publisher: publish.yml on oliverhaas/django-iconx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_iconx-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: django_iconx-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_iconx-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 45cb9f1c1146325995523c68f3b1cf05925699e5cb59b19d85ff717c75bf01d0
MD5 21d3b28b8b3472e56914cb2516d537f0
BLAKE2b-256 bd7e5bf2812a780985a209f1bb656c61bea0f360262716127f7f12d891151c81

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_iconx-0.1.0a2-py3-none-any.whl:

Publisher: publish.yml on oliverhaas/django-iconx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page