> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nemu.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Styling

> Role styles, block level overrides, and the style properties that matter for documents

Styles are plain objects. `set_style` assigns a default style per role, and a block level
`style` merges on top of its role style for that one block.

## Roles

`set_style` takes a partial map from role to style. The roles are:

```ts theme={null}
type StyleRole =
  | "heading" | "paragraph" | "code" | "formula" | "list"
  | "link" | "group" | "divider" | "note" | "table" | "chart";

type RoleStyles = Partial<Record<StyleRole, StyleProperties>>;
```

```ts theme={null}
doc.set_style({
  heading: { font_family: "inter", color: "#111827" },
  paragraph: { font_family: "source-serif-4", font_size: 11.5, line_height: 1.6 },
  link: { color: "#2563eb" },
});
```

A block then overrides its role with `style`:

```ts theme={null}
{ type: "paragraph", text: "Centered note.", style: { text_align: "center", color: "#6b7280" } }
```

## Style properties

`StyleProperties` is a CSS like bag. The fields that matter most for documents:

<ParamField path="color" type="ColorLike">
  Text color. Accepts a hex string or a `Color`. See [Color](/packages/pdf/color).
</ParamField>

<ParamField path="background_color" type="ColorLike">
  Background fill. Accepts a hex string or a `Color`. See [Color](/packages/pdf/color).
</ParamField>

<ParamField path="font_family" type="string">
  One of the bundled font names or a custom registered name. See
  [Fonts and weights](/packages/pdf/doc/fonts).
</ParamField>

<ParamField path="font_size" type="number">
  Font size in points.
</ParamField>

<ParamField path="font_weight" type="&#x22;normal&#x22; | &#x22;bold&#x22; | number">
  Selects a real weight by instancing the variable font. Accepts a weight name or a number.
  See [Fonts and weights](/packages/pdf/doc/fonts).
</ParamField>

<ParamField path="font" type="string">
  The math font name for formulas. See [Formulas](/packages/pdf/doc/formulas).
</ParamField>

<ParamField path="line_height" type="number">
  Line height multiplier.
</ParamField>

<ParamField path="text_align" type="&#x22;left&#x22; | &#x22;center&#x22; | &#x22;right&#x22; | &#x22;justify&#x22;">
  Horizontal text alignment.
</ParamField>

<ParamField path="text_markdown" type="boolean">
  Opt string parts into markdown parsing. See [Inline content](/packages/pdf/doc/inline).
</ParamField>

<ParamField path="margin" type="number | string">
  Outer spacing. Also `margin_top`, `margin_right`, `margin_bottom`, and `margin_left`.
</ParamField>

<ParamField path="padding" type="number | string">
  Inner spacing. Also `padding_top`, `padding_right`, `padding_bottom`, and `padding_left`.
</ParamField>

<ParamField path="width" type="number | string">
  Box width.
</ParamField>

<ParamField path="height" type="number | string">
  Box height.
</ParamField>

```ts theme={null}
interface StyleProperties {
  color?: ColorLike;
  background_color?: ColorLike;
  font_family?: string;
  font_size?: number;
  font_weight?: "normal" | "bold" | number;
  font?: string;
  line_height?: number;
  text_align?: "left" | "center" | "right" | "justify";
  text_markdown?: boolean;
  margin?: number | string;
  padding?: number | string;
  width?: number | string;
  height?: number | string;
}
```

<Note>
  `color` and `background_color` accept a hex string or a `Color`, so `ColorLike = string |
    Color`. See [Color](/packages/pdf/color).
</Note>
