Skip to main content

Library and CLI application for inlining CSS rules from a set of stylesheets and applying them to an HTML file using `style` attributes.

Project description

inline-css

Inline-CSS is a Python module and CLI application for inlining CSS stylesheets by resolving their rules and applying them directly to the HTML as style tags. For example, with the following HTML and CSS:

<div>
    <p class="demo">Hello, world!</p>
</div>
.demo {
    color: red;
}

The result would be:

<div>
    <p style="color: red">Hello, world!</p>
</div>

Getting Started

This project uses uv; running uv sync and then uv run inline_css ought to do it! See below for usage instructions.

Usage

usage: inline-css [-h] [--verbose] [--out OUT | --outdir OUTDIR | --quash]
                  html css [css ...]

Inlines CSS rules within stylesheets and applies them to HTML files

positional arguments:
  html                  Source HTML file
  css                   Source CSS files

options:
  -h, --help            show this help message and exit
  --verbose, -v         Enable verbose output
  --out OUT, -o OUT     File to write HTML output to. Will be overwritten if
                        it already exists.
  --outdir OUTDIR, -d OUTDIR
                        Directory to write HTML output to. Filename will be
                        same as the source file.
  --quash               Overwrite the original HTML file with the inlined
                        output. Very dangerous!

Limitations

From this library:

  • !important is not currently respected. Occurrences of !important are detected and logged as warnings.
  • Existing style attributes on HTML tags are quashed by CSS rules.

From consequences of running outside a browser, these selectors are accepted but never apply:

  • :hover
  • :active
  • :focus
  • :target
  • :visited

Other limitations:

Why?

If you don't know why you'd need this, you don't need this.

(There are some content platforms that allow custom HTML but don't allow custom stylesheets, despite requiring styling to be viable. This is to make life easier for content creators on those platforms.)

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

inline_css-0.1.0.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

inline_css-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file inline_css-0.1.0.tar.gz.

File metadata

  • Download URL: inline_css-0.1.0.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for inline_css-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aca296fd032e0dd70fb5dcc607a8dfeab1991fade71a8d17e56f8c909dc57e6f
MD5 c1896ad615b9d8c67ec96cb2ee4f3a29
BLAKE2b-256 df8d54f63bc6e400453653d7a7b28c16dbe3dc44c0d64e57ddd0b62216ff6665

See more details on using hashes here.

File details

Details for the file inline_css-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: inline_css-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for inline_css-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73c76f9459e0f1f39882b054b4cabf234a90c793858aa83071b6373f40817d70
MD5 84e778b99031fd2337c3424aa6479510
BLAKE2b-256 79fff2fcf3a431ff6d05fc54dce5e96c4fd1e79fc21324de7c67b01b731c7b0d

See more details on using hashes here.

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