# Stretchtext sentence

> A short paragraph where every underlined word opens up and adds its explanation inside the sentence itself, with no popups.

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

## Where to use it

Stretchtext is an old hypertext idea: instead of sending people elsewhere, the sentence grows in place when they ask for more. Here each underlined word is a disclosure button that reveals a hidden aside with a short unfolding animation and a highlighter flash. It suits pitch paragraphs, pricing explanations and onboarding copy that should stay short until someone is curious.

Change the opening words in the text field and edit the expanded asides in the HTML. The main color marks the toggles and the secondary one tints the flash. The read all button opens every aside at once and closes them again.

## Code

### HTML

```html
<div class="uvq14-str"><p class="kc">Tap the underlined words</p><p class="tx">We build sites <button type="button" aria-expanded="false" aria-controls="uvq14-str-1">fast</button><span class="ex" id="uvq14-str-1" hidden> (they load in under a second, even on a weak signal)</span>, <button type="button" aria-expanded="false" aria-controls="uvq14-str-2">accessible</button><span class="ex" id="uvq14-str-2" hidden> (usable with a keyboard, a screen reader or one hand)</span> y <button type="button" aria-expanded="false" aria-controls="uvq14-str-3">easy to change</button><span class="ex" id="uvq14-str-3" hidden> (your team edits the copy without calling us)</span>.</p><button type="button" class="all" aria-pressed="false">Read it all</button></div>
```

### CSS

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

.uvq14-str {
  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;
  width: 19em;
}

.uvq14-str .kc {
  margin: 0 0 .6em;
  font-size: .68em;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c1);
}

.uvq14-str .tx {
  margin: 0;
  font: 400 1.45em/1.42 "Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
  letter-spacing: -.01em;
}

.uvq14-str .tx button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 0 .05em;
  border-radius: .15em;
  text-decoration: underline dotted color-mix(in srgb,var(--c1) 80%,transparent);
  text-decoration-thickness: .09em;
  text-underline-offset: .18em;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .tx button::after {
  content: "+";
  display: inline-block;
  margin-left: .08em;
  font: 700 .6em/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace;
  vertical-align: .7em;
  color: var(--c1);
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq14-str .tx button:hover {
  background: color-mix(in srgb,var(--c2) 45%,transparent);
}

.uvq14-str .tx button:active {
  background: color-mix(in srgb,var(--c2) 75%,transparent);
}

.uvq14-str .tx button[aria-expanded=true] {
  color: var(--c1);
  text-decoration-style: solid;
}

.uvq14-str .tx button[aria-expanded=true]::after {
  transform: rotate(45deg);
}

.uvq14-str .tx button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: 1px;
}

.uvq14-str .ex {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
  border-radius: .15em;
  animation: uvq14-str-in calc(0.6s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq14-str .ex.out {
  animation: uvq14-str-out calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

.uvq14-str .all {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .55em 1.1em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .all:hover {
  transform: translateY(-2px);
}

.uvq14-str .all:active {
  transform: scale(.95);
}

.uvq14-str .all:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq14-str .all {
  margin-top: 1.1em;
}

.uvq14-str .all[aria-pressed=true] {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

@keyframes uvq14-str-in {
  from {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
    background: color-mix(in srgb,var(--c2) 80%,transparent);
  }
  60% {
    background: color-mix(in srgb,var(--c2) 60%,transparent);
  }
  to {
    background: transparent;
  }
}

@keyframes uvq14-str-out {
  to {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
  }
}

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

### JavaScript

```js
document.querySelectorAll(".uvq14-str").forEach(el => {
  const tg=[...el.querySelectorAll(".tx button")],all=el.querySelector(".all");
const set=(b,on)=>{const x=el.querySelector("#"+b.getAttribute("aria-controls"));b.setAttribute("aria-expanded",String(on));if(on){x.classList.remove("out");x.hidden=false}else if(!x.hidden){x.classList.add("out");x.addEventListener("animationend",()=>{if(b.getAttribute("aria-expanded")==="false"){x.hidden=true;x.classList.remove("out")}},{once:true})}};
const sync=()=>all.setAttribute("aria-pressed",String(tg.every(b=>b.getAttribute("aria-expanded")==="true")));
tg.forEach(b=>b.addEventListener("click",()=>{set(b,b.getAttribute("aria-expanded")!=="true");sync()}));
all.addEventListener("click",()=>{const on=all.getAttribute("aria-pressed")!=="true";tg.forEach(b=>set(b,on));sync()})
});
```

### 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-str {
  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;
  width: 19em;
}

.uvq14-str .kc {
  margin: 0 0 .6em;
  font-size: .68em;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c1);
}

.uvq14-str .tx {
  margin: 0;
  font: 400 1.45em/1.42 "Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
  letter-spacing: -.01em;
}

.uvq14-str .tx button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 0 .05em;
  border-radius: .15em;
  text-decoration: underline dotted color-mix(in srgb,var(--c1) 80%,transparent);
  text-decoration-thickness: .09em;
  text-underline-offset: .18em;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .tx button::after {
  content: "+";
  display: inline-block;
  margin-left: .08em;
  font: 700 .6em/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace;
  vertical-align: .7em;
  color: var(--c1);
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq14-str .tx button:hover {
  background: color-mix(in srgb,var(--c2) 45%,transparent);
}

.uvq14-str .tx button:active {
  background: color-mix(in srgb,var(--c2) 75%,transparent);
}

.uvq14-str .tx button[aria-expanded=true] {
  color: var(--c1);
  text-decoration-style: solid;
}

.uvq14-str .tx button[aria-expanded=true]::after {
  transform: rotate(45deg);
}

.uvq14-str .tx button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: 1px;
}

.uvq14-str .ex {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
  border-radius: .15em;
  animation: uvq14-str-in calc(0.6s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq14-str .ex.out {
  animation: uvq14-str-out calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

.uvq14-str .all {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .55em 1.1em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .all:hover {
  transform: translateY(-2px);
}

.uvq14-str .all:active {
  transform: scale(.95);
}

.uvq14-str .all:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq14-str .all {
  margin-top: 1.1em;
}

.uvq14-str .all[aria-pressed=true] {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

@keyframes uvq14-str-in {
  from {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
    background: color-mix(in srgb,var(--c2) 80%,transparent);
  }
  60% {
    background: color-mix(in srgb,var(--c2) 60%,transparent);
  }
  to {
    background: transparent;
  }
}

@keyframes uvq14-str-out {
  to {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq14-str,.uvq14-str *,.uvq14-str *::before,.uvq14-str *::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 tg=[...el.querySelectorAll(".tx button")],all=el.querySelector(".all");
const set=(b,on)=>{const x=el.querySelector("#"+b.getAttribute("aria-controls"));b.setAttribute("aria-expanded",String(on));if(on){x.classList.remove("out");x.hidden=false}else if(!x.hidden){x.classList.add("out");x.addEventListener("animationend",()=>{if(b.getAttribute("aria-expanded")==="false"){x.hidden=true;x.classList.remove("out")}},{once:true})}};
const sync=()=>all.setAttribute("aria-pressed",String(tg.every(b=>b.getAttribute("aria-expanded")==="true")));
tg.forEach(b=>b.addEventListener("click",()=>{set(b,b.getAttribute("aria-expanded")!=="true");sync()}));
all.addEventListener("click",()=>{const on=all.getAttribute("aria-pressed")!=="true";tg.forEach(b=>set(b,on));sync()})
}

export default function TxStretchtext() {
  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": "#c2410c",
          "--c2": "#fde68a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-str"><p className="kc">Tap the underlined words</p><p className="tx">We build sites <button type="button" aria-expanded="false" aria-controls="uvq14-str-1">fast</button><span className="ex" id="uvq14-str-1" hidden={true}> (they load in under a second, even on a weak signal)</span>, <button type="button" aria-expanded="false" aria-controls="uvq14-str-2">accessible</button><span className="ex" id="uvq14-str-2" hidden={true}> (usable with a keyboard, a screen reader or one hand)</span> y <button type="button" aria-expanded="false" aria-controls="uvq14-str-3">easy to change</button><span className="ex" id="uvq14-str-3" hidden={true}> (your team edits the copy without calling us)</span>.</p><button type="button" className="all" aria-pressed="false">Read it all</button></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 “Stretchtext sentence” block (Text & scroll) from AIMRAN Library to my project.

## What it is
A short paragraph where every underlined word opens up and adds its explanation inside the sentence itself, with no popups.

## Chosen settings
- Main color: #c2410c
- Secondary color: #fde68a
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Hacemos webs"

## 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-str {
  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;
  width: 19em;
}

.uvq14-str .kc {
  margin: 0 0 .6em;
  font-size: .68em;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c1);
}

.uvq14-str .tx {
  margin: 0;
  font: 400 1.45em/1.42 "Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;
  letter-spacing: -.01em;
}

.uvq14-str .tx button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: 0 .05em;
  border-radius: .15em;
  text-decoration: underline dotted color-mix(in srgb,var(--c1) 80%,transparent);
  text-decoration-thickness: .09em;
  text-underline-offset: .18em;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),color calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .tx button::after {
  content: "+";
  display: inline-block;
  margin-left: .08em;
  font: 700 .6em/1 ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace;
  vertical-align: .7em;
  color: var(--c1);
  transition: transform calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq14-str .tx button:hover {
  background: color-mix(in srgb,var(--c2) 45%,transparent);
}

.uvq14-str .tx button:active {
  background: color-mix(in srgb,var(--c2) 75%,transparent);
}

.uvq14-str .tx button[aria-expanded=true] {
  color: var(--c1);
  text-decoration-style: solid;
}

.uvq14-str .tx button[aria-expanded=true]::after {
  transform: rotate(45deg);
}

.uvq14-str .tx button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
  outline-offset: 1px;
}

.uvq14-str .ex {
  font-style: italic;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
  border-radius: .15em;
  animation: uvq14-str-in calc(0.6s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq14-str .ex.out {
  animation: uvq14-str-out calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1) forwards;
}

.uvq14-str .all {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: .55em 1.1em;
  border-radius: 2em;
  font-size: .78em;
  font-weight: 700;
  color: var(--bg);
  background: var(--fg);
  transition: transform calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),opacity calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-str .all:hover {
  transform: translateY(-2px);
}

.uvq14-str .all:active {
  transform: scale(.95);
}

.uvq14-str .all:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq14-str .all {
  margin-top: 1.1em;
}

.uvq14-str .all[aria-pressed=true] {
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 7%,transparent);
}

@keyframes uvq14-str-in {
  from {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
    background: color-mix(in srgb,var(--c2) 80%,transparent);
  }
  60% {
    background: color-mix(in srgb,var(--c2) 60%,transparent);
  }
  to {
    background: transparent;
  }
}

@keyframes uvq14-str-out {
  to {
    opacity: 0;
    letter-spacing: -.4em;
    filter: blur(3px);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq14-str,.uvq14-str *,.uvq14-str *::before,.uvq14-str *::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 tg=[...el.querySelectorAll(".tx button")],all=el.querySelector(".all");
const set=(b,on)=>{const x=el.querySelector("#"+b.getAttribute("aria-controls"));b.setAttribute("aria-expanded",String(on));if(on){x.classList.remove("out");x.hidden=false}else if(!x.hidden){x.classList.add("out");x.addEventListener("animationend",()=>{if(b.getAttribute("aria-expanded")==="false"){x.hidden=true;x.classList.remove("out")}},{once:true})}};
const sync=()=>all.setAttribute("aria-pressed",String(tg.every(b=>b.getAttribute("aria-expanded")==="true")));
tg.forEach(b=>b.addEventListener("click",()=>{set(b,b.getAttribute("aria-expanded")!=="true");sync()}));
all.addEventListener("click",()=>{const on=all.getAttribute("aria-pressed")!=="true";tg.forEach(b=>set(b,on));sync()})
}

export default function TxStretchtext() {
  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": "#c2410c",
          "--c2": "#fde68a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-str"><p className="kc">Tap the underlined words</p><p className="tx">We build sites <button type="button" aria-expanded="false" aria-controls="uvq14-str-1">fast</button><span className="ex" id="uvq14-str-1" hidden={true}> (they load in under a second, even on a weak signal)</span>, <button type="button" aria-expanded="false" aria-controls="uvq14-str-2">accessible</button><span className="ex" id="uvq14-str-2" hidden={true}> (usable with a keyboard, a screen reader or one hand)</span> y <button type="button" aria-expanded="false" aria-controls="uvq14-str-3">easy to change</button><span className="ex" id="uvq14-str-3" hidden={true}> (your team edits the copy without calling us)</span>.</p><button type="button" className="all" aria-pressed="false">Read it all</button></div>
      </div>
    </>
  );
}
```

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