CSSified-HTML is an HTML-friendly alternative to CSS and utility frameworks like Tailwind and UnoCSS. It introduces new elements and attributes that allow you to completely eliminate the need for *.css|scss|sass|less|pcss
files in your codebase. Configure your elements directly within your markup and use new elements to define <keyframe>
s, <mixin>
s, <media>
queries, and more—all within HTML!
- 🦾 CSS Property Attributes - Every HTML element now supports attributes for all CSS properties, including support for complex selectors and media queries. Check the documentation for syntax examples.
- 🧑🎨 Enhanced
style
Attribute - Thestyle=""
attribute now includes state support (e.g.,hover:style=""
), media queries (@landscape:style=""
), and more variants. - 🎞️ New Elements -
<animation>
and<keyframe>
elements enable defining complex@keyframes
directly within your HTML. - ✒️ Automatic CDN Fonts - Effortlessly import fonts from a CDN (fonts.google.com) using
font-family:google="Roboto"
. - 🏎️ Blazing Performance - CSS generation is nearly instantaneous, averaging around 0.15ms.
- 🤏 Compact Size - Weighing in at only ~2.7kb (minified + gzip), with zero dependencies, and compatible with any browser beyond IE11.
- 🔌 Vite Plugin - Available for all frameworks, with support for SSR and no-JavaScript environments.
- 📇 Named Groups - Simplify complex UIs with named groups. Use
group="banana"
and style it withgroup-banana:hover:background-color="red"
. - 🛣️
Custom Shortcuts - Define boolean attributes for rapid prototyping and design system management(W.I.P.).
<html font-family:google="Roboto Condensed, sans-serif">
<head>
<title>Example</title>
</head>
<body margin="0" background-color="white" color="#030303" @dark:style="background-color: black; color: #fff;">
<media-query name="dark" query="prefers-color-scheme: dark" />
<animation name="example">
<keyframe frame="from" background-color="red"></keyframe>
<keyframe frame="to" background-color="green"></keyframe>
</animation>
<nav height="80px">
<div margin="0px auto" display="flex" align-items="center" justify-content="space-between" flex-direction="row" height="inherit" width="1200px">
<div color="#EE0000" font-weight="800">CSS-HTML-ATTRIBUTES</div>
<div display="flex" gap="1rem" justify-content="center" flex-direction="row" align-items="center" children:style="text-decoration: none; color: inherit;font-weight: 500;">
<a href="/">Home</a>
<a href="/documentation">Documentation</a>
<a href="/tutorial">Tutorial</a>
<a href="/examples">Components</a>
</div>
</div>
</nav>
<div animation="example 4s infinite" padding="40px">
I'm animated by a animation defined through HTML element!
</div>
</body>
</html>
/** generated css in: 0.0755ms (average of 100_000 runs) */
@import 'https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@800&display=swap';@keyframes example{from{background-color:red}to{background-color:green}}[font-family\:google]{font-family:Roboto Condensed, sans-serif}[margin]{margin:0}[background-color]{background-color:white}[color]{color:#030303}[height]{height:80px}[margin="0px auto"]{margin:0px auto}[display],[display="flex"]{display:flex}[align-items],[align-items="center"]{align-items:center}[justify-content]{justify-content:space-between}[flex-direction],[flex-direction="row"]{flex-direction:row}[height="inherit"]{height:inherit}[width]{width:1200px}[color="#EE0000"]{color:#EE0000}[font-weight]{font-weight:800}[gap]{gap:1rem}[justify-content="center"]{justify-content:center}[children\:style="text-decoration: none; color: inherit;font-weight: 500;"] > *{text-decoration: none; color: inherit;font-weight: 500;}animation{display:none}[animation]{animation:example 4s infinite}[padding]{padding:40px}@media (prefers-color-scheme: dark){[\@dark\:style]{background-color: black; color: #fff;}}
Note: css is automatically minimized, including selector specificness but not values.
🧪 CSSified-HTML is still in active development. Though the generator is usable and stable, our vite plugin is not. We do not recommend using it in production as major refactors are on its way to the codebase, which will introduce breaking changes to your project.
If you want to use the css generator programatically, you can import generator from '@CSSified-HTML/core'
. Using the generator you can generate css for any html, like so: generator('<div background-color="orange"></div>')
.
We do not (yet) have a recommended CDN.
Our vite plugin is not yet finished, but there is an experimental one available.
To get started...
- Install the vite plugin with your package manager of choice:
npm install @CSSified-HTML/vite --save-dev
yarn add @CSSified-HTML/vite --save-dev
pnpm install @CSSified-HTML/vite --save-dev
- Add the plugin to your
vite.config.js
:
// vite.config.ts
import CSSifiedHTML from '@CSSified-HTML/vite'
export default {
plugins: [
CSSifiedHTML(),
]
}
- Import the virtually generated css file in your entry point (main.js) or primary layout component (+layout.svelte, layout.vue, layout.blade.php, etc)
// main.js
import 'CSSified-HTML.css'
<!-- component -->
<script>
import 'CSSified-HTML.css'
</script>
We do not yet have a website. For now you can read the not-so-in-depth instructions below. If you have any questions, feel free to raise an issue.
For every CSS property there is now a attribute that you can add to any html element. The name of the attributes are the same as their corosponding CSS properties.
Here are some basic examples:
display: flex
-><div display="flex"></div>
transform: scale(0.5)
-><div transform="scale(0.5)"></div>
background: #F0F0F0
-><div background="#F0F0F0"></div>
overflow: scroll
-><div overflow="scroll"></div>
If you want a property to only apply on :hover
you can just prefix the attribute with hover:
, like so:
div:hover { transform: scale(0.5) }
-><div hover:transform="scale(0.5)"></div>
div:hover { background: #F0F0F0 }
-><div hover:background="#F0F0F0"></div>
Only want to apply a property on smaller screens, when printing the page and/or when dark theme is active? Simply prefix the attribute with the appropriate media-query-prefix.
@media only print { display: flex }
-><div @print:display="flex"></div>
@media (prefers-color-scheme: dark) { transform: scale(0.5) }
-><div @dark:transform="scale(0.5)"></div>
@media (prefers-color-scheme: light) { background: #F0F0F0 }
-><div @light:background="#F0F0F0"></div>
@media (orientation: portrait) { overflow: scroll }
-><div @portrait:overflow="scroll"></div>
You can also stack media-query-prefixes like so:
<div @portrait:@dark:@print:background="inherit"></div>
We have also added some shortcuts to make your life easier.
Allows you to write <div color:var="theme"></div>
instead of <div color="var(--theme)"></div>
Allows you to write <div background:url="./background.svg"></div>
instead of <div background="url('./background.svg')"></div>
Any other suffix you place behind a property will wrap the attribute value to $1(<value>)
.
Examples:
<div width:calc="10px + 20px">
->width: calc(10px + 20px)
<div width:banana="10px + 20px">
->width: banana(10px + 20px)
// This does not work, but this is expected behavior. We wrap everything!
The following options are available on the Vite plugin:
TODO: write docs
in alphabetical order, based on UnoCSS's "Acknowledgement" list.
- ACSS
- Bootstrap Utilities
- Chakra UI Style Props
- Semantic UI
- Tachyons
- Tailwind CSS
- Twind
- UnoCSS
- Windi CSS
MIT License © 2022 Jack van der Bilt