Gathering detailed insights and metrics for free-style
Gathering detailed insights and metrics for free-style
Gathering detailed insights and metrics for free-style
Gathering detailed insights and metrics for free-style
style-it
Component for writing plaintext CSS in React apps -- isomorphic, scoped, FOUC-free, fully featured, CSS-in-JS
react-free-style
Make React components easier and more maintainable by using JavaScript with Free Style
@fe-free/style-lint
css-free-style
Just simple utils for css :)
npm install free-style
Typescript
Module System
Node Version
NPM Version
ES2015 Set and Map
Updated on Jan 18, 2024
ESM only
Updated on Jan 18, 2024
Allow null and undefined in `PropertyValue`
Updated on Jan 24, 2021
Remove `register*` Methods
Updated on May 02, 2020
Fix Nested Selector Hashing
Updated on Apr 29, 2020
Remove \0 From Strings
Updated on Apr 25, 2020
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
707 Stars
284 Commits
28 Forks
13 Watchers
5 Branches
11 Contributors
Updated on Jul 09, 2025
Latest Version
5.0.1
Package Id
free-style@5.0.1
Unpacked Size
46.22 kB
Size
11.97 kB
File Count
6
NPM Version
10.2.0
Node Version
21.0.0
Published on
Jan 18, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Free-Style is designed to make CSS easier and more maintainable by using JavaScript.
npm install free-style --save
There's a great presentation by Christopher Chedeau you should check out.
.button
? Why is it conflicting?)<script />
).class-name
in your styles)ul > li > a
){ '&:hover': { ... } }
)@
-rule styles ({ '@media (min-width: 500px)': { ... } }
){ backgroundColor: ['red', 'linear-gradient(to right, red 0%, blue 100%)'] }
)Free-Style generates a hash from the style to use as the class name. This allows duplicate styles to automatically be merged on duplicate hashes. Every style is "registered" and assigned to a variable, which gets the most out of linters that will warn on unused variables and features like dead code minification. Styles should usually be created outside of the application run loop (e.g. render()
) so the CSS string and hashes are only generated once.
typestyle
- Popular type-safe interface for working with CSSreact-free-style
- React implementation that renders styles on the current page (for universal apps)stylin
- Simplest abstraction for creating styles, rules, and keyframes, and keeps <style />
in syncethcss
- Library for writing CSS with literal objects1import { create } from "free-style"; 2 3// Create a stylesheet instance. 4const sheet = create(); 5 6// Register a new style, returning a class name to use. 7const backgroundStyle = sheet.registerStyle({ 8 backgroundColor: "red", 9}); //=> "f14svl5e" 10 11// Inject `<style>` into the `<head>`. 12const styleElement = document.createElement("style"); 13styleElement.textContent = sheet.getStyles(); 14document.head.appendChild(styleElement); 15 16// Render the style by using the class name. 17React.render( 18 <div className={backgroundStyle}>Hello world!</div>, 19 document.body, 20);
1const buttonStyle = sheet.registerStyle({ 2 $displayName: "button", 3 backgroundColor: "red", 4 padding: 10, 5}); 6 7console.log(buttonStyle); //=> "button_f65pi0b"
Tip: The string returned by registerStyle
is a unique hash of the content and used as the HTML class name. The $displayName
is only used during development, and stripped in production (process.env.NODE_ENV === 'production'
).
1Style.registerStyle({ 2 background: [ 3 "red", 4 "-moz-linear-gradient(left, red 0%, blue 100%)", 5 "-webkit-linear-gradient(left, red 0%, blue 100%)", 6 "-o-linear-gradient(left, red 0%, blue 100%)", 7 "-ms-linear-gradient(left, red 0%, blue 100%)", 8 "linear-gradient(to right, red 0%, blue 100%)", 9 ], 10}); //=> "f1n85iiq"
1Style.registerStyle({ 2 color: "red", 3 "@media (min-width: 500px)": { 4 //=> "@media (min-width: 500px){.fk9tfor{color:blue}}" 5 color: "blue", 6 }, 7}); //=> "fk9tfor"
1Style.registerStyle({ 2 color: "red", 3 ".classy": { 4 //=> ".fc1zv17 .classy" 5 color: "blue", 6 }, 7}); //=> "fc1zv17"
1Style.registerStyle({ 2 color: "red", 3 "&:hover": { 4 //=> ".f1h42yg6:hover" 5 color: "blue", 6 }, 7}); //=> "f1h42yg6"
Tip: The ampersand (&
) will be replaced by the parent selector at runtime.
1const ellipsisStyle = { 2 whiteSpace: "nowrap", 3 overflow: "hidden", 4 textOverflow: "ellipsis", 5}; 6 7const redEllipsisStyle = Style.registerStyle({ 8 color: "red", 9 ...ellipsisStyle, 10}); //=> "fvxl8qs" 11 12// Share rule between styles using computed properties. 13const mediaQuery = "@media (min-width: 400px)"; 14 15const style = Style.registerStyle({ 16 backgroundColor: "red", 17 [mediaQuery]: { 18 backgroundColor: "pink", 19 }, 20});
Sometimes you need to skip the de-duping behavior of free-style
. Use $unique
to force separate styles:
1Style.registerStyle({ 2 color: "blue", 3 "&::-webkit-input-placeholder": { 4 color: `rgba(0, 0, 0, 0)`, 5 $unique: true, 6 }, 7 "&::-moz-placeholder": { 8 color: `rgba(0, 0, 0, 0)`, 9 $unique: true, 10 }, 11 "&::-ms-input-placeholder": { 12 color: `rgba(0, 0, 0, 0)`, 13 $unique: true, 14 }, 15}); //=> "f13byakl" 16 17Style.getStyles(); //=> ".f13byakl{color:blue}.f13byakl::-webkit-input-placeholder{color:rgba(0, 0, 0, 0)}.f13byakl::-moz-placeholder{color:rgba(0, 0, 0, 0)}.f13byakl::-ms-input-placeholder{color:rgba(0, 0, 0, 0)}"
1const colorAnimation = Style.registerStyle({
2 $global: true,
3 "@keyframes &": {
4 from: { color: "red" },
5 to: { color: "blue" },
6 },
7}); //=> "h1j3ughx"
8
9const style = Style.registerStyle({
10 animationName: colorAnimation,
11 animationDuration: "1s",
12}); //=> "fibanyf"
1Style.registerStyle({ 2 $global: true, 3 "@font-face": { 4 fontFamily: '"Bitstream Vera Serif Bold"', 5 src: 'url("https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf")', 6 }, 7}); 8 9Style.registerStyle({ 10 $global: true, 11 "@media print": { 12 body: { 13 color: "red", 14 }, 15 }, 16}); 17 18Style.registerStyle({ 19 $global: true, 20 body: { 21 margin: 0, 22 padding: 0, 23 }, 24}); 25 26Style.registerStyle({ 27 $global: true, 28 body: { 29 margin: 0, 30 padding: 0, 31 "@print": { 32 color: "#000", 33 }, 34 }, 35 h1: { 36 fontSize: "2em", 37 }, 38});
1Style.getStyles(); //=> ".f65pi0b{background-color:red;padding:10px}"
This package is a pure ESM package and ships with TypeScript definitions. It cannot be require
'd or used with CommonJS module resolution in TypeScript.
polished
classnames
color
style-helper
postcss-js
inline-style-prefixer
insert-css
image-url
Display names will automatically be removed when process.env.NODE_ENV === "production"
.
The only argument to create()
is a map of change function handlers. All functions are required:
add(style: Container<any>, index: number)
change(style: Container<any>, index: number)
remove(style: Container<any>, index: number)
All styles implement Container
, so you can call getStyles()
or clone()
.
Sheet
, Style
, and Rule
have the ability to be merged.
1const otherSheet = create(); 2 3sheet.merge(otherSheet); // Merge the current styles of `otherSheet` into `sheet`. 4sheet.unmerge(otherSheet); // Remove the current styles of `otherSheet` from `sheet`.
If you plan to re-use styles across Sheet
s, it will be more efficient to use compile
once and register
many times instead of registerStyle
.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More