Tailwindcss Inline CSS
npm install tw-to-cssTransform Tailwind classes to pure CSS using our plug-and-play package, compatible with both CSR and SSR. The package also includes the option to convert the output to JSON for use with React or other tools.
Here's a list of advantages of using the package:
- ✅ Simplifies integration of Tailwind CSS into projects
- ✅ Compatible with both Client-side and Server-side Rendering
- ✅ Plug-and-play, no configuration necessary
- ✅ Option to convert output to JSON for use with React or other tools
- ✅ Improves performance by eliminating runtime processing
- ✅ Reduces project size and build time
- ✅ Maintains the readability and maintainability of the Tailwind CSS codebase
#### NPM module
``sh npm`
npm install tw-to-css -E
`sh yarn`
yarn add tw-to-css -E
#### CDN
`html`
`typescript
import { twi, twj } from "tw-to-css";
// Convert classes to inline CSS
const styleInline = twi(bg-white mx-auto);
// Output: margin-left:auto;margin-right:auto;background-color:rgb(255, 255, 255);
// Convert classes to JSON
const styleJSON = twj(bg-white mx-auto);`
// Output: {marginLeft: 'auto', marginRight: 'auto', backgroundColor: 'rgb(255, 255, 255)'}
- Template Literal
`typescriptbg-blue-700 ${false && "rounded"}
twi;`
- Objects
`typescript`
twi({ "bg-blue-700": true, rounded: false, underline: isTrue() });
- Arrays
`typescript`
twi([["bg-blue-700"], ["text-white", "rounded"], [["underline"]]]);
- String
`typescript`
twi("bg-blue-700 text-white");
#### Options:
| Option | Type | Default | Result |
| ------ | ------- | ------- | ------------------------------------------------------------- |
| minify | boolean | true | Compresses the CSS code |
| merge | boolean | true | Combines all generated CSS classes into a single style block. |
#### Example:
`typescript`
twi("bg-white mx-auto", { minify: false, merge: false });
/*
Output:
.mx-auto {
margin-left: auto;
margin-right: auto
}
.bg-white {
background-color: rgb(255, 255, 255)
}
*/
`typescript
import { tailwindToCSS } from "tw-to-css";
const { twi, twj } = tailwindToCSS({
config: {
theme: {
extend: {
colors: {
"custom-color": "#ff0000",
},
},
},
},
});
`
`tsx
import * as React from "react";
import { twj } from "tw-to-css";
export default function EmailTemplate() {
return (
Transform Tailwind classes to pure CSS
/*
Output:
Transform Tailwind classes to pure CSS