TypstDocumentation

rectElement
Question mark

A rectangle with optional content.

Example

// Without content.
#rect(width: 35%, height: 30pt)

// With content.
#rect[
  Automatically sized \
  to fit the content.
]
Preview

Parameters
Question mark

width
auto or relative length
Settable
Question mark

The rectangle's width, relative to its parent container.

Default: auto

height
auto or relative length
Settable
Question mark

The rectangle's height, relative to its parent container.

Default: auto

fill
none or color
Settable
Question mark

How to fill the rectangle.

When setting a fill, the default stroke disappears. To create a rectangle with both fill and stroke, you have to configure both.

Default: none

#rect(fill: blue)
Preview

stroke
none or auto or length or color or dictionary or stroke
Settable
Question mark

How to stroke the rectangle. This can be:

Default: auto

#stack(
  dir: ltr,
  spacing: 1fr,
  rect(stroke: red),
  rect(stroke: 2pt),
  rect(stroke: 2pt + red),
)
Preview

radius
relative length or dictionary
Settable
Question mark

How much to round the rectangle's corners, relative to the minimum of the width and height divided by two. This can be:

Default: 0pt

#set rect(stroke: 4pt)
#rect(
  radius: (
    left: 5pt,
    top-right: 20pt,
    bottom-right: 10pt,
  ),
  stroke: (
    left: red,
    top: yellow,
    right: green,
    bottom: blue,
  ),
)
Preview

inset
relative length or dictionary
Settable
Question mark

How much to pad the rectangle's content.

Note: When the rectangle contains text, its exact size depends on the current text edges.

Default: 5pt

#rect(inset: 0pt)[Tight]
Preview

outset
relative length or dictionary
Settable
Question mark

How much to expand the rectangle's size without affecting the layout. See the box's documentation for more details.

Default: 0pt

body
none or content
Positional
Question mark
Settable
Question mark

The content to place into the rectangle.

When this is omitted, the rectangle takes on a default size of at most 45pt by 30pt.

Default: none