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.1.tar.gz (17.9 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.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: inline_css-0.1.1.tar.gz
  • Upload date:
  • Size: 17.9 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.1.tar.gz
Algorithm Hash digest
SHA256 13b6a07c751ff16690a376d945997dd03fefbc947d930f2c9c8ce5223924e6eb
MD5 2fb1f375b4d60bd05b409dac85f5c493
BLAKE2b-256 df1349d61d6da3ef5f1f5318c6c12c2fb60d02cd876e044ff547dfbaaa321ce2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: inline_css-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2cfc51f837e9aa2dc6680028552e9e77d30e85a4c5724ef0dbd5f246008daa2f
MD5 e7dbe228378b8e46e892ea4927362739
BLAKE2b-256 7c2c72538ab11e647cb1f73a50e90da49151887576b267ed143f6659010235c5

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