Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
@vanilla-extract/css
Advanced tools
Zero-runtime Stylesheets-in-TypeScript
@vanilla-extract/css is a zero-runtime CSS-in-TypeScript library. It allows you to write type-safe, themeable, and modular CSS using TypeScript. The library compiles your styles to static CSS at build time, ensuring no runtime overhead.
Creating Styles
This feature allows you to create CSS styles using TypeScript. The `style` function is used to define a class with various CSS properties.
import { style } from '@vanilla-extract/css';
const buttonStyle = style({
backgroundColor: 'blue',
color: 'white',
padding: '10px 20px',
borderRadius: '5px',
':hover': {
backgroundColor: 'darkblue'
}
});
Theming
Theming allows you to create and use design tokens in your styles. The `createTheme` function generates a theme class and variables that can be used in your styles.
import { createTheme, style } from '@vanilla-extract/css';
const [themeClass, vars] = createTheme({
color: {
primary: 'blue',
secondary: 'green'
},
font: {
body: 'Arial, sans-serif'
}
});
const themedStyle = style({
backgroundColor: vars.color.primary,
color: vars.color.secondary,
fontFamily: vars.font.body
});
Composition
Composition allows you to combine multiple styles into one. The `composeStyles` function is used to merge multiple style classes into a single class.
import { style, composeStyles } from '@vanilla-extract/css';
const baseStyle = style({
padding: '10px',
borderRadius: '5px'
});
const primaryButton = style({
backgroundColor: 'blue',
color: 'white'
});
const composedStyle = composeStyles(baseStyle, primaryButton);
styled-components is a popular library for writing CSS-in-JS. It allows you to use ES6 and CSS to style your components. Unlike @vanilla-extract/css, styled-components has a runtime dependency and supports dynamic styling.
Emotion is a performant and flexible CSS-in-JS library. It provides both a styled API similar to styled-components and a low-level CSS API. Emotion also has runtime dependencies but offers more flexibility in terms of styling approaches.
Linaria is a zero-runtime CSS-in-JS library similar to @vanilla-extract/css. It allows you to write CSS in JavaScript and extracts it to static CSS files at build time. Linaria focuses on performance and type safety, much like @vanilla-extract/css.
Zero-runtime Stylesheets-in-TypeScript.
Write your styles in TypeScript (or JavaScript) with locally scoped class names and CSS Variables, then generate static CSS files at build time.
Basically, it’s “CSS Modules-in-TypeScript” but with scoped CSS Variables + heaps more.
🔥 All styles generated at build time — just like Sass, Less, etc.
✨ Minimal abstraction over standard CSS.
🦄 Works with any front-end framework — or even without one.
🌳 Locally scoped class names — just like CSS Modules.
🚀 Locally scoped CSS Variables, @keyframes
and @font-face
rules.
🎨 High-level theme system with support for simultaneous themes. No globals!
🛠 Utils for generating variable-based calc
expressions.
💪 Type-safe styles via CSSType.
🏃♂️ Optional runtime version for development and testing.
🙈 Optional API for dynamic runtime theming.
🌐 Check out the documentation site for setup guides, examples and API docs.
🖥 Try it out for yourself in CodeSandbox.
Write your styles in .css.ts
files.
// styles.css.ts
import { createTheme, style } from '@vanilla-extract/css';
export const [themeClass, vars] = createTheme({
color: {
brand: 'blue'
},
font: {
body: 'arial'
}
});
export const exampleStyle = style({
backgroundColor: vars.color.brand,
fontFamily: vars.font.body,
color: 'white',
padding: 10
});
💡 Once you've configured your build tooling, these
.css.ts
files will be evaluated at build time. None of the code in these files will be included in your final bundle. Think of it as using TypeScript as your preprocessor instead of Sass, Less, etc.
Then consume them in your markup.
// app.ts
import { themeClass, exampleStyle } from './styles.css.ts';
document.write(`
<section class="${themeClass}">
<h1 class="${exampleStyle}">Hello world!</h1>
</section>
`);
Want to work at a higher level while maximising style re-use? Check out 🍨 Sprinkles, our official zero-runtime atomic CSS framework, built on top of vanilla-extract.
MIT.
FAQs
Zero-runtime Stylesheets-in-TypeScript
The npm package @vanilla-extract/css receives a total of 754,984 weekly downloads. As such, @vanilla-extract/css popularity was classified as popular.
We found that @vanilla-extract/css demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.