Traditionally, whenever you need to style something on the web, you write CSS in a dedicated file and apply the rules using classes in your HTML, like that:
```html
react
has just been released, did you know it?
It is a JavaScript library for creating user interfaces.
```
However styling this way is pretty boring because you need to think about good class names and to repeatedly switch between several files, it could be better. Utility-first CSS frameworks takes a new approach by using minimal and pre-defined class names directly linked to its CSS rule content. The CSS file will then be generated on-demand allowing the classes to be very flexible and customizable. This approach lets you quickly prototype visual HTML elements and encourages you to turn them into components using your favorite web framework. It also makes building a responsive website easier and forces it to be closer to your design system (if you have one):
```html
react
has just been released, did you know it?
It is a JavaScript library for creating user interfaces.
```
There is already a lot of utility-first frameworks like Tailwind
CSS, Windi CSS, Twind
and Uno CSS, but encre-css
is unique because it is written in Rust and
uses a new architecture, making it the fastest utility-first framework (according to the
benchmark here based on
Uno CSS' benchmark).
Add encre-css
to your Cargo.toml
:
toml
[dependencies]
encre-css = "0.10.0"
Generating styles takes two steps:
- You need to configure the CSS generation by making a Config
structure.
It can be created by reading a TOML file using
Config::from_file
or by using the default values with Config::default
;
- Then, you need to generate the styles based on some sources using the generate
function. This function will scan the content of the sources, extract atomic classes and
generate the style needed for each class.
```rust use encre_css::Config;
let config = Config::default(); let css = encre_css::generate( [r#"
Hello world!
"#], &config, );assert!(css.expect("failed to generate the CSS").ends_with(r#" .w-auto { width: auto; }
.rounded-md { border-radius: 0.375rem; }
.bg-red-200 { --en-bg-opacity: 1; background-color: rgb(254 202 202 / var(--en-bg-opacity)); }"#)); ```
A command line interface is also available. Install it using:
bash
cargo install encre-css-cli
Then run encrecss --help
for instructions on how to use it.
encre-css
was built with modularity in mind and it is possible to write or use
custom plugins. Learn more
encre
means ink
in French.
encre-css
is published under the MIT license.