# Password field with eye

> A password input with an eye button; a line slides off the eye when the password is shown.

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

## Where to use it

Letting people see what they typed cuts down on failed logins, especially on phones. This show password toggle fits any login or sign-up form, the Wi-Fi setup of a smart device or a shop account. Tap the eye and its slash draws away as the dots turn into text. A few lines of JavaScript handle the switch.

Put it on sign-up forms first: that's where a typo in a new password causes the most trouble. The button also carries a hidden label for screen readers, so people who can't see the eye still know what it does.

## Code

### HTML

```html
<label class="uv-ip"><input type="password" value="secret123"><button type="button" aria-label="Show password"><svg viewBox="0 0 24 24"><path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/><path class="sl" d="M4 4l16 16" pathLength="1"/></svg></button></label>
```

### CSS

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

.uv-ip {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  width: 16em;
  font-size: var(--s);
}

.uv-ip input {
  width: 100%;
  box-sizing: border-box;
  height: 3em;
  padding: 0 3em 0 1em;
  border: 0;
  border-radius: .9em;
  font: inherit;
  letter-spacing: .05em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  outline: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
  transition: box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip input:focus {
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-ip button {
  position: absolute;
  right: .5em;
  top: 50%;
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  cursor: pointer;
  translate: 0 -50%;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}

.uv-ip button:active {
  transform: scale(.85);
}

.uv-ip svg {
  width: 1.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.uv-ip .sl {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset calc(0.35s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip.on .sl {
  stroke-dashoffset: 1;
}

.uv-ip.on button {
  color: var(--c1);
}
```

### JavaScript

```js
document.querySelectorAll(".uv-ip").forEach(el => {
  const i=el.querySelector("input"),b=el.querySelector("button");b.addEventListener("click",()=>{const on=el.classList.toggle("on");i.type=on?"text":"password"})
});
```

### 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 = `
.uv-ip {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  width: 16em;
  font-size: var(--s);
}

.uv-ip input {
  width: 100%;
  box-sizing: border-box;
  height: 3em;
  padding: 0 3em 0 1em;
  border: 0;
  border-radius: .9em;
  font: inherit;
  letter-spacing: .05em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  outline: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
  transition: box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip input:focus {
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-ip button {
  position: absolute;
  right: .5em;
  top: 50%;
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  cursor: pointer;
  translate: 0 -50%;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}

.uv-ip button:active {
  transform: scale(.85);
}

.uv-ip svg {
  width: 1.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.uv-ip .sl {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset calc(0.35s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip.on .sl {
  stroke-dashoffset: 1;
}

.uv-ip.on button {
  color: var(--c1);
}
`;

// 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"),b=el.querySelector("button");b.addEventListener("click",()=>{const on=el.classList.toggle("on");i.type=on?"text":"password"})
}

export default function InPassword() {
  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": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-ip"><input type="password" value="secret123" /><button type="button" aria-label="Show password"><svg viewBox="0 0 24 24"><path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z" /><circle cx="12" cy="12" r="3" /><path className="sl" d="M4 4l16 16" pathLength="1" /></svg></button></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 “Password field with eye” block (Inputs) from AIMRAN Library to my project.

## What it is
A password input with an eye button; a line slides off the eye when the password is shown.

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

## 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 = `
.uv-ip {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  position: relative;
  display: block;
  width: 16em;
  font-size: var(--s);
}

.uv-ip input {
  width: 100%;
  box-sizing: border-box;
  height: 3em;
  padding: 0 3em 0 1em;
  border: 0;
  border-radius: .9em;
  font: inherit;
  letter-spacing: .05em;
  color: var(--fg);
  background: color-mix(in srgb,var(--fg) 6%,transparent);
  outline: none;
  box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--fg) 12%,transparent);
  transition: box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip input:focus {
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uv-ip button {
  position: absolute;
  right: .5em;
  top: 50%;
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: color-mix(in srgb,var(--fg) 55%,transparent);
  cursor: pointer;
  translate: 0 -50%;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1);
}

.uv-ip button:active {
  transform: scale(.85);
}

.uv-ip svg {
  width: 1.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.uv-ip .sl {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset calc(0.35s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uv-ip.on .sl {
  stroke-dashoffset: 1;
}

.uv-ip.on button {
  color: var(--c1);
}
`;

// 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"),b=el.querySelector("button");b.addEventListener("click",()=>{const on=el.classList.toggle("on");i.type=on?"text":"password"})
}

export default function InPassword() {
  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": "#0071e3",
          "--c2": "#8ec5ff",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uv-ip"><input type="password" value="secret123" /><button type="button" aria-label="Show password"><svg viewBox="0 0 24 24"><path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12z" /><circle cx="12" cy="12" r="3" /><path className="sl" d="M4 4l16 16" pathLength="1" /></svg></button></label>
      </div>
    </>
  );
}
```

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