In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
- Build time compilation to achieve awesome runtime performance and minimal size
- Next.js, React Server Components, Vite and Webpack support
- Type safety with out of the box TypeScript and ESLint plugin
- Advanced CSS variables configuration to allow smooth token usage
- Style templates to create reusable styles easily
- Initialize:
npx salty-css init [directory]
- Create component:
npx salty-css generate [filePath]
- Build:
npx salty-css build [directory]
Fastest way to get started with any framework is npx salty-css init [directory] command
- Next.js → Next.js guide + Next.js example app
- React → React guide + React example code
- Vite → Vite guide
- Webpack → Guide coming soon
- ESLint → Guide coming soon
In your existing repository you can use npx salty-css [command]
to initialize a project, generate components, update related packages and build required files.
- Initialize project →
npx salty-css init [directory]
- Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. - Generate component →
npx salty-css update [version]
- Update @salty-css packages in your repository. Default version is "latest". Additional options like--dir
,--tag
,--name
and--className
are also supported. - Build files →
npx salty-css build [directory]
- Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
In your existing Next.js repository you can run npx salty-css init
to automatically configure Salty CSS.
- For Next.js support install
npm i @salty-css/next @salty-css/core @salty-css/react
- Create
salty.config.ts
to your app directory - Add Salty CSS plugin to next.js config
- Next.js 15: In
next.config.ts
add import for salty pluginimport { withSaltyCss } from '@salty-css/next';
and then addwithSaltyCss
to wrap your nextConfig export like soexport default withSaltyCss(nextConfig);
- Next.js 14 and older: In
next.config.js
add import for salty pluginconst { withSaltyCss } = require('@salty-css/next');
and then addwithSaltyCss
to wrap your nextConfig export like somodule.exports = withSaltyCss(nextConfig);
- Make sure that
salty.config.ts
andnext.config.ts
are in the same folder! - Build
saltygen
directory by running your app once or with clinpx salty-css build [directory]
- Import global styles from
saltygen/index.css
to some global css file with@import 'insert_path_to_index_css';
.
Check out Next.js demo project or react example code
In your existing Vite repository you can run npx salty-css init
to automatically configure Salty CSS.
- For Vite support install
npm i @salty-css/vite @salty-css/core
- In
vite.config
add import for salty pluginimport { saltyPlugin } from '@salty-css/vite';
and then addsaltyPlugin(__dirname)
to your vite configuration plugins - Make sure that
salty.config.ts
andvite.config.ts
are in the same folder! - Build
saltygen
directory by running your app once or with clinpx salty-css build [directory]
- Import global styles from
saltygen/index.css
to some global css file with@import 'insert_path_to_index_css';
.
In your existing React repository you can run npx salty-css init
to automatically configure Salty CSS.
- Install related dependencies:
npm i @salty-css/core @salty-css/react
- Create
salty.config.ts
to your app directory - Configure your build tool to support Salty CSS (Vite or Webpack) or after changes run
npx salty-css build
- Create salty components with styled only inside files that end with
.css.ts
,.salty.ts
.styled.ts
or.styles.ts
Salty config
import { defineConfig } from '@salty-css/core/config';
export const config = defineConfig({
variables: {
colors: {
brand: '#111',
highlight: 'yellow',
},
},
global: {
html: {
backgroundColor: '#f8f8f8',
},
},
});
Wrapper (components/wrapper/wrapper.css.ts
)
import { styled } from '@salty-css/react/styled';
export const Wrapper = styled('div', {
base: {
display: 'block',
padding: '2vw',
},
});
Button (components/button/button.css.ts
)
import { styled } from '@salty-css/react/styled';
export const Button = styled('button', {
base: {
display: 'block',
padding: `0.6em 1.2em`,
border: '1px solid currentColor',
background: 'transparent',
color: 'currentColor',
cursor: 'pointer',
transition: '200ms',
textDecoration: 'none',
'&:hover': {
background: 'black',
borderColor: 'black',
color: 'white',
},
'&:disabled': {
opacity: 0.25,
pointerEvents: 'none',
},
},
variants: {
variant: {
outlined: {
// same as default styles
},
solid: {
'&:not(:hover)': {
background: 'black',
borderColor: 'black',
color: 'white',
},
'&:hover': {
background: 'transparent',
borderColor: 'currentColor',
color: 'currentColor',
},
},
},
},
});
Your React component file
import { Wrapper } from '../components/wrapper/wrapper.css';
import { Button } from '../components/button/button.css';
export const IndexPage = () => {
return (
<Wrapper>
<Button variant="solid" onClick={() => alert('It is a button.')}>
Outlined
</Button>
</Wrapper>
);
};
More examples coming soon