Home

Awesome

Warning This repository is no longer maintained. HTMLText has been rolled into the main project and it now bundled by default in pixi.js or pixi.js-legacy packages.

PixiJS HTMLText

Node.js CI npm (scoped)

An alternative to PIXI.Text that works with PixiJS v5 (both WebGL and Canvas), however, it has some advantages:

Disadvantages:

Install

npm install @pixi/text-html
yarn add @pixi/text-html

Usage

import { HTMLText } from '@pixi/text-html';

const text = new HTMLText("Hello World", { fontSize: 20 });

Important: Because the HTMLText object takes a raw HTML string, it's represents a potential vector for XSS, it's strongly encourage you santize input especially if you're accepting user-strings.

Custom Fonts

Because rendering within a <foreignObject> element does not have access to fonts available in the current document, therefore, you need to load the fonts explicitly.

const text = new HTMLText("Hello World", { fontFamily: 'Custom' });

await text.style.loadFont('./path/to/custom-regular.ttf', { family: 'Custom' });

Multiple Weights

const text = new HTMLText("Hello <b>World</b>", { fontFamily: 'Custom' });

await Promise.all([
    text.style.loadFont('./path/to/custom-regular.ttf', { family: 'Custom' }),
    text.style.loadFont('./path/to/custom-bold.ttf', { family: 'Custom', weight: 'bold' });
]);

Styles

Not all styles and values are compatible between PIXI.Text, mainly because Text is rendered using a DOM element instead of Context2D's fillText API.

Supported

Values may differ slightly from PIXI.Text rendering.Appearance may differ slightly between different browsers.

Unsupported

Example

https://pixijs.io/html-text/demo/

Documentation

https://pixijs.io/html-text/docs/