Skip to content

Text

Renders a text string inside a configurable HTML container. Supports variants for headings, body text, and visual styling.

new Text("Hello, world!")
PropertyTypeDefaultDescription
idString—Optional component ID
textString—The text content (may contain template expressions like ${value})
containerTextContainerdivHTML element used to wrap the text
variantsList<TextVariant>[]Visual modifiers
sizeTextSizemFont size relative to the surrounding text
noMarginsbooleanfalseDrops the container’s block margins
styleString""Inline CSS
cssClassesString""CSS class names
attributesMap<String, String>{}Additional HTML attributes
ValueHTML element
div<div> (block, default)
span<span> (inline)
h1 – h6Heading levels
p<p> paragraph
ValueDescription
bBold weight
iItalic

Colour and other visual tweaks go through style / cssClasses; the font size through size (TextSize: xl, l, m — the default —, s, xs).

// Heading
new Text("Page title", TextContainer.h2)
// Paragraph
new Text("Introductory paragraph.", TextContainer.p)
// Bold, coloured through style
Text.builder()
.text("Something went wrong!")
.variants(List.of(TextVariant.b))
.style("color: var(--lumo-error-text-color);")
.build()
// Template expression (interpolated at render time)
new Text("Welcome, ${user.name}!")
// Inline span
new Text("inline", TextContainer.span)
new Text("plain string")
new Text("text", TextContainer.h1)
new Text("text", List.of(TextVariant.b))
new Text("id", "text")
new Text("id", "text", TextContainer.h2)
new Text("id", "text", List.of(TextVariant.i))

See it live in the Explorer: Text, Markdown, links & lists