Info
This site is generated using the static site generator developed by the Typst Community. Please adjust the text content of this banner according to your usage requirements. At Typst GmbH's request, when publishing documentation, you must clearly indicate that it is non-official and display the version of Typst being documented. For details, refer to Issue #874 on typst/typst.
TypstDocumentEnglish
v0.dev.2025-09-12

selector

A filter for selecting elements within the document.

To construct a selector you can:

Selectors are used to apply styling rules to elements. You can also use selectors to query the document for certain types of elements.

Furthermore, you can pass a selector to several of Typst's built-in functions to configure their behaviour. One such example is the outline where it can be used to change which elements are listed within the outline.

Multiple selectors can be combined using the methods shown below. However, not all kinds of selectors are supported in all places, at the moment.

Example

#context query(
  heading.where(level: 1)
    .or(heading.where(level: 2))
)

= This will be found
== So will this
=== But this will not.
Preview

Constructor
Parameter
Parameters are input values for functions. Specify them in parentheses after the function name.

Turns a value into a selector. The following values are accepted:

target
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

Can be an element function like a heading or figure, a <label> or a more complex selector like heading.where(level: 1).

Definition
Definition
These functions and types can have related definitions. To access a definition, specify the name of the function or type, followed by the definition name separated by a period.

or

Selects all elements that match this or any of the other selectors.

others
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.
Variadic
Variadic
Variadic parameters can be specified multiple times.

The other selectors to match on.

and

Selects all elements that match this and all of the other selectors.

others
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.
Variadic
Variadic
Variadic parameters can be specified multiple times.

The other selectors to match on.

before

Returns a modified selector that will only match elements that occur before the first match of end.

end
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

The original selection will end at the first match of end.

inclusive

Whether end itself should match or not. This is only relevant if both selectors match the same type of element. Defaults to true.

Default value:

true

after

Returns a modified selector that will only match elements that occur after the first match of start.

start
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

The original selection will start at the first match of start.

inclusive

Whether start itself should match or not. This is only relevant if both selectors match the same type of element. Defaults to true.

Default value:

true

Open official docs

Search