Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/davesnx/styled-ppx/llms.txt

Use this file to discover all available pages before exploring further.

Since v0.40, styled-ppx ships a runtime module called CSS. The PPX transformation uses it internally to emit typed CSS declarations, but you can also use it directly to build values for interpolation or to construct rules for the Array API.

Available packages

Install the runtime that matches your platform:
PlatformPackage / library
ReScript@davesnx/styled-ppx/rescript (npm)
Melangestyled-ppx.melange (dune library, (modes melange))
Nativestyled-ppx.native (dune library)

Quick start

let small = CSS.px(10)
// Creates a CSS.length type, valid on any CSS property that accepts a length value

// `small` can now be interpolated in %cx, %css, or %styled.tag
let classname = %cx(`margin: $(small)`)

Values

All CSS values are available as typed constructors on the CSS module. Polymorphic variants are direct aliases — both forms are interchangeable:
let ten = CSS.px(10)
let position = CSS.block

// Polymorphic variant aliases — identical types
let ten' = #px(10)      // same as CSS.px(10)
let position' = #block  // same as CSS.block

Properties

All CSS properties are available as camelCased functions that return a Css.rule. When using the Array API, calling these functions directly lets you programmatically build rule lists without writing a CSS string:
let faded = CSS.opacity(0.9)

// Properties with complex values
let basic = CSS.flex(1.0, 1.0, #px(100))

// Properties that accept polymorphic variants
let row = CSS.display(#flex)
If you are using the PPX string syntax (%cx, %styled.*), the property functions are generated for you automatically. You only need to call them manually when using the Array API.

Common value constructors

Length

ConstructorExampleCSS output
CSS.pxCSS.px(10)10px
CSS.emCSS.em(1.5)1.5em
CSS.remCSS.rem(1.0)1rem
CSS.vhCSS.vh(100.0)100vh
CSS.vwCSS.vw(50.0)50vw
CSS.pctCSS.pct(50.0)50%
CSS.chCSS.ch(2.0)2ch
CSS.cmCSS.cm(1.0)1cm
CSS.mmCSS.mm(5.0)5mm
CSS.ptCSS.pt(12)12pt
CSS.frCSS.fr(1.0)1fr
CSS.zeroCSS.zero0

Color

ConstructorExampleCSS output
CSS.hexCSS.hex("ff0000")#ff0000
CSS.rgbCSS.rgb(255, 0, 0)rgb(255,0,0)
CSS.rgbaCSS.rgba(255, 0, 0, 0.5)rgba(255,0,0,0.5)
CSS.hslCSS.hsl(0, 100.0, 50.0)hsl(0,100%,50%)
CSS.hslaCSS.hsla(0, 100.0, 50.0, 1.0)hsla(0,100%,50%,1)
CSS.currentColorCSS.currentColorcurrentColor
CSS.transparentCSS.transparenttransparent

Angle

ConstructorExampleCSS output
CSS.degCSS.deg(45.0)45deg
CSS.radCSS.rad(1.57)1.57rad
CSS.gradCSS.grad(100.0)100grad
CSS.turnCSS.turn(0.25)0.25turn

Time

ConstructorExampleCSS output
CSS.sCSS.s(1)1s
CSS.msCSS.ms(300)300ms

Easing

ConstructorExample
CSS.easeCSS.ease
CSS.linearCSS.linear
CSS.easeInCSS.easeIn
CSS.easeOutCSS.easeOut
CSS.easeInOutCSS.easeInOut
CSS.cubicBezierCSS.cubicBezier(0.4, 0.0, 0.2, 1.0)
CSS.stepsCSS.steps(4, ...)

Transform

ConstructorExample
CSS.translateCSS.translate(CSS.px(10), CSS.px(20))
CSS.translateXCSS.translateX(CSS.pct(50.0))
CSS.translateYCSS.translateY(CSS.px(8))
CSS.rotateCSS.rotate(CSS.deg(45.0))
CSS.scaleCSS.scale(1.2, 1.2)
CSS.skewXCSS.skewX(CSS.deg(15.0))
CSS.skewYCSS.skewY(CSS.deg(10.0))

CSS.unsafe

When a CSS property is not yet supported by styled-ppx, use CSS.unsafe as an escape hatch. It accepts a raw property name and a raw value string, and returns a Css.rule you can include via the Array API:
let block: Css.rule = %css("display: block")
let randomProperty = CSS.unsafe("-webkit-invented-property", "10px")

let picture = %cx([block, randomProperty])
CSS.unsafe bypasses all type checking. Correctness is entirely your responsibility. If a property you need is missing, consider opening an issue — most properties are straightforward to add.

Native-only utilities

The following functions are only available when using the styled-ppx.native dune library. They are not available in the ReScript or Melange packages.
FunctionDescription
CSS.get_stylesheet()Returns the accumulated stylesheet as a string, for server-side rendering
CSS.style_tagProduces an HTML <style> tag containing the collected styles

Build docs developers (and LLMs) love