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
Settable
Question mark

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

Default: auto

height
auto or relative
Settable
Question mark

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

Default: auto

fill
none or color or gradient or pattern
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

View example
#rect(fill: blue)
Preview

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

How to stroke the rectangle. This can be:

Default: auto

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

radius
relative 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: (:)

View example
#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 or dictionary
Settable
Question mark

How much to pad the rectangle's content. See the box's documentation for more details.

Default: 5pt

outset
relative 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: (:)

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