Skip to content
Focsd homeFocsd homeFocsd
Forms

Streaming text

Markdown that grows while a reply streams. Raw HTML stays text, and links keep only safe schemes.

  • Tag: focsd-streaming-text
  • Pattern: Static text that grows while it streams
  • Category: AI

Example

HTML
<focsd-streaming-text id="text-demo" streaming></focsd-streaming-text>
<script type="module">
document.getElementById('text-demo').text = 'Markdown is **built as it arrives**:\n\n- lists and `inline code`\n- [links](https://focsd.dev) that are safe to follow\n- <b>raw HTML</b> shown as text\n\n```js\nawait chat.send("Hello");\n```';
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/ai';
</script>
<focsd-streaming-text streaming></focsd-streaming-text>

API

Attributes

AttributePropertyTypeDefault
texttextstring—
plainplainbooleanfalse
streamingstreamingbooleanfalse

CSS parts

Style the inside of the component with ::part(), for example focsd-streaming-text::part(text).

PartDescription
textThe text.
caretThe caret shown while streaming (hidden from assistive technology).
codeEach code block (`pre`).
code-copyThe copy button of each code block.

Accessibility

  • The text is built with DOM calls only (never innerHTML), so it runs under a strict Content Security Policy with Trusted Types. Raw HTML, images and tables are shown as text.
  • Links keep https:, http:, mailto: and relative URLs only (javascript:, data: and the rest become text) and get rel="noopener noreferrer nofollow".
  • Only the last block is rebuilt on each update, so a selection or focus inside finished blocks survives while text streams.
  • The caret is hidden from assistive technology and stops pulsing under reduced motion. Each code block shows its language and has its own copy button. A code block that scrolls sideways is a named region in the tab order, so it scrolls by keyboard; one that fits adds no tab stop.
  • Headings inside a reply are rendered from level 3 down, never as h1 or h2, so they sit under the page’s own headings.
  • On the server the text renders as plain text with its line breaks, so there is content before the script loads.