Open-source project
cristianbote/goober avatar
cristianbote/goober

goober: a sub-1KB css-in-js library with a styled-components API

🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API

3,275 stars127 forksJavaScriptMIT

At a glance

What is it?
goober is a small css-in-js runtime for Preact, React and vanilla DOM that keeps the styled pattern while staying under 1KB. The trade-off is a thinner API surface and a setup call you must not forget.
Who is it for?
goober fits teams that already write styled-components or emotion style code and want the same shape at a fraction of the bundle, especially on Preact, Fre or web-component projects where a custom render target matters. It does not fit codebases that depend on .attrs, .withComponent, style labels or classNames, because the comparison table in the README marks those as not supported.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Activity is slowing. The repository last received commits 6 months ago.
What is it written in?
Mainly JavaScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • cristianbote/goober3,275 ★ · +0
Star history
Repository2026-09-242026-11-25
cristianbote/goober3.3k3.3k

0 Stars in the last 62 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The bundle-size problem goober was written to answer

The README's motivation section is unusually direct about the origin: the author wanted the styled pattern in a side project, looked at the JavaScript bundle sizes, and found that using styled-components or emotion would mean shipping roughly 12kB or 11kB respectively before writing a single style. goober exists to make that cost small enough to stop being a design constraint. The tagline is a pun on the same idea: css-in-js at the cost of peanuts.

The intended audience follows from that. This is for people who want the styled('div')`...` form and the css helper, not for people who want every feature of a full css-in-js framework. The README's own comparison table lists goober at 1.25 kB base bundle size against 12.6 kB for styled-components and 7.4 kB for emotion, and it also marks goober as framework agnostic where styled-components is not. If your project already has a styling system you are happy with, goober solves a problem you do not have.

How the styled and css functions actually work

The API is explicitly described as inspired by emotion's styled function. You call styled with a tag name, and it returns a vDOM component for that tag. The README states that setup has to run before styled is used. In the Preact example this is a single call, setup(h), where h is the hyperscript function from preact.

Styles are written as tagged template literals. Interpolations are allowed anywhere a value would go, including inside selectors, and the README's Button example interpolates Math.random() directly into a border declaration. Nested selectors such as &:focus and &:hover, plain class selectors like .otherClass, and references to another styled component inside the template are all shown in that same example. Object styles and dynamic styles are both marked as supported in the comparison table.

One capability that stands out in the table is render with target. The README says goober can render into any DOM target, which the author calls out as useful for defining scoped styles in any context, specifically web components. Neither styled-components nor emotion is marked as supporting that. A separate extractCss(target) function exists for pulling the generated styles out, which is the hook server rendering depends on.

Installing goober and writing a first styled component

The package is published on npm as goober, and the package.json lists dist/goober.cjs, dist/goober.esm.js and dist/goober.umd.js as entry points, so a normal bundler install works. Install it alongside your framework.

bash
npm install goober

Before any styled component is defined, setup must be called once with your framework's hyperscript function. The README says it should be called here, and just once. For Preact that function is h, imported from preact.

js
import { h } from 'preact';
import { styled, setup } from 'goober';

setup(h);

const Button = styled('button')`
    background: dodgerblue;
    color: white;
`;

The result is a component you render like any other element, and the class it produces is applied to the button at runtime. After that first component renders, the generated rule should be visible in the document's stylesheet. For React, the README's examples link to a CodeSandbox rather than repeating the setup call in the README body, so check the React example for the exact import before wiring it up.

Two optional packages ship in the same repository and are exposed as subpath exports. goober/prefixer adds autoprefixing, and it has its own README. goober/should-forward-prop controls which props reach the DOM. There is also goober/global for createGlobalStyles and a goober/macro entry for the Babel macro plugin.

Where goober stops: the missing API surface

The comparison table is the most useful page in the repository because it is a list of things goober does not do. The default export is not supported. .withComponent is not supported. .attrs is not supported. Labels and classNames are not supported, though emotion supports both. Those are not edge cases in a large codebase: .attrs is a common way to bake props into a styled component, and .withComponent is used when the same styles need to move between tags.

The table also carries a partial-support marker on styled.<tag>. Treat that row as unverified until you read the full README.

There is a second, structural cost. setup must run before styled, and the README says once. That is a module-level ordering requirement rather than a compile-time guarantee, and forgetting it is the kind of failure that shows up as an error at first render rather than at build time. Projects that enforce strict import ordering or that lazily load styling code need to account for it.

Server rendering, CSP and the extractCss step

Server rendering is listed as supported, and extractCss(target) is the API that makes it work: it pulls the accumulated styles out so they can be placed in the served HTML. The README links a dedicated SSR with Preact example rather than inlining the full pattern, so the ordering of extractCss relative to your render call is something to take from that example, not from the README body.

Content Security Policy is listed as a feature in the table of contents. That matters because css-in-js libraries that inject style tags at runtime can conflict with strict style-src directives. The specific approach is worth confirming before you commit to it under a strict policy.

Browser support is its own section in the table of contents. The README does not state a browser matrix in the text available here, so if you need to support older browsers, that section is where to look rather than assuming the small bundle implies broad support.

goober against styled-components and emotion

The README compares goober to styled-components and emotion directly, and the difference is not only size. styled-components is marked as not framework agnostic and as not supporting render with target; goober supports both. The practical consequence is that goober can be used outside React and Preact, and the README points at a Fre example alongside React, Preact and vanilla ones.

emotion is closer in shape. It is framework agnostic, and it supports labels and classNames, which goober does not. If you rely on generated class names being readable in devtools, emotion is the one that gives you that. If you do not, goober's smaller surface is the whole point.

The honest framing is that goober is a subset, not a replacement. Its own table says so. Choosing it means accepting that some patterns you may already use have no equivalent, in exchange for a base bundle the README puts at 1.25 kB. That is a reasonable trade only if you can enumerate which patterns you actually use.

Maintenance, licence and what upgrading costs

The repository is not archived, and the last push was on 2026-05-13, which is the same date as the v2.1.19 release. The two releases before it, v2.1.18 and v2.1.17, are dated 2025-10-03 and 2025-10-02. So the cadence visible here is a burst of patch releases in October 2025 and a single patch in May 2026.

The version numbers say something about upgrade cost on their own: the project is on 2.1.19, and the recent releases are all patch-level. Nothing here describes a breaking change in that window, and the README documents no migration path, because there is nothing to migrate from at this version. That is the good case for a dependency this small.

The licence is MIT, which is permissive and places few conditions on redistribution or modification. This is not legal advice; if you vendor the source or ship it in a product with unusual licensing requirements, read the LICENSE file in the repository root yourself. The package.json marks the package as sideEffects: false, which is the flag bundlers use for tree shaking, and it declares both CJS and ESM entry points plus a UMD build, so the packaging story is conventional.

Editorial conclusion

goober fits teams that already write styled-components or emotion style code and want the same shape at a fraction of the bundle, especially on Preact, Fre or web-component projects where a custom render target matters. It does not fit codebases that depend on .attrs, .withComponent, style labels or classNames, because the comparison table in the README marks those as not supported. Before adopting it, check three things in your own code: that setup is called once with your framework's h function, that any server render uses extractCss, and that the style props you pass down survive shouldForwardProp. The README's own comparison table is the fastest way to confirm which of your existing patterns have no equivalent here.

Frequently asked questions

How do you use goober in a Preact or React app?

Import styled and setup from goober, call setup once with your framework's hyperscript function such as h from preact, then define components with styled('tag') followed by a tagged template literal. The README states setup must be called before styled is used, and only once.

What is goober?

It is a css-in-js library published on npm as goober, described in its README as a less than 1KB css-in-js solution with an API inspired by emotion's styled function. It supports Preact, React, vanilla DOM and Fre, and it is licensed under MIT.

Does goober support server-side rendering?

Yes. SSR is marked as supported in the README's comparison table, and the extractCss(target) API is documented for pulling generated styles out. The README links a separate SSR with Preact example rather than showing the full pattern inline.

Which styled-components features are missing from goober?

The README's comparison table marks the default export, .withComponent, .attrs, labels and classNames as not supported. It also marks styled.<tag> as only partially supported, though the footnote explaining that limitation is truncated in the README text available.

Does goober work with React as well as Preact?

The README lists React and Preact examples alongside vanilla, Fre and SSR with Preact examples. setup takes your framework's hyperscript function, which is h in the Preact example shown in the README.

Official sources

  1. cristianbote/goober on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/cristianbote-goober.svg)](https://hysenlabs.com/projects/cristianbote-goober)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/cristianbote-goober.svg)](https://hysenlabs.com/projects/cristianbote-goober)

Was this useful?