Zubra UI
Code for
GitHub

typing-text

Text typed out a letter at a time with a blinking caret, starting when it scrolls into view. Screen readers get the whole text at once; reduced motion shows it typed.

This one has no events: it shows what it's given.

Source: typing-text.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/typing-text.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/typing-text.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/typing-text.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/typing-text.json
One file, no dependencies (2.3 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/typing-text.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/typing-text.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/typing-text.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/typing-text.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/typing-text.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/typing-text.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/typing-text.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/typing-text.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/typing-text.js"></script>

The compiled install writes src/components/zubra/typing-text.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<typing-text text="Bake bread you are proud of."></typing-text>

<script type="module">
  import './components/zubra/typing-text.js';

  const element = document.querySelector('typing-text');
  element.speed = 45;
</script>
Example.jsx
import './components/zubra/typing-text.js';

const speed = 45;

export function TypingTextExample() {
  return (
    <typing-text text="Bake bread you are proud of." speed={speed}></typing-text>
  );
}
Example.vue
<script setup>
import './components/zubra/typing-text.js';
const speed = 45;
</script>

<template>
  <typing-text text="Bake bread you are proud of." :speed.prop="speed"></typing-text>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/typing-text.js';
  const speed = 45;
</script>

<typing-text text="Bake bread you are proud of." {speed}></typing-text>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/typing-text.js';

@Component({
  selector: 'app-typing-text-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <typing-text text="Bake bread you are proud of." [speed]="speed"></typing-text>
  `,
})
export class TypingTextExample {
  speed = 45;
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
textstring""
speednumber45
delaynumber200
caretbooleantrue

Size

1.1 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.7 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour