# Coin flip toggle

> A coin hops and spins in 3D to go from the euro side to the dollar side.

- Category: [Toggles](https://library.aimran.es/components/toggles)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tg-coin-flip
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

This switch is a two-sided coin: a gold face with the euro sign and a silver face with the dollar sign. Changing it tosses the coin up a little and spins it several times in 3D before it lands on the other face, while its shadow shrinks and grows on the ground. Faces use backface-visibility, and a short script replays the hop. It suits currency selectors, pricing pages and shops.

The two colors set the metal of each face. Swap the symbols in the HTML for pounds, yen or any pair of options, and keep the label clear about what the active side means.

## Code

### HTML

```html
<label class="uvq03-con"><input type="checkbox" role="switch"><span class="st"><span class="cn"><b class="f a">€</b><b class="f b">$</b></span><i class="sd"></i></span>Prices in dollars</label>
```

### CSS

```css
.uvq03-con {
  --c1: #e8b53a;
  --c2: #b8c1cc;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq03-con {
  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;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-con input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-con .st {
  position: relative;
  display: block;
  flex: none;
  width: 3em;
  height: 4.2em;
  perspective: 12em;
}

.uvq03-con .cn {
  position: absolute;
  left: .2em;
  top: 1em;
  width: 2.6em;
  height: 2.6em;
  border-radius: 50%;
  transform-style: preserve-3d;
  transition: transform calc(1s / var(--k)) cubic-bezier(.22,1,.36,1),rotate calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con .f {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  font: 800 1.3em/1 Georgia,"Times New Roman",serif;
}

.uvq03-con .a {
  color: color-mix(in srgb,var(--c1) 45%,#4a3000);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c1) 45%,#fff),var(--c1) 50%,color-mix(in srgb,var(--c1) 70%,#4a3000));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c1) 75%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c1) 55%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c1) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
}

.uvq03-con .b {
  color: color-mix(in srgb,var(--c2) 40%,#1d2430);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c2) 40%,#fff),var(--c2) 50%,color-mix(in srgb,var(--c2) 65%,#2a3038));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c2) 70%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c2) 50%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c2) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
  transform: rotateY(180deg);
}

.uvq03-con .sd {
  position: absolute;
  left: .5em;
  right: .5em;
  bottom: 0;
  height: .4em;
  border-radius: 50%;
  background: radial-gradient(closest-side,rgba(0,0,0,.35),transparent);
}

.uvq03-con:hover .cn {
  rotate: x 14deg;
}

.uvq03-con:active .cn {
  scale: .94;
}

.uvq03-con input:checked + .st .cn {
  transform: rotateY(900deg);
}

.uvq03-con.ts .cn {
  animation: uvq03-con calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con.ts .sd {
  animation: uvq03-con-s calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq03-con {
  45% {
    translate: 0 -1em;
  }
}

@keyframes uvq03-con-s {
  45% {
    transform: scale(.55);
    opacity: .5;
  }
}

.uvq03-con input:focus-visible + .st .cn {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

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

### JavaScript

```js
document.querySelectorAll(".uvq03-con").forEach(el => {
  const i=el.querySelector("input"),t=el;const f=()=>{t.classList.remove("ts");void t.offsetWidth;t.classList.add("ts")};i.addEventListener("change",f);return()=>i.removeEventListener("change",f)
});
```

### 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 = `
.uvq03-con {
  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;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-con input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-con .st {
  position: relative;
  display: block;
  flex: none;
  width: 3em;
  height: 4.2em;
  perspective: 12em;
}

.uvq03-con .cn {
  position: absolute;
  left: .2em;
  top: 1em;
  width: 2.6em;
  height: 2.6em;
  border-radius: 50%;
  transform-style: preserve-3d;
  transition: transform calc(1s / var(--k)) cubic-bezier(.22,1,.36,1),rotate calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con .f {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  font: 800 1.3em/1 Georgia,"Times New Roman",serif;
}

.uvq03-con .a {
  color: color-mix(in srgb,var(--c1) 45%,#4a3000);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c1) 45%,#fff),var(--c1) 50%,color-mix(in srgb,var(--c1) 70%,#4a3000));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c1) 75%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c1) 55%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c1) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
}

.uvq03-con .b {
  color: color-mix(in srgb,var(--c2) 40%,#1d2430);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c2) 40%,#fff),var(--c2) 50%,color-mix(in srgb,var(--c2) 65%,#2a3038));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c2) 70%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c2) 50%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c2) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
  transform: rotateY(180deg);
}

.uvq03-con .sd {
  position: absolute;
  left: .5em;
  right: .5em;
  bottom: 0;
  height: .4em;
  border-radius: 50%;
  background: radial-gradient(closest-side,rgba(0,0,0,.35),transparent);
}

.uvq03-con:hover .cn {
  rotate: x 14deg;
}

.uvq03-con:active .cn {
  scale: .94;
}

.uvq03-con input:checked + .st .cn {
  transform: rotateY(900deg);
}

.uvq03-con.ts .cn {
  animation: uvq03-con calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con.ts .sd {
  animation: uvq03-con-s calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq03-con {
  45% {
    translate: 0 -1em;
  }
}

@keyframes uvq03-con-s {
  45% {
    transform: scale(.55);
    opacity: .5;
  }
}

.uvq03-con input:focus-visible + .st .cn {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-con,.uvq03-con *,.uvq03-con *::before,.uvq03-con *::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 i=el.querySelector("input"),t=el;const f=()=>{t.classList.remove("ts");void t.offsetWidth;t.classList.add("ts")};i.addEventListener("change",f);return()=>i.removeEventListener("change",f)
}

export default function TgCoinFlip() {
  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": "#e8b53a",
          "--c2": "#b8c1cc",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-con"><input type="checkbox" role="switch" /><span className="st"><span className="cn"><b className="f a">€</b><b className="f b">$</b></span><i className="sd"></i></span>Prices in dollars</label>
      </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 “Coin flip toggle” block (Toggles) from AIMRAN Library to my project.

## What it is
A coin hops and spins in 3D to go from the euro side to the dollar side.

## Chosen settings
- Main color: #e8b53a
- Secondary color: #b8c1cc
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Precios en dólares"

## 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 = `
.uvq03-con {
  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;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-con input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-con .st {
  position: relative;
  display: block;
  flex: none;
  width: 3em;
  height: 4.2em;
  perspective: 12em;
}

.uvq03-con .cn {
  position: absolute;
  left: .2em;
  top: 1em;
  width: 2.6em;
  height: 2.6em;
  border-radius: 50%;
  transform-style: preserve-3d;
  transition: transform calc(1s / var(--k)) cubic-bezier(.22,1,.36,1),rotate calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1),scale calc(0.15s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con .f {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  font: 800 1.3em/1 Georgia,"Times New Roman",serif;
}

.uvq03-con .a {
  color: color-mix(in srgb,var(--c1) 45%,#4a3000);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c1) 45%,#fff),var(--c1) 50%,color-mix(in srgb,var(--c1) 70%,#4a3000));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c1) 75%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c1) 55%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c1) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
}

.uvq03-con .b {
  color: color-mix(in srgb,var(--c2) 40%,#1d2430);
  background: radial-gradient(circle,transparent 60%,rgba(0,0,0,.18) 61% 63%,transparent 64%),radial-gradient(circle at 35% 30%,color-mix(in srgb,var(--c2) 40%,#fff),var(--c2) 50%,color-mix(in srgb,var(--c2) 65%,#2a3038));
  box-shadow: inset 0 0 0 .1em color-mix(in srgb,var(--c2) 70%,#000),inset 0 0 0 .16em color-mix(in srgb,var(--c2) 50%,#fff);
  text-shadow: 0 1px 0 color-mix(in srgb,var(--c2) 45%,#fff),0 -1px 0 rgba(0,0,0,.3);
  transform: rotateY(180deg);
}

.uvq03-con .sd {
  position: absolute;
  left: .5em;
  right: .5em;
  bottom: 0;
  height: .4em;
  border-radius: 50%;
  background: radial-gradient(closest-side,rgba(0,0,0,.35),transparent);
}

.uvq03-con:hover .cn {
  rotate: x 14deg;
}

.uvq03-con:active .cn {
  scale: .94;
}

.uvq03-con input:checked + .st .cn {
  transform: rotateY(900deg);
}

.uvq03-con.ts .cn {
  animation: uvq03-con calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-con.ts .sd {
  animation: uvq03-con-s calc(1s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

@keyframes uvq03-con {
  45% {
    translate: 0 -1em;
  }
}

@keyframes uvq03-con-s {
  45% {
    transform: scale(.55);
    opacity: .5;
  }
}

.uvq03-con input:focus-visible + .st .cn {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-con,.uvq03-con *,.uvq03-con *::before,.uvq03-con *::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 i=el.querySelector("input"),t=el;const f=()=>{t.classList.remove("ts");void t.offsetWidth;t.classList.add("ts")};i.addEventListener("change",f);return()=>i.removeEventListener("change",f)
}

export default function TgCoinFlip() {
  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": "#e8b53a",
          "--c2": "#b8c1cc",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-con"><input type="checkbox" role="switch" /><span className="st"><span className="cn"><b className="f a">€</b><b className="f b">$</b></span><i className="sd"></i></span>Prices in dollars</label>
      </div>
    </>
  );
}
```

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