# Typewriter carriage loader

> A typewriter types the message letter by letter as the carriage moves along, then returns with a line feed.

- Category: [Loaders](https://library.aimran.es/components/loaders)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-ld-typewriter-carriage
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

The message is typed one character at a time at an irregular human pace, with a type bar striking each letter and the paper and roller sliding left as on a real machine. At the end the carriage springs back and the line moves up. It suits writing tools, newsletters, editorial sites and AI drafts.

Write the message in the text field; short phrases of up to twenty characters look best. The main color is the ink and the second color tints the type guide under the letter being struck.

## Code

### HTML

```html
<div class="uvq10-typ" role="status"><span class="sr">Loading…</span><div class="vw" aria-hidden="true"><div class="car"><div class="pap"><span class="old"></span><span class="ln"></span></div><i class="rol"></i></div><i class="tb"></i><i class="gd"></i></div></div>
```

### CSS

```css
.uvq10-typ {
  --c1: #1c1917;
  --c2: #b91c1c;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq10-typ {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.uvq10-typ .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-typ .vw {
  position: relative;
  width: 12em;
  height: 5em;
  overflow: hidden;
  font: 600 1.3em/1 "Courier New",Courier,ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  -webkit-mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
  mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
}

.uvq10-typ .car {
  position: absolute;
  left: 6em;
  top: 0;
  width: 30ch;
  height: 100%;
  transform: translateX(calc(var(--c,0) * -1ch));
  transition: transform calc(0.08s / var(--k)) ease-out;
}

.uvq10-typ.r .car {
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.3,1.3,.5,1);
}

.uvq10-typ .pap {
  position: absolute;
  left: -14ch;
  width: 46ch;
  top: .2em;
  height: 3.4em;
  background: linear-gradient(#fdfcf7,#f4f0e4);
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

.uvq10-typ.r .pap {
  animation: uvq10-typ-lf calc(0.4s / var(--k)) ease-out;
}

.uvq10-typ .ln,.uvq10-typ .old {
  position: absolute;
  left: 14ch;
  white-space: pre;
  color: var(--c1);
  text-shadow: 0 0 .6px color-mix(in srgb,var(--c1) 60%,transparent);
}

.uvq10-typ .ln {
  top: 2.05em;
}

.uvq10-typ .old {
  top: .85em;
  opacity: .55;
}

.uvq10-typ .rol {
  position: absolute;
  left: -16ch;
  width: 50ch;
  top: 3.15em;
  height: 1.2em;
  border-radius: .6em;
  background: repeating-linear-gradient(90deg,transparent 0 .5ch,rgba(255,255,255,.04) .5ch 1ch),linear-gradient(#5a5a5a,#161616 50%,#2c2c2c);
  box-shadow: 0 .3em .5em -.2em rgba(0,0,0,.5);
}

.uvq10-typ .tb {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 2.05em;
  height: 1em;
  border-radius: .1em;
  background: linear-gradient(#d1d5db,#6b7280);
  opacity: 0;
  transform: translateY(2.4em);
}

.uvq10-typ .vw.k .tb {
  animation: uvq10-typ-k calc(0.12s / var(--k)) ease-out;
}

.uvq10-typ .gd {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 3.1em;
  height: .45em;
  box-sizing: border-box;
  border: .12em solid var(--c2);
  border-top: 0;
  border-radius: 0 0 .35em .35em;
}

@keyframes uvq10-typ-k {
  0% {
    opacity: 0;
    transform: translateY(2.4em);
  }
  50% {
    opacity: 1;
    transform: translateY(.2em);
  }
  100% {
    opacity: 0;
    transform: translateY(2.4em);
  }
}

@keyframes uvq10-typ-lf {
  from {
    transform: translateY(1.2em);
  }
  to {
    transform: none;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-typ,.uvq10-typ *,.uvq10-typ *::before,.uvq10-typ *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq10-typ").forEach(el => {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const car=el.querySelector('.car'),ln=el.querySelector('.ln'),old=el.querySelector('.old'),vw=el.querySelector('.vw');
const txt=el.querySelector('.sr').textContent||'';
let i=0,t;
const pos=(n)=>car.style.setProperty('--c',String(n));
const type=()=>{if(i<txt.length){i++;ln.textContent=txt.slice(0,i);pos(i);vw.classList.remove('k');void vw.offsetWidth;vw.classList.add('k');t=setTimeout(type,(80+Math.random()*130)/k);}else{t=setTimeout(ret,1000/k);}};
const ret=()=>{el.classList.add('r');old.textContent=ln.textContent;ln.textContent='';i=0;pos(0);t=setTimeout(()=>{el.classList.remove('r');type();},800/k);};
if(rm){ln.textContent=txt;pos(txt.length);}else{t=setTimeout(type,400/k);}
return()=>clearTimeout(t);
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq10-typ {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.uvq10-typ .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-typ .vw {
  position: relative;
  width: 12em;
  height: 5em;
  overflow: hidden;
  font: 600 1.3em/1 "Courier New",Courier,ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  -webkit-mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
  mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
}

.uvq10-typ .car {
  position: absolute;
  left: 6em;
  top: 0;
  width: 30ch;
  height: 100%;
  transform: translateX(calc(var(--c,0) * -1ch));
  transition: transform calc(0.08s / var(--k)) ease-out;
}

.uvq10-typ.r .car {
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.3,1.3,.5,1);
}

.uvq10-typ .pap {
  position: absolute;
  left: -14ch;
  width: 46ch;
  top: .2em;
  height: 3.4em;
  background: linear-gradient(#fdfcf7,#f4f0e4);
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

.uvq10-typ.r .pap {
  animation: uvq10-typ-lf calc(0.4s / var(--k)) ease-out;
}

.uvq10-typ .ln,.uvq10-typ .old {
  position: absolute;
  left: 14ch;
  white-space: pre;
  color: var(--c1);
  text-shadow: 0 0 .6px color-mix(in srgb,var(--c1) 60%,transparent);
}

.uvq10-typ .ln {
  top: 2.05em;
}

.uvq10-typ .old {
  top: .85em;
  opacity: .55;
}

.uvq10-typ .rol {
  position: absolute;
  left: -16ch;
  width: 50ch;
  top: 3.15em;
  height: 1.2em;
  border-radius: .6em;
  background: repeating-linear-gradient(90deg,transparent 0 .5ch,rgba(255,255,255,.04) .5ch 1ch),linear-gradient(#5a5a5a,#161616 50%,#2c2c2c);
  box-shadow: 0 .3em .5em -.2em rgba(0,0,0,.5);
}

.uvq10-typ .tb {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 2.05em;
  height: 1em;
  border-radius: .1em;
  background: linear-gradient(#d1d5db,#6b7280);
  opacity: 0;
  transform: translateY(2.4em);
}

.uvq10-typ .vw.k .tb {
  animation: uvq10-typ-k calc(0.12s / var(--k)) ease-out;
}

.uvq10-typ .gd {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 3.1em;
  height: .45em;
  box-sizing: border-box;
  border: .12em solid var(--c2);
  border-top: 0;
  border-radius: 0 0 .35em .35em;
}

@keyframes uvq10-typ-k {
  0% {
    opacity: 0;
    transform: translateY(2.4em);
  }
  50% {
    opacity: 1;
    transform: translateY(.2em);
  }
  100% {
    opacity: 0;
    transform: translateY(2.4em);
  }
}

@keyframes uvq10-typ-lf {
  from {
    transform: translateY(1.2em);
  }
  to {
    transform: none;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-typ,.uvq10-typ *,.uvq10-typ *::before,.uvq10-typ *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const car=el.querySelector('.car'),ln=el.querySelector('.ln'),old=el.querySelector('.old'),vw=el.querySelector('.vw');
const txt=el.querySelector('.sr').textContent||'';
let i=0,t;
const pos=(n)=>car.style.setProperty('--c',String(n));
const type=()=>{if(i<txt.length){i++;ln.textContent=txt.slice(0,i);pos(i);vw.classList.remove('k');void vw.offsetWidth;vw.classList.add('k');t=setTimeout(type,(80+Math.random()*130)/k);}else{t=setTimeout(ret,1000/k);}};
const ret=()=>{el.classList.add('r');old.textContent=ln.textContent;ln.textContent='';i=0;pos(0);t=setTimeout(()=>{el.classList.remove('r');type();},800/k);};
if(rm){ln.textContent=txt;pos(txt.length);}else{t=setTimeout(type,400/k);}
return()=>clearTimeout(t);
}

export default function LdTypewriterCarriage() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#1c1917",
          "--c2": "#b91c1c",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq10-typ" role="status"><span className="sr">Loading…</span><div className="vw" aria-hidden="true"><div className="car"><div className="pap"><span className="old"></span><span className="ln"></span></div><i className="rol"></i></div><i className="tb"></i><i className="gd"></i></div></div>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Typewriter carriage loader” block (Loaders) from AIMRAN Library to my project.

## What it is
A typewriter types the message letter by letter as the carriage moves along, then returns with a line feed.

## Chosen settings
- Main color: #1c1917
- Secondary color: #b91c1c
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Cargando…"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq10-typ {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.uvq10-typ .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.uvq10-typ .vw {
  position: relative;
  width: 12em;
  height: 5em;
  overflow: hidden;
  font: 600 1.3em/1 "Courier New",Courier,ui-monospace,"SF Mono",Menlo,Consolas,monospace;
  -webkit-mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
  mask: linear-gradient(90deg,transparent,#000 1.5em calc(100% - 1.5em),transparent);
}

.uvq10-typ .car {
  position: absolute;
  left: 6em;
  top: 0;
  width: 30ch;
  height: 100%;
  transform: translateX(calc(var(--c,0) * -1ch));
  transition: transform calc(0.08s / var(--k)) ease-out;
}

.uvq10-typ.r .car {
  transition: transform calc(0.55s / var(--k)) cubic-bezier(.3,1.3,.5,1);
}

.uvq10-typ .pap {
  position: absolute;
  left: -14ch;
  width: 46ch;
  top: .2em;
  height: 3.4em;
  background: linear-gradient(#fdfcf7,#f4f0e4);
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

.uvq10-typ.r .pap {
  animation: uvq10-typ-lf calc(0.4s / var(--k)) ease-out;
}

.uvq10-typ .ln,.uvq10-typ .old {
  position: absolute;
  left: 14ch;
  white-space: pre;
  color: var(--c1);
  text-shadow: 0 0 .6px color-mix(in srgb,var(--c1) 60%,transparent);
}

.uvq10-typ .ln {
  top: 2.05em;
}

.uvq10-typ .old {
  top: .85em;
  opacity: .55;
}

.uvq10-typ .rol {
  position: absolute;
  left: -16ch;
  width: 50ch;
  top: 3.15em;
  height: 1.2em;
  border-radius: .6em;
  background: repeating-linear-gradient(90deg,transparent 0 .5ch,rgba(255,255,255,.04) .5ch 1ch),linear-gradient(#5a5a5a,#161616 50%,#2c2c2c);
  box-shadow: 0 .3em .5em -.2em rgba(0,0,0,.5);
}

.uvq10-typ .tb {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 2.05em;
  height: 1em;
  border-radius: .1em;
  background: linear-gradient(#d1d5db,#6b7280);
  opacity: 0;
  transform: translateY(2.4em);
}

.uvq10-typ .vw.k .tb {
  animation: uvq10-typ-k calc(0.12s / var(--k)) ease-out;
}

.uvq10-typ .gd {
  position: absolute;
  left: 6em;
  width: 1ch;
  top: 3.1em;
  height: .45em;
  box-sizing: border-box;
  border: .12em solid var(--c2);
  border-top: 0;
  border-radius: 0 0 .35em .35em;
}

@keyframes uvq10-typ-k {
  0% {
    opacity: 0;
    transform: translateY(2.4em);
  }
  50% {
    opacity: 1;
    transform: translateY(.2em);
  }
  100% {
    opacity: 0;
    transform: translateY(2.4em);
  }
}

@keyframes uvq10-typ-lf {
  from {
    transform: translateY(1.2em);
  }
  to {
    transform: none;
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq10-typ,.uvq10-typ *,.uvq10-typ *::before,.uvq10-typ *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const k=parseFloat(getComputedStyle(el).getPropertyValue('--k'))||1;const rm=matchMedia('(prefers-reduced-motion: reduce)').matches;
const car=el.querySelector('.car'),ln=el.querySelector('.ln'),old=el.querySelector('.old'),vw=el.querySelector('.vw');
const txt=el.querySelector('.sr').textContent||'';
let i=0,t;
const pos=(n)=>car.style.setProperty('--c',String(n));
const type=()=>{if(i<txt.length){i++;ln.textContent=txt.slice(0,i);pos(i);vw.classList.remove('k');void vw.offsetWidth;vw.classList.add('k');t=setTimeout(type,(80+Math.random()*130)/k);}else{t=setTimeout(ret,1000/k);}};
const ret=()=>{el.classList.add('r');old.textContent=ln.textContent;ln.textContent='';i=0;pos(0);t=setTimeout(()=>{el.classList.remove('r');type();},800/k);};
if(rm){ln.textContent=txt;pos(txt.length);}else{t=setTimeout(type,400/k);}
return()=>clearTimeout(t);
}

export default function LdTypewriterCarriage() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#1c1917",
          "--c2": "#b91c1c",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq10-typ" role="status"><span className="sr">Loading…</span><div className="vw" aria-hidden="true"><div className="car"><div className="pap"><span className="old"></span><span className="ln"></span></div><i className="rol"></i></div><i className="tb"></i><i className="gd"></i></div></div>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
