Typst Fumadocs

Stroke

Documentation for the Stroke type.

Defines how to draw a line.

A stroke has a paint (a solid color or gradient), a thickness, a line cap, a line join, a miter limit, and a dash pattern. All of these values are optional and have sensible defaults.

Example

Loading compiler...

Simple strokes

You can create a simple solid stroke from a color, a thickness, or a combination of the two. Specifically, wherever a stroke is expected you can pass any of the following values:

  • A length specifying the stroke's thickness. The color is inherited, defaulting to black.
  • A color to use for the stroke. The thickness is inherited, defaulting to 1pt.
  • A stroke combined from color and thickness using the + operator as in 2pt + red.

For full control, you can also provide a dictionary or a stroke object to any function that expects a stroke. The dictionary's keys may include any of the parameters for the constructor function, shown below.

Fields

On a stroke object, you can access any of the fields listed in the constructor function. For example, (2pt + blue).thickness is 2pt. Meanwhile, stroke(red).cap is auto because it's unspecified. Fields set to auto are inherited.

Constructor

Converts a value to a stroke or constructs a stroke with the given parameters.

Note that in most cases you do not need to convert values to strokes in order to use them, as they will be converted automatically. However, this constructor can be useful to ensure a value has all the fields of a stroke.

Loading compiler...
#stroke(
  paint,
  thickness,
  cap,
  join,
  dash,
  miter-limit
) -> stroke

Parameters

Prop

Type

On this page