mrkeyoor.comAsk

npm package

csstype review

Use CSSType when you own a style-object type boundary and can test the resulting CSS in its actual consumer.

npmWeb Frontendupdated 01 Dec 2026

A misspelled style key is easier to catch before you open the browser. CSSType 3.2.4 supplies TypeScript and Flow definitions for CSS properties and values, generated from MDN data. Use it to describe JavaScript style objects and give editors useful suggestions. Its types do not apply styles, convert units, or prove that a value will render as intended. Some value types accept arbitrary strings, so a successful type check still leaves browser behavior to verify.

Verdict

Use CSSType when you own a style-object type boundary and can test the resulting CSS in its actual consumer. Start with React's existing style type for React-only code, or a CSS parser when validating CSS text.

Answers from our run

csstype or @types/react: which should you use?

@types/react: For a React style prop, consider React.CSSProperties from your React types. The supplied @types/react 19.3.3 declaration extends CSS.Properties<string | number>, so this is a framework entry point to CSSType rather than an independent replacement. Use CSSType when you own a style-object type boundary and can test the resulting CSS in its actual consumer.

When should you not use csstype?

You need to validate untrusted CSS strings. Some value types accept arbitrary strings; use a parser and a suitable validation step.

API stability3/5The versioned README documents named property families, separate length and time generics, and the Property namespace. Those give callers a concrete contract. Its explicit warning about conflicts between 3.2 and 2.x limits the stability evidence; the documentation does not promise compatibility across dependency graphs.
Docs4/5The pinned README includes the style-family table, generics, fallback arrays, pseudo maps, DOM assignment, and a section on type errors and custom properties. That is enough to choose a type shape and see the escape hatches. Runtime behavior still belongs to the consuming styling API, and these examples have not been compiled here.
Maintenance3/5The supplied npm response identifies version 3.2.4, and its matching README says the declarations are generated from MDN data rather than edited by hand. This documents an update mechanism. It does not establish maintainer response times, release cadence, or future support; those maintenance questions remain unresolved.
Ecosystem4/5The supplied @types/react 19.3.3 declaration extends CSSType's Properties interface for CSSProperties, giving a concrete integration point. CSSType's documentation also covers TypeScript and Flow. These are documented uses, not evidence of market share or proof that every styling framework accepts the same object shape.

Use it if

You author reusable TypeScript style objects and want property-name checking without choosing a CSS-in-JS runtime.
Your styling adapter needs an explicit choice between camelCase keys, kebab-case keys, and fallback arrays.
A public component or styling library needs CSS property types in its exported declarations.
Your project uses Flow and needs the CSS definitions supplied alongside the TypeScript declarations.

Skip it if

You need to validate untrusted CSS strings. Some value types accept arbitrary strings; use a parser and a suitable validation step.
You expect installing this package to render styles, insert rules, or convert numeric values into units. It supplies types.
You only need to type React's style prop. Consider the existing React.CSSProperties type before introducing a direct import.
Your dependency graph still mixes CSSType 2.x and 3.2, and you cannot review a dependency override. The README explicitly warns of conflicts.
Your goal is to prove that every target browser supports a declaration. A successful TypeScript check cannot establish that.

Setup reality

Install the version this guide describes with npm install --save-dev csstype@3.2.4 for an application that only uses its types. Import with import type * as CSS from 'csstype'. A library whose public declarations import csstype needs to make that dependency available to consumers; copying an application's dev-dependency setup can leave consumers with unresolved types. The published package points TypeScript at index.d.ts and has an empty main field. Treat it as a declaration dependency rather than a JavaScript module to call.

Start with CSS.Properties for camelCase object keys. PropertiesHyphen describes kebab-case keys, while PropertiesFallback permits arrays as property values. Those shapes do not serialize anything. A fallback array needs a styling system that understands it, and widening the length generic to string | number does not decide whether 12 means pixels. The receiving platform owns that rule. Even the default width type includes a free-form string branch, so typing width as a string is not a CSS grammar check.

Literal widening can turn a separately declared value into string before you assign it to a narrower property type. Annotate the object where you create it rather than scattering assertions over later assignments. Custom properties need an explicit extension. Add the variable you need, or constrain a local custom-property namespace; a general string index signature also accepts spelling mistakes in ordinary property names. Module augmentation changes the shared Properties interface, so keep it in a declaration file included by the project and review its scope.

The pinned README warns that 3.2 can conflict with 2.x when both are installed. Inspect npm ls csstype before applying the README's suggested override, because forcing one version changes the type dependency chosen for affected consumers. React projects should first consider React.CSSProperties: the supplied @types/react 19.3.3 declaration extends CSS.Properties<string | number>. A direct csstype dependency is useful when your own code or public declarations import it.

These are documentation-based, unexecuted illustrations. The supplied evidence includes versioned declarations and documentation, but no package installation, snippet compilation, rendered-style checks, or bundle-size measurement. Check the examples against your compiler and styling system before adopting them. Reader-facing scores are computed by the site's published rubric. The dimension notes explain the editor's assessment of the supplied documentation; they do not establish measured compatibility, adoption, maintenance response times, or future support.

Patterns

Check a camelCase style object type-style-object

import type * as CSS from 'csstype';

const card: CSS.Properties = {
  display: 'grid',
  backgroundColor: 'white',
  gap: '1rem',
};

Properties describes camelCase keys. It does not insert a stylesheet or attach this object to an element. This illustration was not executed.

Keep CSS spelling in an object type-hyphenated-keys

import type * as CSS from 'csstype';

const rule: CSS.PropertiesHyphen = {
  'background-color': 'white',
  'font-weight': 600,
};

Use the Hyphen variant for kebab-case keys. Choosing that interface does not convert an existing camelCase object.

Describe a fallback list describe-fallback-values

import type * as CSS from 'csstype';

const layout: CSS.PropertiesFallback = {
  display: ['-webkit-flex', 'flex'],
};

Fallback permits arrays, including readonly arrays in the declaration mapping. Your styling system must interpret the list; this is not an object to pass directly as a DOM style value.

Match a consumer that accepts numeric lengths allow-numeric-lengths

import type * as CSS from 'csstype';

const box: CSS.Properties<string | number> = {
  width: 120,
  marginTop: 8,
};

The default length parameter allows strings and zero. Broadening it accepts other numbers but performs no unit conversion; use this only when the receiving API defines their meaning.

Describe numeric time values for a custom consumer allow-numeric-times

import type * as CSS from 'csstype';

type TimedStyle = CSS.Properties<string | number, number>;
const transition: TimedStyle = {
  transitionDuration: 150,
};

The second generic controls time values. It does not make this object valid for every style API or turn 150 into milliseconds at runtime.

Type a single property parameter type-single-value

import type * as CSS from 'csstype';

function withAlignment(textAlign: CSS.Property.TextAlign): CSS.Properties {
  return { textAlign };
}
const centered = withAlignment('center');

Property types live under the Property namespace in version 3. This narrows the parameter without pretending that all CSS value strings have a strict grammar.

Describe a map of simple pseudo rules describe-pseudo-rules

import type * as CSS from 'csstype';

type PseudoRules = { [P in CSS.SimplePseudos]?: CSS.Properties };
const states: PseudoRules = {
  ':hover': { color: 'red' },
  ':focus': { outline: '2px solid currentColor' },
};

SimplePseudos supplies selector names for this map. It does not attach event handlers or emit selectors; functional selectors need additional modeling.

Add one custom property locally type-local-variable

import type * as CSS from 'csstype';

type ThemeStyle = CSS.Properties & {
  '--theme-color'?: 'black' | 'white';
};
const theme: ThemeStyle = {
  '--theme-color': 'black',
  color: 'var(--theme-color)',
};

The intersection limits the extra key to this local type. It does not guarantee that a referenced CSS variable exists on an element at runtime.

Declare a shared custom property augment-shared-properties

// project-css.d.ts, included by your TypeScript project
import type * as CSS from 'csstype';

declare module 'csstype' {
  interface Properties {
    '--theme-color'?: 'black' | 'white';
  }
}

export type ThemeProperties = CSS.Properties;

Module augmentation affects users of the shared Properties interface within the compilation. Prefer a named custom property over a catch-all string index signature that hides misspelled CSS keys.

Apply a small ordinary style object in a browser assign-browser-style

import type * as CSS from 'csstype';

const style: CSS.Properties = {
  color: 'red',
  margin: '1em',
};
const button = document.createElement('button');
Object.assign(button.style, style);

This follows the README example with ordinary camelCase properties and string values. The button is detached until you insert it. Do not generalize this assignment to fallback arrays or arbitrary custom-property keys.

Alternatives

PackageRegistryPick it when
@types/reactnpmFor a React style prop, consider React.CSSProperties from your React types. The supplied @types/react 19.3.3 declaration extends CSS.Properties<string | number>, so this is a framework entry point to CSSType rather than an independent replacement.
css-treenpmChoose a CSS parser and lexer when the input is CSS text that needs parsing or validation. Its npm description lists those jobs; it solves a different problem from typing JavaScript style objects.

More web frontend guides

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.