{"id":50111387,"url":"https://github.com/npow/cssbox","last_synced_at":"2026-05-23T12:32:21.671Z","repository":{"id":343321474,"uuid":"1156713000","full_name":"npow/cssbox","owner":"npow","description":"Fast embeddable Rust CSS layout engine for document rendering without a browser.","archived":false,"fork":false,"pushed_at":"2026-03-09T20:38:30.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-10T01:49:41.083Z","etag":null,"topics":["css","css-layout","flexbox","grid","html","layout","layout-engine","no-std","pdf","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-13T00:53:35.000Z","updated_at":"2026-03-09T20:38:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/npow/cssbox","commit_stats":null,"previous_names":["npow/cssbox"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/npow/cssbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npow%2Fcssbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npow%2Fcssbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npow%2Fcssbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npow%2Fcssbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npow","download_url":"https://codeload.github.com/npow/cssbox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npow%2Fcssbox/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33396574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","css-layout","flexbox","grid","html","layout","layout-engine","no-std","pdf","rust"],"created_at":"2026-05-23T12:32:19.553Z","updated_at":"2026-05-23T12:32:21.665Z","avatar_url":"https://github.com/npow.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cssbox\n\n[![CI](https://github.com/npow/cssbox/actions/workflows/ci.yml/badge.svg)](https://github.com/npow/cssbox/actions/workflows/ci.yml)\n[![Crates.io](https://img.shields.io/crates/v/cssbox-core.svg)](https://crates.io/crates/cssbox-core)\n[![docs.rs](https://img.shields.io/docsrs/cssbox-core)](https://docs.rs/cssbox-core)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Docs](https://img.shields.io/badge/docs-mintlify-18a34a?style=flat-square)](https://mintlify.com/npow/cssbox)\n\nA standalone CSS layout engine in Rust. HTML/CSS in, exact coordinates out.\n\nBuilt for PDF generation, document rendering, native UI, and anywhere you need CSS layout without a browser.\n\n---\n\n## The Problem\n\nIf you need to lay out a document with CSS — generate a PDF from HTML, render rich text in a native app, build an e-book reader — your options are:\n\n- **Headless Chrome/Puppeteer** — works, but it's a 200MB dependency that spawns a browser process\n- **WeasyPrint** — Python-only, slow, flexbox/grid support is [incomplete](https://doc.courtbouillon.org/weasyprint/stable/)\n- **Prince XML** — proprietary, expensive\n- **wkhtmltopdf** — deprecated and unmaintained\n\nLibraries like [Yoga](https://github.com/facebook/yoga) and [Taffy](https://github.com/DioxusLabs/taffy) are great for app-style UI (flexbox/grid), but they don't handle document-style layout — inline text flow, floats, tables, or the CSS cascade. They solve a different problem.\n\ncssbox fills the gap: a fast, embeddable Rust library that handles the full CSS layout spec, from modern flexbox/grid to traditional document flow.\n\n## Getting Started\n\n```toml\n[dependencies]\ncssbox-core = \"0.1\"\n```\n\n```rust\nuse cssbox_core::tree::BoxTreeBuilder;\nuse cssbox_core::style::ComputedStyle;\nuse cssbox_core::geometry::Size;\nuse cssbox_core::layout::{compute_layout, FixedWidthTextMeasure};\nuse cssbox_core::values::LengthPercentageAuto;\n\n// Build a tree of styled nodes\nlet mut builder = BoxTreeBuilder::new();\nlet root = builder.root(ComputedStyle::block());\n\nlet mut child_style = ComputedStyle::block();\nchild_style.width = LengthPercentageAuto::px(200.0);\nchild_style.height = LengthPercentageAuto::px(100.0);\nlet child = builder.element(root, child_style);\n\nlet tree = builder.build();\n\n// Compute layout against an 800x600 viewport\nlet result = compute_layout(\u0026tree, \u0026FixedWidthTextMeasure, Size::new(800.0, 600.0));\n\n// Query the result — just like getBoundingClientRect()\nlet rect = result.bounding_rect(child).unwrap();\nassert_eq!(rect.width, 200.0);\nassert_eq!(rect.height, 100.0);\n```\n\n### From HTML/CSS\n\n```rust\nuse cssbox_dom::computed::html_to_box_tree;\nuse cssbox_core::geometry::Size;\nuse cssbox_core::layout::{compute_layout, FixedWidthTextMeasure};\n\nlet tree = html_to_box_tree(r#\"\n    \u003cdiv style=\"display: flex; gap: 10px\"\u003e\n        \u003cdiv style=\"flex: 1; height: 100px\"\u003e\u003c/div\u003e\n        \u003cdiv style=\"flex: 2; height: 100px\"\u003e\u003c/div\u003e\n    \u003c/div\u003e\n\"#);\n\nlet result = compute_layout(\u0026tree, \u0026FixedWidthTextMeasure, Size::new(800.0, 600.0));\n```\n\n## What It Supports\n\ncssbox implements 7 CSS layout modes — both the modern layout primitives (flexbox, grid) and the traditional document flow (block, inline, float) that document rendering requires.\n\n| Algorithm | Spec | What it covers |\n|-----------|------|----------------|\n| **Block** | CSS 2.1 \u0026sect;9.4.1 | Width/height determination, margin collapsing, `box-sizing`, min/max constraints, percentages |\n| **Inline** | CSS 2.1 \u0026sect;9.4.2 | Line box construction, greedy line breaking, `text-align`, `vertical-align`, `white-space` |\n| **Float** | CSS 2.1 \u0026sect;9.5.1 | Left/right placement, exclusion zones, `clear`, BFC containment |\n| **Positioning** | CSS 2.1 \u0026sect;9.3 | `relative`, `absolute`, `fixed`, `sticky`, constraint solving, stretch |\n| **Flexbox** | Flex Level 1 | Direction, wrapping, grow/shrink, all alignment and spacing modes |\n| **Grid** | Grid Level 2 | Track sizing (`fr`, `minmax()`, `fit-content()`), auto-placement, gap |\n| **Table** | CSS 2.1 \u0026sect;17 | Fixed and auto layout, `border-collapse`/`border-spacing`, captions |\n\n## Landscape\n\nExisting embeddable layout libraries are purpose-built for app UI (flexbox/grid) and intentionally skip document layout. Full browsers handle everything but aren't embeddable. cssbox sits in the middle.\n\n### Embeddable libraries\n\n| Engine | Language | Stars | Document layout | App layout |\n|--------|----------|------:|:---:|:---:|\n| [Yoga](https://github.com/facebook/yoga) | C++ | 18.7k | — | Flexbox |\n| [Taffy](https://github.com/DioxusLabs/taffy) | Rust | 3k | Block only | Flexbox, Grid |\n| [Dropflow](https://github.com/chearon/dropflow) | TS/Zig | 1.4k | Block, Inline, Float | — |\n| **cssbox** | **Rust** | — | **Block, Inline, Float, Table** | **Flexbox, Grid** |\n\n### Full browsers and renderers (not embeddable as libraries)\n\n| Engine | Notes |\n|--------|-------|\n| [Servo](https://github.com/servo/servo) | Rust browser engine. Uses Taffy for flex/grid. Inline/float still incomplete (18-52% WPT). |\n| [NetSurf](https://www.netsurf-browser.org/) | C browser. Strong CSS 2.1 + flexbox. No grid. |\n| [Ladybird](https://github.com/LadybirdBrowser/ladybird) | C++ browser. Pre-alpha. Targeting full CSS. |\n| [WeasyPrint](https://github.com/Kozea/WeasyPrint) | Python PDF renderer. Best document layout coverage, but flexbox/grid marked \"not deeply tested\". |\n\n## Use Cases\n\n- **PDF / document generation** — HTML/CSS to precise coordinates, then render to PDF\n- **Rich text UI** — document-style layout in native apps (editors, readers, email clients)\n- **Native UI** — CSS layout without a webview\n- **Embedded devices** — small footprint, zero runtime dependencies\n- **Testing tools** — verify CSS layout behavior programmatically\n\n## Crate Structure\n\n| Crate | Description |\n|-------|-------------|\n| [**cssbox-core**](crates/cssbox-core) | Core layout algorithms. Zero dependencies, `no_std` compatible. |\n| [**cssbox-dom**](crates/cssbox-dom) | HTML/CSS parsing, selector matching, cascade, computed values. |\n| [**cssbox-test-harness**](crates/cssbox-test-harness) | WPT test infrastructure (reftest + testharness.js). |\n\n## Text Measurement\n\ncssbox doesn't measure text — you provide the font metrics via a trait:\n\n```rust\npub trait TextMeasure {\n    fn measure(\u0026self, text: \u0026str, font_size: f32, max_width: f32) -\u003e Size;\n}\n```\n\nA built-in `FixedWidthTextMeasure` (8px/character) is included for testing. For production, plug in your font rasterizer (e.g., `rusttype`, `fontdue`, `cosmic-text`).\n\n## Testing\n\n```bash\ncargo test --workspace              # all 97 tests\ncargo test -p cssbox-core           # core layout tests\ncargo test -p cssbox-core block     # specific algorithm\ncargo test -p cssbox-core flex\ncargo test -p cssbox-core grid\n```\n\n## Contributing\n\nContributions are welcome! The biggest impact areas:\n\n1. **WPT pass rate** — pick a failing test, fix the layout algorithm\n2. **Missing CSS properties** — add parsing + layout support\n3. **Text shaping** — improve inline layout with real text measurement\n4. **Performance** — layout caching, incremental relayout\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpow%2Fcssbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpow%2Fcssbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpow%2Fcssbox/lists"}