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

elem
Element
Element
Element functions can be customized with set and show rules.

An HTML element that can contain Typst content.

Typst's HTML export automatically generates the appropriate tags for most elements. However, sometimes, it is desirable to retain more control. For example, when using Typst to generate your blog, you could use this function to wrap each article in an <article> tag.

Typst is aware of what is valid HTML. A tag and its attributes must form syntactically valid HTML. Some tags, like meta do not accept content. Hence, you must not provide a body for them. We may add more checks in the future, so be sure that you are generating valid HTML when using this function.

Normally, Typst will generate html, head, and body tags for you. If you instead create them with this function, Typst will omit its own tags.

#html.elem("div", attrs: (style: "background: aqua"))[
  A div with _Typst content_ inside!
]

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

tag
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 element's tag.

attrs
Settable
Settable
Settable parameters can be set using the set rule, changing the default value used thereafter.

The element's HTML attributes.

Default value:

(:)

body
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.
Settable
Settable
Settable parameters can be set using the set rule, changing the default value used thereafter.

The contents of the HTML element.

The body can be arbitrary Typst content.

Default value:

none

Open official docs

Search