I've been working on ONCSS, a CSS-in-JS library designed to make styling modern web applications simple, flexible, and developer-friendly.
Instead of writing separate CSS files for every component, ONCSS lets you define styles directly in JavaScript using a familiar object-based API.
Why ONCSS?
ONCSS provides a css() function that generates and injects CSS dynamically.
Here's a quick example:
import css from "oncss";
const button = css({
backgroundColor: "#2563eb",
color: "#fff",
padding: "10px 20px",
borderRadius: "8px",
"&:hover": {
backgroundColor: "#1d4ed8",
},
"@media (min-width: 768px)": {
padding: "14px 28px",
},
});
function Button() {
return <button className={button}>Click me</button>;
}
Features
- Object-based CSS styling
- Nested selectors and pseudo-classes
- Responsive media queries
- Custom breakpoints
- Dynamic keyframes and animations
- Global styles
- CSS at-rules:
@media,@container,@layer,@supports - Custom aliases and CSS property transformations
- Configurable style injection
- TypeScript support
- Server-side rendering support
Installation
npm install oncss
Built for flexibility
ONCSS also supports customization through configuration options such as classPrefix, breakpoints, aliases, injectStyle, and custom property handlers.
It also provides CSSFactory for collecting generated styles during server-side rendering.
I'm building ONCSS as an open-source project and would appreciate feedback from developers who work with React and modern JavaScript styling.
Check it out:
If you try it, I'd love to hear what you think and what features you'd like to see next.
Top comments (0)