# Sentence-style filter

> Filters that read as a sentence: tap each underlined phrase and it rolls to the next option.

- Category: [Filters](https://library.aimran.es/components/filters)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-f-sentence
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Natural-language filters suit property, travel and booking sites where a full form feels heavy. The sentence is set in a serif face, and each underlined phrase is a button that cycles through its options on click or with the arrow keys, rolling the new words in from below while the result count updates with a small bounce.

The first colour styles the phrases and their dotted underline, the second the hover highlight. Edit the option arrays in the script to build your own sentence, and keep every option a similar length so the line does not jump.

## Code

### HTML

```html
<div class="uvq05-st"><p class="ph"><span>I'm looking for</span> <button type="button" data-k="0"><span>a flat</span></button> <button type="button" data-k="1"><span>with a terrace</span></button> <button type="button" data-k="2"><span>in the centre</span></button> <button type="button" data-k="3"><span>up to 900 €</span></button></p><p class="rs"><b>16</b> <span>results</span></p><p class="hn">Tap the underlined words to change them</p></div>
```

### CSS

```css
.uvq05-st {
  --c1: #2f6b4f;
  --c2: #dcefe3;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq05-st {
  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;
}

.uvq05-st .ph {
  margin: 0;
  font: 400 1.45em/1.55 Georgia,"Iowan Old Style","Times New Roman",serif;
  letter-spacing: -.01em;
}

.uvq05-st .ph button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-block;
  padding: 0 .12em;
  border-radius: .2em;
  font-style: italic;
  line-height: 1.25;
  color: color-mix(in srgb,var(--c1) 82%,var(--fg));
  vertical-align: bottom;
  overflow: hidden;
  background: linear-gradient(var(--c2),var(--c2)) 0 100%/100% 0 no-repeat;
  transition: background-size calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq05-st .ph button::after {
  content: "";
  position: absolute;
  left: .12em;
  right: .12em;
  bottom: .06em;
  height: 2px;
  background: repeating-linear-gradient(90deg,var(--c1) 0 .18em,transparent .18em .3em);
}

.uvq05-st .ph button:hover {
  background-size: 100% 100%;
}

.uvq05-st .ph button:active {
  transform: translateY(1px);
}

.uvq05-st .ph button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq05-st .ph button span {
  display: inline-block;
}

.uvq05-st .ph button span.in {
  animation: uvq05-sti calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq05-st .ph button span.in.up {
  animation-name: uvq05-stu;
}

.uvq05-st .rs {
  display: flex;
  align-items: baseline;
  gap: .3em;
  margin: .9em 0 0;
  font-size: .85em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq05-st .rs b {
  font-size: 1.5em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.uvq05-st .rs.is-p b {
  animation: uvq05-stp calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq05-st .hn {
  margin: .25em 0 0;
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

@keyframes uvq05-sti {
  from {
    transform: translateY(.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stu {
  from {
    transform: translateY(-.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stp {
  40% {
    transform: scale(1.15);
  }
}

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

### JavaScript

```js
document.querySelectorAll(".uvq05-st").forEach(el => {
  const O=[["a flat","a house","a studio","a penthouse"],["with a terrace","with a garden","with a garage","unfurnished"],["in the centre","near the sea","on the outskirts","next to the park"],["up to 900 €","up to 1,200 €","up to 1,500 €","with no price limit"]];const bs=[...el.querySelectorAll(".ph button")],rs=el.querySelector(".rs b"),ix=[0,0,0,0];
const count=()=>{let h=7;ix.forEach((v,i)=>{h=(h*31+v*17+i*5)%997});return 12+h%240};
const set=(b,i,d)=>{ix[i]=(ix[i]+d+O[i].length)%O[i].length;const s=document.createElement("span");s.textContent=O[i][ix[i]];s.className=d>0?"in":"in up";b.replaceChildren(s);rs.textContent=count();rs.parentElement.classList.remove("is-p");void rs.offsetWidth;rs.parentElement.classList.add("is-p")};
bs.forEach((b,i)=>{b.addEventListener("click",()=>set(b,i,1));b.addEventListener("keydown",e=>{if(e.key==="ArrowDown"||e.key==="ArrowRight"){e.preventDefault();set(b,i,1)}else if(e.key==="ArrowUp"||e.key==="ArrowLeft"){e.preventDefault();set(b,i,-1)}})})
});
```

### 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 = `
.uvq05-st {
  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;
}

.uvq05-st .ph {
  margin: 0;
  font: 400 1.45em/1.55 Georgia,"Iowan Old Style","Times New Roman",serif;
  letter-spacing: -.01em;
}

.uvq05-st .ph button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-block;
  padding: 0 .12em;
  border-radius: .2em;
  font-style: italic;
  line-height: 1.25;
  color: color-mix(in srgb,var(--c1) 82%,var(--fg));
  vertical-align: bottom;
  overflow: hidden;
  background: linear-gradient(var(--c2),var(--c2)) 0 100%/100% 0 no-repeat;
  transition: background-size calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq05-st .ph button::after {
  content: "";
  position: absolute;
  left: .12em;
  right: .12em;
  bottom: .06em;
  height: 2px;
  background: repeating-linear-gradient(90deg,var(--c1) 0 .18em,transparent .18em .3em);
}

.uvq05-st .ph button:hover {
  background-size: 100% 100%;
}

.uvq05-st .ph button:active {
  transform: translateY(1px);
}

.uvq05-st .ph button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq05-st .ph button span {
  display: inline-block;
}

.uvq05-st .ph button span.in {
  animation: uvq05-sti calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq05-st .ph button span.in.up {
  animation-name: uvq05-stu;
}

.uvq05-st .rs {
  display: flex;
  align-items: baseline;
  gap: .3em;
  margin: .9em 0 0;
  font-size: .85em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq05-st .rs b {
  font-size: 1.5em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.uvq05-st .rs.is-p b {
  animation: uvq05-stp calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq05-st .hn {
  margin: .25em 0 0;
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

@keyframes uvq05-sti {
  from {
    transform: translateY(.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stu {
  from {
    transform: translateY(-.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stp {
  40% {
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq05-st,.uvq05-st *,.uvq05-st *::before,.uvq05-st *::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 O=[["a flat","a house","a studio","a penthouse"],["with a terrace","with a garden","with a garage","unfurnished"],["in the centre","near the sea","on the outskirts","next to the park"],["up to 900 €","up to 1,200 €","up to 1,500 €","with no price limit"]];const bs=[...el.querySelectorAll(".ph button")],rs=el.querySelector(".rs b"),ix=[0,0,0,0];
const count=()=>{let h=7;ix.forEach((v,i)=>{h=(h*31+v*17+i*5)%997});return 12+h%240};
const set=(b,i,d)=>{ix[i]=(ix[i]+d+O[i].length)%O[i].length;const s=document.createElement("span");s.textContent=O[i][ix[i]];s.className=d>0?"in":"in up";b.replaceChildren(s);rs.textContent=count();rs.parentElement.classList.remove("is-p");void rs.offsetWidth;rs.parentElement.classList.add("is-p")};
bs.forEach((b,i)=>{b.addEventListener("click",()=>set(b,i,1));b.addEventListener("keydown",e=>{if(e.key==="ArrowDown"||e.key==="ArrowRight"){e.preventDefault();set(b,i,1)}else if(e.key==="ArrowUp"||e.key==="ArrowLeft"){e.preventDefault();set(b,i,-1)}})})
}

export default function FSentence() {
  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": "#2f6b4f",
          "--c2": "#dcefe3",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq05-st"><p className="ph"><span>I'm looking for</span> <button type="button" data-k="0"><span>a flat</span></button> <button type="button" data-k="1"><span>with a terrace</span></button> <button type="button" data-k="2"><span>in the centre</span></button> <button type="button" data-k="3"><span>up to 900 €</span></button></p><p className="rs"><b>16</b> <span>results</span></p><p className="hn">Tap the underlined words to change them</p></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-style filter” block (Filters) from AIMRAN Library to my project.

## What it is
Filters that read as a sentence: tap each underlined phrase and it rolls to the next option.

## Chosen settings
- Main color: #2f6b4f
- Secondary color: #dcefe3
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Busco"

## 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 = `
.uvq05-st {
  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;
}

.uvq05-st .ph {
  margin: 0;
  font: 400 1.45em/1.55 Georgia,"Iowan Old Style","Times New Roman",serif;
  letter-spacing: -.01em;
}

.uvq05-st .ph button {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-block;
  padding: 0 .12em;
  border-radius: .2em;
  font-style: italic;
  line-height: 1.25;
  color: color-mix(in srgb,var(--c1) 82%,var(--fg));
  vertical-align: bottom;
  overflow: hidden;
  background: linear-gradient(var(--c2),var(--c2)) 0 100%/100% 0 no-repeat;
  transition: background-size calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq05-st .ph button::after {
  content: "";
  position: absolute;
  left: .12em;
  right: .12em;
  bottom: .06em;
  height: 2px;
  background: repeating-linear-gradient(90deg,var(--c1) 0 .18em,transparent .18em .3em);
}

.uvq05-st .ph button:hover {
  background-size: 100% 100%;
}

.uvq05-st .ph button:active {
  transform: translateY(1px);
}

.uvq05-st .ph button:focus-visible {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

.uvq05-st .ph button span {
  display: inline-block;
}

.uvq05-st .ph button span.in {
  animation: uvq05-sti calc(0.35s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq05-st .ph button span.in.up {
  animation-name: uvq05-stu;
}

.uvq05-st .rs {
  display: flex;
  align-items: baseline;
  gap: .3em;
  margin: .9em 0 0;
  font-size: .85em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq05-st .rs b {
  font-size: 1.5em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.uvq05-st .rs.is-p b {
  animation: uvq05-stp calc(0.35s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq05-st .hn {
  margin: .25em 0 0;
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

@keyframes uvq05-sti {
  from {
    transform: translateY(.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stu {
  from {
    transform: translateY(-.9em);
    opacity: 0;
  }
}

@keyframes uvq05-stp {
  40% {
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion:reduce) {
  .uvq05-st,.uvq05-st *,.uvq05-st *::before,.uvq05-st *::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 O=[["a flat","a house","a studio","a penthouse"],["with a terrace","with a garden","with a garage","unfurnished"],["in the centre","near the sea","on the outskirts","next to the park"],["up to 900 €","up to 1,200 €","up to 1,500 €","with no price limit"]];const bs=[...el.querySelectorAll(".ph button")],rs=el.querySelector(".rs b"),ix=[0,0,0,0];
const count=()=>{let h=7;ix.forEach((v,i)=>{h=(h*31+v*17+i*5)%997});return 12+h%240};
const set=(b,i,d)=>{ix[i]=(ix[i]+d+O[i].length)%O[i].length;const s=document.createElement("span");s.textContent=O[i][ix[i]];s.className=d>0?"in":"in up";b.replaceChildren(s);rs.textContent=count();rs.parentElement.classList.remove("is-p");void rs.offsetWidth;rs.parentElement.classList.add("is-p")};
bs.forEach((b,i)=>{b.addEventListener("click",()=>set(b,i,1));b.addEventListener("keydown",e=>{if(e.key==="ArrowDown"||e.key==="ArrowRight"){e.preventDefault();set(b,i,1)}else if(e.key==="ArrowUp"||e.key==="ArrowLeft"){e.preventDefault();set(b,i,-1)}})})
}

export default function FSentence() {
  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": "#2f6b4f",
          "--c2": "#dcefe3",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq05-st"><p className="ph"><span>I'm looking for</span> <button type="button" data-k="0"><span>a flat</span></button> <button type="button" data-k="1"><span>with a terrace</span></button> <button type="button" data-k="2"><span>in the centre</span></button> <button type="button" data-k="3"><span>up to 900 €</span></button></p><p className="rs"><b>16</b> <span>results</span></p><p className="hn">Tap the underlined words to change them</p></div>
      </div>
    </>
  );
}
```

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