{"id":21448966,"url":"https://github.com/stackcss/inline-critical-css","last_synced_at":"2025-07-14T20:31:29.418Z","repository":{"id":57274138,"uuid":"96682704","full_name":"stackcss/inline-critical-css","owner":"stackcss","description":"Inline critical CSS in HTML","archived":false,"fork":false,"pushed_at":"2020-08-06T17:54:30.000Z","size":39,"stargazers_count":28,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T10:47:56.180Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/stackcss.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}},"created_at":"2017-07-09T12:25:07.000Z","updated_at":"2023-02-04T02:27:34.000Z","dependencies_parsed_at":"2022-09-17T10:10:44.357Z","dependency_job_id":null,"html_url":"https://github.com/stackcss/inline-critical-css","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/stackcss/inline-critical-css","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackcss%2Finline-critical-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackcss%2Finline-critical-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackcss%2Finline-critical-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackcss%2Finline-critical-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackcss","download_url":"https://codeload.github.com/stackcss/inline-critical-css/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackcss%2Finline-critical-css/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265344830,"owners_count":23750566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-23T03:17:41.694Z","updated_at":"2025-07-14T20:31:29.151Z","avatar_url":"https://github.com/stackcss.png","language":"JavaScript","readme":"# inline-critical-css [![stability][0]][1]\n[![npm version][2]][3] [![build status][4]][5]\n[![downloads][8]][9] [![js-standard-style][10]][11]\n\nStream that inlines critical CSS in HTML. Looks at the used CSS on a page and\nonly inlines the CSS that's used.\n\n## Usage\n```js\nvar inline = require('inline-critical-css')\nvar pump = require('pump')\n\nvar css = `\n  .red { color: red }\n`\n\nvar html = `\n  \u003chtml\u003e\n    \u003chead\u003e\u003c/head\u003e\n    \u003cbody class=\"red\"\u003eHello world\u003c/body\u003e\n  \u003c/html\u003e\n`\n\nvar stream = inline(css)\npump(stream, process.stdout)\nstream.end(html)\n```\n\n## FAQ\n### Why is this is a stream?\n[hyperstream](https://github.com/substack/hyperstream) makes it easy to chain\nHTML transforms together. I was too lazy to write my own parser + selector so\nhence it being a stream. Also I use streams for this stuff anyway so it would\nmake a lot of sense to keep it as a stream.\n\n### Why does it inline _all_ CSS used on a page?\nIdeally we'd only inline the \"above the fold\" CSS, but that requires knowing\nwhich tokens are \"above the fold\". This would require looking at a specific\nviewport, and checking which tokens are used (e.g. headless chrome or similar).\nWe opted for a slightly simpler option, which hopefully works out well enough\nfor most cases.\n\n### Why doesn't it inline my fancy selectors?\nInlining fancy selectors (e.g. `.foo:not(:first-child)`) is really hard to\ndetermine statically if it's used. The best way to do so would be to launch a\nheadless chrome instance - but that requires a fair amount of compute\nresources. So we don't. If you want that behavior, we recommend writing a\nheadless chrome module specifically for that (and let us know, we'd be\ninterested in that!)\n\n## API\n### `transformStream = inline(css)`\nCreate a transform stream that inlines critical CSS in HTML.\n\n## See Also\n- [substack/hyperstream](https://github.com/substack/hyperstream)\n- [stackcss/extract-html-class](https://github.com/stackcss/extract-html-class)\n\n## License\n[MIT](https://tldrlegal.com/license/mit-license)\n\n[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square\n[1]: https://nodejs.org/api/documentation.html#documentation_stability_index\n[2]: https://img.shields.io/npm/v/inline-critical-css.svg?style=flat-square\n[3]: https://npmjs.org/package/inline-critical-css\n[4]: https://img.shields.io/travis/stackcss/inline-critical-css/master.svg?style=flat-square\n[5]: https://travis-ci.org/stackcss/inline-critical-css\n[6]: https://img.shields.io/codecov/c/github/stackcss/inline-critical-css/master.svg?style=flat-square\n[7]: https://codecov.io/github/stackcss/inline-critical-css\n[8]: http://img.shields.io/npm/dm/inline-critical-css.svg?style=flat-square\n[9]: https://npmjs.org/package/inline-critical-css\n[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square\n[11]: https://github.com/feross/standard\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackcss%2Finline-critical-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackcss%2Finline-critical-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackcss%2Finline-critical-css/lists"}