JSS is a more powerful abstraction over CSS. It uses JavaScript as a language to describe styles in a declarative and maintainable way. It is a high performance JS to CSS compiler which works at runtime and server-side. This core library is low level and framework agnostic. It is about 6KB (minified and gzipped) and is extensible via plugins API.
Feel free to ask any JSS related questions on Twitter by using hashtag #cssinjs
and mentioning @oleg008, watch my latest talk about "Unique Value Proposition of CSSinJS" and try it on a playground.
If you are a Sass (SCSS) user, this course will show how to express popular Sass language features using the latest JavaScript features: Convert SCSS (Sass) to CSS-in-JS.
- Framework agnostic
- Scoped selectors by default
- Function values and rules
- Observables
- SSR
- Plugins support
- Global CSS
- Expanded syntax
- Composition syntax
- Template strings syntax
- Isolation
- React-JSS - HOC interface for React with theming, try it on playground.
- Styled-JSS - styled components interface for React, try it on playground.
- Glamor-JSS - glamor flavored CSS with JSS under the hood.
- Aphrodite-JSS - aphrodite like API.
- Live examples
- Benefits
- Setup
- Core JSS Syntax
- JavaScript API
- Server-side rendering
- Performance
- Plugins API
- All related projects
- CLI Converter
- Contributing
Try it out on playground.
You need to setup plugins first.
You can use a preset for a quick setup with default plugins, or try jss-starter-kit
for easy experimentation.
import jss from 'jss'
import preset from 'jss-preset-default'
import color from 'color'
// One time setup with default plugins and settings.
jss.setup(preset())
const styles = {
button: {
fontSize: 12,
'&:hover': {
background: 'blue'
}
},
ctaButton: {
extend: 'button',
'&:hover': {
background: color('blue')
.darken(0.3)
.hex()
}
},
'@media (min-width: 1024px)': {
button: {
width: 200
}
}
}
const {classes} = jss.createStyleSheet(styles).attach()
document.body.innerHTML = `
<button class="${classes.button}">Button</button>
<button class="${classes.ctaButton}">CTA Button</button>
`
Result
<head>
<style>
.button-0 {
font-size: 12px;
}
.button-0:hover {
background: blue;
}
.ctaButton-1 {
font-size: 12px;
}
.ctaButton-1:hover {
background: red;
}
@media (min-width: 1024px) {
.button-0 {
min-width: 200px;
}
}
</style>
</head>
<body>
<button class="button-0">Button</button>
<button class="ctaButton-1">CTA Button</button>
</body>
- You build a JavaScript-heavy application.
- You use components based architecture.
- You build a reusable UI library.
- You need a collision-free CSS (external content, third-party UI components ...).
- You need code sharing between JS and CSS.
- Minimal download size is important to you.
- Robustness and code reuse is essential to you.
- Ease of maintenance is critical to you.
- You want to use any of its benefits
We don't have a strict roadmap. We work on issues depending on personal priorities. If you are looking to help, important issues are tagged.
We have automated tests running in real browsers.
MIT
Thanks to BrowserStack for providing the infrastructure that allows us to run our tests in real browsers and to all awesome contributors.
Support us with a monthly donation and help us continue our activities. [Become a backer]
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]