# 3D flip card

> A card that turns over in 3D on hover to show a second face on its back.

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

## Where to use it

A flip card hides a second layer of information behind the first. It is handy for team pages (photo on the front, a short bio on the back), vocabulary flashcards in a language course or a services page where the front names the service and the back lists what's included. It turns with a slight bounce.

On touch screens, whether the card flips on tap depends on the browser, so never hide anything essential on the back. The card has a fixed height; keep the back text to a few lines or it will overflow.

## Code

### HTML

```html
<div class="uv-kf"><div class="in"><div class="f"><h3>Hover over me</h3><p>Front</p></div><div class="b"><h3>Hi!</h3><p>This is the back of the card.</p></div></div></div>
```

### CSS

```css
.uv-kf {
  --c1: #0071e3;
  --c2: #8ec5ff;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uv-kf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  width: 14em;
  height: 17em;
  font-size: var(--s);
  perspective: 60em;
}

.uv-kf .in {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-kf:hover .in {
  transform: rotateY(180deg);
}

.uv-kf .f,.uv-kf .b {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5em;
  border-radius: 1.4em;
  backface-visibility: hidden;
}

.uv-kf .f {
  background: linear-gradient(160deg,var(--c2),var(--c1));
  color: #fff;
  box-shadow: 0 20px 40px -20px var(--c1);
}

.uv-kf .b {
  background: var(--bg);
  color: var(--fg);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-kf h3 {
  margin: 0;
  font-size: 1.3em;
}

.uv-kf p {
  margin: .3em 0 0;
  font-size: .85em;
  opacity: .7;
}
```

### React

```tsx
import type { CSSProperties } from "react";

const css = `
.uv-kf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  width: 14em;
  height: 17em;
  font-size: var(--s);
  perspective: 60em;
}

.uv-kf .in {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-kf:hover .in {
  transform: rotateY(180deg);
}

.uv-kf .f,.uv-kf .b {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5em;
  border-radius: 1.4em;
  backface-visibility: hidden;
}

.uv-kf .f {
  background: linear-gradient(160deg,var(--c2),var(--c1));
  color: #fff;
  box-shadow: 0 20px 40px -20px var(--c1);
}

.uv-kf .b {
  background: var(--bg);
  color: var(--fg);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-kf h3 {
  margin: 0;
  font-size: 1.3em;
}

.uv-kf p {
  margin: .3em 0 0;
  font-size: .85em;
  opacity: .7;
}
`;

export default function CardFlip() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-kf"><div className="in"><div className="f"><h3>Hover over me</h3><p>Front</p></div><div className="b"><h3>Hi!</h3><p>This is the back of the card.</p></div></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 “3D flip card” block (Cards) from AIMRAN Library to my project.

## What it is
A card that turns over in 3D on hover to show a second face on its back.

## Chosen settings
- Main color: #0071e3
- Secondary color: #8ec5ff
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Hover over me"

## 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
import type { CSSProperties } from "react";

const css = `
.uv-kf {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  width: 14em;
  height: 17em;
  font-size: var(--s);
  perspective: 60em;
}

.uv-kf .in {
  position: relative;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform calc(0.8s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uv-kf:hover .in {
  transform: rotateY(180deg);
}

.uv-kf .f,.uv-kf .b {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1.5em;
  border-radius: 1.4em;
  backface-visibility: hidden;
}

.uv-kf .f {
  background: linear-gradient(160deg,var(--c2),var(--c1));
  color: #fff;
  box-shadow: 0 20px 40px -20px var(--c1);
}

.uv-kf .b {
  background: var(--bg);
  color: var(--fg);
  transform: rotateY(180deg);
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
}

.uv-kf h3 {
  margin: 0;
  font-size: 1.3em;
}

.uv-kf p {
  margin: .3em 0 0;
  font-size: .85em;
  opacity: .7;
}
`;

export default function CardFlip() {
  return (
    <>
      <style>{css}</style>
      <div
        style={{
          "--c1": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uv-kf"><div className="in"><div className="f"><h3>Hover over me</h3><p>Front</p></div><div className="b"><h3>Hi!</h3><p>This is the back of the card.</p></div></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.
````
