# Sentence riding a wave on scroll

> Two sentences travel in opposite directions along two drawn curves; their place on the line depends on how far you scroll.

- Category: [Text & scroll](https://library.aimran.es/components/text-scroll)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tx-wave-path
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Text on a path feels hand placed, and tying it to scroll turns reading into a small journey. This block sets two phrases on SVG curves with textPath and moves their start offset with the scroll progress of their own container, while a thin bar shows how far along you are. It suits manifestos, about pages and slow storytelling sections.

Write your main sentence in the text field and the secondary one in the SVG. The main color paints the big phrase and the progress bar, the secondary one the small caps line. Edit the path to draw a calmer or wilder wave.

## Code

### HTML

```html
<div class="uvq14-wav"><div class="sc" tabindex="0" aria-label="Good ideas always find their way"><div class="tr"><div class="st"><p class="sr">Good ideas always find their way</p><svg viewBox="0 0 400 230" aria-hidden="true"><path id="uvq14-wav-a" class="g" d="M-30 92C40 22 110 162 200 92S330 22 430 92"/><path id="uvq14-wav-b" class="g" d="M-30 172C50 112 120 232 200 172S340 112 430 172"/><text class="t1"><textPath href="#uvq14-wav-a">Good ideas always find their way</textPath></text><text class="t2"><textPath href="#uvq14-wav-b">slowly · no rush · step by step</textPath></text></svg><span class="pc" aria-hidden="true"><i></i></span></div></div></div><span class="hn" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M6 13l6 6 6-6"/></svg>Scroll</span></div>
```

### CSS

```css
.uvq14-wav {
  --c1: #0369a1;
  --c2: #f59e0b;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq14-wav {
  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;
  width: 22em;
  height: 17em;
  border-radius: 1.3em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq14-wav .sc {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  outline: 0;
}

.uvq14-wav .tr {
  height: 320%;
}

.uvq14-wav .st {
  position: sticky;
  top: 0;
  height: 17em;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(90% 70% at 50% 110%,color-mix(in srgb,var(--c2) 22%,transparent),transparent 70%);
}

.uvq14-wav svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.uvq14-wav .g {
  fill: none;
  stroke: color-mix(in srgb,var(--fg) 14%,transparent);
  stroke-width: 1.2;
  stroke-dasharray: 3 6;
}

.uvq14-wav .t1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.5px;
  fill: color-mix(in srgb,var(--c1) 82%,var(--fg));
}

.uvq14-wav .t2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  fill: var(--c2);
}

.uvq14-wav .pc {
  position: absolute;
  left: 1.2em;
  right: 1.2em;
  top: 1em;
  height: .25em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uvq14-wav .pc i {
  display: block;
  height: 100%;
  width: calc(var(--p,0) * 100%);
  border-radius: inherit;
  background: var(--c1);
}

.uvq14-wav .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.uvq14-wav .hn {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .3em;
  padding: .35em .7em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  translate: -50% 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
  animation: uvq14-wav-h calc(1.6s / var(--k)) ease-in-out infinite;
}

.uvq14-wav .hn svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq14-wav.moved .hn {
  opacity: 0;
}

.uvq14-wav .sc:focus-visible {
  box-shadow: inset 0 0 0 2px var(--c1);
  border-radius: 1.3em;
}

@keyframes uvq14-wav-h {
  50% {
    transform: translateY(.25em);
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq14-wav").forEach(el => {
  const tp=[...el.querySelectorAll("textPath")],ph=[...el.querySelectorAll("path.g")];let p=0;const place=()=>{p=parseFloat(el.style.getPropertyValue("--p"))||0;tp.forEach((t,i)=>{const L=ph[i].getTotalLength(),w=t.parentNode.getComputedTextLength(),q=i?1-p:p,o=L*.04+q*(L*.92-w-L*.04);t.setAttribute("startOffset",o.toFixed(1))})};const sc=el.querySelector(".sc");const u=()=>{const m=sc.scrollHeight-sc.clientHeight;const p=m>0?sc.scrollTop/m:0;el.style.setProperty("--p",p.toFixed(4));el.classList.toggle("moved",sc.scrollTop>8);place()};sc.addEventListener("scroll",u,{passive:true});const ro=new ResizeObserver(u);ro.observe(sc);u();const mo=new MutationObserver(place);el.querySelectorAll("textPath").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>{ro.disconnect();mo.disconnect()}
});
```

### 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 = `
.uvq14-wav {
  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;
  width: 22em;
  height: 17em;
  border-radius: 1.3em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq14-wav .sc {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  outline: 0;
}

.uvq14-wav .tr {
  height: 320%;
}

.uvq14-wav .st {
  position: sticky;
  top: 0;
  height: 17em;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(90% 70% at 50% 110%,color-mix(in srgb,var(--c2) 22%,transparent),transparent 70%);
}

.uvq14-wav svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.uvq14-wav .g {
  fill: none;
  stroke: color-mix(in srgb,var(--fg) 14%,transparent);
  stroke-width: 1.2;
  stroke-dasharray: 3 6;
}

.uvq14-wav .t1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.5px;
  fill: color-mix(in srgb,var(--c1) 82%,var(--fg));
}

.uvq14-wav .t2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  fill: var(--c2);
}

.uvq14-wav .pc {
  position: absolute;
  left: 1.2em;
  right: 1.2em;
  top: 1em;
  height: .25em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uvq14-wav .pc i {
  display: block;
  height: 100%;
  width: calc(var(--p,0) * 100%);
  border-radius: inherit;
  background: var(--c1);
}

.uvq14-wav .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.uvq14-wav .hn {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .3em;
  padding: .35em .7em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  translate: -50% 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
  animation: uvq14-wav-h calc(1.6s / var(--k)) ease-in-out infinite;
}

.uvq14-wav .hn svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq14-wav.moved .hn {
  opacity: 0;
}

.uvq14-wav .sc:focus-visible {
  box-shadow: inset 0 0 0 2px var(--c1);
  border-radius: 1.3em;
}

@keyframes uvq14-wav-h {
  50% {
    transform: translateY(.25em);
  }
}
`;

// 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 tp=[...el.querySelectorAll("textPath")],ph=[...el.querySelectorAll("path.g")];let p=0;const place=()=>{p=parseFloat(el.style.getPropertyValue("--p"))||0;tp.forEach((t,i)=>{const L=ph[i].getTotalLength(),w=t.parentNode.getComputedTextLength(),q=i?1-p:p,o=L*.04+q*(L*.92-w-L*.04);t.setAttribute("startOffset",o.toFixed(1))})};const sc=el.querySelector(".sc");const u=()=>{const m=sc.scrollHeight-sc.clientHeight;const p=m>0?sc.scrollTop/m:0;el.style.setProperty("--p",p.toFixed(4));el.classList.toggle("moved",sc.scrollTop>8);place()};sc.addEventListener("scroll",u,{passive:true});const ro=new ResizeObserver(u);ro.observe(sc);u();const mo=new MutationObserver(place);el.querySelectorAll("textPath").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>{ro.disconnect();mo.disconnect()}
}

export default function TxWavePath() {
  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": "#0369a1",
          "--c2": "#f59e0b",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-wav"><div className="sc" tabIndex={0} aria-label="Good ideas always find their way"><div className="tr"><div className="st"><p className="sr">Good ideas always find their way</p><svg viewBox="0 0 400 230" aria-hidden="true"><path id="uvq14-wav-a" className="g" d="M-30 92C40 22 110 162 200 92S330 22 430 92" /><path id="uvq14-wav-b" className="g" d="M-30 172C50 112 120 232 200 172S340 112 430 172" /><text className="t1"><textPath href="#uvq14-wav-a">Good ideas always find their way</textPath></text><text className="t2"><textPath href="#uvq14-wav-b">slowly · no rush · step by step</textPath></text></svg><span className="pc" aria-hidden="true"><i></i></span></div></div></div><span className="hn" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M6 13l6 6 6-6" /></svg>Scroll</span></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 “Sentence riding a wave on scroll” block (Text & scroll) from AIMRAN Library to my project.

## What it is
Two sentences travel in opposite directions along two drawn curves; their place on the line depends on how far you scroll.

## Chosen settings
- Main color: #0369a1
- Secondary color: #f59e0b
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Las buenas ideas siempre encuentran su camino"

## 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 = `
.uvq14-wav {
  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;
  width: 22em;
  height: 17em;
  border-radius: 1.3em;
  overflow: hidden;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 10%,transparent);
}

.uvq14-wav .sc {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  outline: 0;
}

.uvq14-wav .tr {
  height: 320%;
}

.uvq14-wav .st {
  position: sticky;
  top: 0;
  height: 17em;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(90% 70% at 50% 110%,color-mix(in srgb,var(--c2) 22%,transparent),transparent 70%);
}

.uvq14-wav svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.uvq14-wav .g {
  fill: none;
  stroke: color-mix(in srgb,var(--fg) 14%,transparent);
  stroke-width: 1.2;
  stroke-dasharray: 3 6;
}

.uvq14-wav .t1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.5px;
  fill: color-mix(in srgb,var(--c1) 82%,var(--fg));
}

.uvq14-wav .t2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  fill: var(--c2);
}

.uvq14-wav .pc {
  position: absolute;
  left: 1.2em;
  right: 1.2em;
  top: 1em;
  height: .25em;
  border-radius: 1em;
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

.uvq14-wav .pc i {
  display: block;
  height: 100%;
  width: calc(var(--p,0) * 100%);
  border-radius: inherit;
  background: var(--c1);
}

.uvq14-wav .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.uvq14-wav .hn {
  position: absolute;
  left: 50%;
  bottom: .8em;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: .3em;
  padding: .35em .7em;
  border-radius: 2em;
  font-size: .7em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  translate: -50% 0;
  pointer-events: none;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
  animation: uvq14-wav-h calc(1.6s / var(--k)) ease-in-out infinite;
}

.uvq14-wav .hn svg {
  width: 1.1em;
  height: 1.1em;
}

.uvq14-wav.moved .hn {
  opacity: 0;
}

.uvq14-wav .sc:focus-visible {
  box-shadow: inset 0 0 0 2px var(--c1);
  border-radius: 1.3em;
}

@keyframes uvq14-wav-h {
  50% {
    transform: translateY(.25em);
  }
}
`;

// 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 tp=[...el.querySelectorAll("textPath")],ph=[...el.querySelectorAll("path.g")];let p=0;const place=()=>{p=parseFloat(el.style.getPropertyValue("--p"))||0;tp.forEach((t,i)=>{const L=ph[i].getTotalLength(),w=t.parentNode.getComputedTextLength(),q=i?1-p:p,o=L*.04+q*(L*.92-w-L*.04);t.setAttribute("startOffset",o.toFixed(1))})};const sc=el.querySelector(".sc");const u=()=>{const m=sc.scrollHeight-sc.clientHeight;const p=m>0?sc.scrollTop/m:0;el.style.setProperty("--p",p.toFixed(4));el.classList.toggle("moved",sc.scrollTop>8);place()};sc.addEventListener("scroll",u,{passive:true});const ro=new ResizeObserver(u);ro.observe(sc);u();const mo=new MutationObserver(place);el.querySelectorAll("textPath").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>{ro.disconnect();mo.disconnect()}
}

export default function TxWavePath() {
  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": "#0369a1",
          "--c2": "#f59e0b",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-wav"><div className="sc" tabIndex={0} aria-label="Good ideas always find their way"><div className="tr"><div className="st"><p className="sr">Good ideas always find their way</p><svg viewBox="0 0 400 230" aria-hidden="true"><path id="uvq14-wav-a" className="g" d="M-30 92C40 22 110 162 200 92S330 22 430 92" /><path id="uvq14-wav-b" className="g" d="M-30 172C50 112 120 232 200 172S340 112 430 172" /><text className="t1"><textPath href="#uvq14-wav-a">Good ideas always find their way</textPath></text><text className="t2"><textPath href="#uvq14-wav-b">slowly · no rush · step by step</textPath></text></svg><span className="pc" aria-hidden="true"><i></i></span></div></div></div><span className="hn" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M12 5v14M6 13l6 6 6-6" /></svg>Scroll</span></div>
      </div>
    </>
  );
}
```

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