{"id":19653031,"url":"https://github.com/csstools/postcss-write-svg","last_synced_at":"2025-08-31T20:31:13.599Z","repository":{"id":57328675,"uuid":"42337100","full_name":"csstools/postcss-write-svg","owner":"csstools","description":"Write SVGs directly in CSS","archived":false,"fork":false,"pushed_at":"2020-10-01T04:49:43.000Z","size":84,"stargazers_count":758,"open_issues_count":4,"forks_count":27,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-12-22T23:54:40.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jonathantneal.github.io/postcss-write-svg/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csstools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-11T23:38:44.000Z","updated_at":"2024-11-19T00:03:22.000Z","dependencies_parsed_at":"2022-09-12T09:50:48.628Z","dependency_job_id":null,"html_url":"https://github.com/csstools/postcss-write-svg","commit_stats":null,"previous_names":["jonathantneal/postcss-write-svg"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-write-svg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-write-svg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-write-svg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fpostcss-write-svg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csstools","download_url":"https://codeload.github.com/csstools/postcss-write-svg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231622014,"owners_count":18401829,"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-11T15:12:58.022Z","updated_at":"2024-12-28T12:12:10.043Z","avatar_url":"https://github.com/csstools.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Write SVG \u003ca href=\"https://github.com/postcss/postcss\"\u003e\u003cimg src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\"\u003e\u003c/a\u003e\n\n[![NPM Version][npm-img]][npm-url]\n[![Build Status][cli-img]][cli-url]\n[![Licensing][lic-image]][lic-url]\n[![Changelog][log-image]][log-url]\n[![Gitter Chat][git-image]][git-url]\n\n[Write SVG] lets you write SVGs directly in CSS.\n\n```css\n/* before */\n\n@svg square {\n\t@rect {\n\t\tfill: var(--color, black);\n\t\twidth: var(--size);\n\t\theight: var(--size);\n\t}\n}\n\n.example {\n\tbackground: svg(square param(--color green) param(--size 100%)) center / cover;\n}\n\n/* after */\n\n.example {\n\tbackground: url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Crect fill='green' width='100%25' height='100%25'/%3E%3C/svg%3E\") center / cover;\n}\n```\n\n`@svg` at-rules generate SVG elements available to CSS. Within an `@svg`, descendant at-rules (like `@rect`) are interpreted as elements, while declarations (like `width`) are interpreted as attributes.\n\nThe `svg()` function renders an `@svg` as a data `url()`. `var()` functions within an `@svg` honor the variables passed in through `param()` functions.\n\n## Options\n\n#### `utf8`\n\nType: `Boolean`  \nDefault: `true`\n\nAllows you to define whether UTF-8 or base64 encoding will be used.\n\n```css\n/* before { utf8: false } */\n\n@svg square {\n\t@rect {\n\t\tfill: black;\n\t\twidth: 100%;\n\t\theight: 100%;\n\t}\n}\n\n.example {\n\tbackground: svg(square);\n}\n\n/* after */\n\n.example {\n\tbackground: url(\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IGZpbGw9ImJsYWNrIiB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIi8+PC9zdmc+\");\n}\n```\n\n## Usage\n\nAdd [Write SVG] to your build tool:\n\n```bash\nnpm install jonathantneal/postcss-write-svg --save-dev\n```\n\n#### Node\n\n```js\nrequire('postcss-write-svg').process(YOUR_CSS, { /* options */ });\n```\n\n#### PostCSS\n\nAdd [PostCSS] to your build tool:\n\n```bash\nnpm install postcss --save-dev\n```\n\nLoad [Write SVG] as a PostCSS plugin:\n\n```js\npostcss([\n\trequire('postcss-write-svg')({ /* options */ })\n]).process(YOUR_CSS, /* options */);\n```\n\n#### Gulp\n\nAdd [Gulp PostCSS] to your build tool:\n\n```bash\nnpm install gulp-postcss --save-dev\n```\n\nEnable [Write SVG] within your Gulpfile:\n\n```js\nvar postcss = require('gulp-postcss');\n\ngulp.task('css', function () {\n\treturn gulp.src('./src/*.css').pipe(\n\t\tpostcss([\n\t\t\trequire('postcss-write-svg')({ /* options */ })\n\t\t])\n\t).pipe(\n\t\tgulp.dest('.')\n\t);\n});\n```\n\n#### Grunt\n\nAdd [Grunt PostCSS] to your build tool:\n\n```bash\nnpm install grunt-postcss --save-dev\n```\n\nEnable [Write SVG] within your Gruntfile:\n\n```js\ngrunt.loadNpmTasks('grunt-postcss');\n\ngrunt.initConfig({\n\tpostcss: {\n\t\toptions: {\n\t\t\tuse: [\n\t\t\t\trequire('postcss-write-svg')({ /* options */ })\n\t\t\t]\n\t\t},\n\t\tdist: {\n\t\t\tsrc: '*.css'\n\t\t}\n\t}\n});\n```\n\n[npm-url]: https://www.npmjs.com/package/postcss-write-svg\n[npm-img]: https://img.shields.io/npm/v/postcss-write-svg.svg\n[cli-url]: https://travis-ci.org/jonathantneal/postcss-write-svg\n[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-write-svg.svg\n[lic-url]: LICENSE.md\n[lic-image]: https://img.shields.io/npm/l/postcss-write-svg.svg\n[log-url]: CHANGELOG.md\n[log-image]: https://img.shields.io/badge/changelog-md-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[git-image]: https://img.shields.io/badge/chat-gitter-blue.svg\n\n[Write SVG]: https://github.com/jonathantneal/postcss-write-svg\n[PostCSS]: https://github.com/postcss/postcss\n[Gulp PostCSS]: https://github.com/postcss/gulp-postcss\n[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-write-svg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsstools%2Fpostcss-write-svg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fpostcss-write-svg/lists"}