Skip to content

HTMLText

Creates an HTMLText

Renders text using HTML and CSS within a PixiJS scene. This allows rich formatting including custom fonts, colors, links, and other CSS styles that are not available with the standard <text> element.

Usage

vue
<script setup>
const style = {
  fontFamily: 'Arial',
  fontSize: 24,
  fill: '#336699',
  wordWrap: true,
  wordWrapWidth: 400,
}
</script>

<template>
  <html-text
    text="Hello <b>World</b>!"
    :style="style"
    :x="50"
    :y="50"
  />
</template>

Rich HTML Content

HTMLText supports inline HTML tags for formatting:

vue
<template>
  <html-text
    text="<h2>Title</h2><p>Styled with <em>CSS</em> and <span style='color:red'>HTML</span></p>"
    :style="{ fontSize: 16, wordWrap: true, wordWrapWidth: 300 }"
  />
</template>

API

HTMLText Attributes

NameTypeDefaultDescription
textstring''The HTML string to render. Supports inline HTML tags.
styleobjectundefinedText style options including font, fill, wordWrap, and CSS properties.
anchor

number array object

0The anchor sets the origin point of the text.
anchor-xnumber0The x anchor sets the origin point of the text.
anchor-ynumber0The y anchor sets the origin point of the text.

more props in Container Attributes and HTMLText

HTMLText Events

NameTypeDescription
effectfunctionCustom render function

more events in Container Events

Notes

  • HTMLText renders via a foreign object in SVG, then rasterizes to a texture. This makes it slower than <text> or <bitmap-text> for frequently changing content.
  • Best suited for static or infrequently updated rich text where CSS styling is needed.
  • For high-performance text, prefer <text> or <bitmap-text>.