css-inline
Version, currently main branch1 version
- main branchlatestFeb 6, 2026
github.com/osbre/css-inline
Crystal bindings to high-performance library for inlining CSS into HTML 'style' attributes.
Installation
# Add this to your shard.yml
dependencies:
css-inline:
github: osbre/css-inline
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.19.1- License
- MIT
- Author
- Ostap Brehin
Dependencies
This version declares no dependencies.
README
css-inline
Crystal bindings for css-inline — a high-performance library for inlining CSS into HTML. Perfect for preparing HTML emails or embedding HTML into third-party web pages.
Prerequisites
- Rust toolchain (the C library is compiled from source during installation)
Installation
Add the dependency to your shard.yml:
dependencies:
css-inline:
github: osbre/css-inline
Run shards install — this will automatically build the native library.
Usage
require "css-inline"
# Inline CSS from <style> tags
html = "<html><head><style>h1 { color: blue; }</style></head><body><h1>Hello</h1></body></html>"
result = CssInline.inline(html)
# => <html><head></head><body><h1 style="color: blue;">Hello</h1></body></html>
# Inline a CSS fragment
result = CssInline.inline_fragment("<h1>Hello</h1>", "h1 { color: blue; }")
# => <h1 style="color: blue;">Hello</h1>
Options
inliner = CssInline::CSSInliner.new(
keep_style_tags: true,
extra_css: "h1 { font-size: 2em; }",
minify_css: true,
)
result = inliner.inline(html)
All available options:
| Option | Default | Description |
|---|---|---|
inline_style_tags | true | Inline CSS from <style> tags |
keep_style_tags | false | Keep <style> tags after inlining |
keep_link_tags | false | Keep <link> tags after inlining |
keep_at_rules | false | Keep @media and other at-rules |
load_remote_stylesheets | true | Fetch and inline remote stylesheets |
minify_css | false | Minify the inlined CSS |
remove_inlined_selectors | false | Remove selectors that were inlined |
apply_width_attributes | false | Set width HTML attributes from CSS |
apply_height_attributes | false | Set height HTML attributes from CSS |
base_url | nil | Base URL for resolving relative URLs |
extra_css | nil | Additional CSS to inline |
cache | nil | Stylesheet cache (see below) |
Stylesheet Cache
Reuse parsed stylesheets across multiple calls:
cache = CssInline::StylesheetCache.new(size: 64)
inliner = CssInline::CSSInliner.new(cache: cache)
inliner.inline(html1)
inliner.inline(html2) # reuses cached stylesheets
Contributing
- Fork it (https://github.com/osbre/css-inline/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Ostap Brehin - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Feb 6, 2026
- Crystal
>= 1.19.1- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/osbre/css-inline
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 1