You're reading the v2 beta docs. For the stable release, switch to v1 →
TakumiTakumi

Styling

How CSS reaches a node, what the stylesheet engine supports, and the Tailwind paths.

Four ways to put CSS on a node:

  • style prop: inline CSSProperties on one node. Overrides the tag default.
  • tw prop: Tailwind classes on one node.
  • <style> tags: CSS that travels inside the JSX.
  • stylesheets option: full stylesheets matched against className and id.

Stylesheets

Pass real CSS through stylesheets and match it by className or id.

import {  } from "takumi-js";

const  = await (< ="card">Hello</>, {
  : 1200,
  : 630,
  : [`.card { display: flex; padding: 48px; background: #0f172a; color: white; }`],
});

The engine handles:

SelectorsAt-rulesProperties
class, id, descendant@keyframes, @media, @supportscustom properties with var(), shorthands, gradients, box-shadow, filter, backdrop-filter, mix-blend-mode, transform

A render is one static frame, so interactive pseudo-classes like :hover and :focus parse but never match.

A <style> tag feeds the same engine and gets extracted from the JSX automatically.

<div className="card">
  <style>{`.card { display: flex; padding: 48px; }`}</style>
  Hello
</div>

Tailwind

Bring your stylesheet

Compile Tailwind with your bundler, then pass the CSS through stylesheets. On Vite, import it with the ?inline query.

og.tsx
import { ImageResponse } from "takumi-js/response";
import stylesheet from "~/styles/global.css?inline";

export function GET() {
  return new ImageResponse(
    <div className="bg-background text-foreground flex justify-center items-center w-full h-full text-4xl">
      Hello Tailwind!
    </div>,
    {
      width: 1200,
      height: 630,
      stylesheets: [stylesheet],
    },
  );
}
vite.config.ts
import { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite";

export default defineConfig({
  plugins: [tailwindcss()],
});

Native parser

The tw prop runs a built-in parser with no build step. It won't cover every Tailwind feature.

  • No theme config, but arbitrary values work.
  • See the parser mapping for every supported class.
<div tw="bg-blue-500 p-4 rounded-lg">
  <h1 tw="text-white text-2xl font-bold">Hello Tailwind!</h1>
</div>

tw is a plain prop, so build it dynamically:

import clsx from "clsx";

const isError = true;

<div tw={clsx("p-4 rounded", isError ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700")}>
  {isError ? "Something went wrong" : "Success!"}
</div>;
Edit on GitHub

Last updated on

On this page