# Avatar Upload

> A round profile-photo picker with a camera badge, where the whole circle is a label for a hidden file input.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: avatar, profile photo, upload, file input, camera, circle
- Live preview: https://copy-css.com/snippets/avatar-upload
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="avatar-up">
  <input type="file" name="avatar" accept="image/*">
  <span class="avatar-up-photo" aria-hidden="true">
    <svg viewBox="0 0 24 24"><circle cx="12" cy="9" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/></svg>
  </span>
  <span class="avatar-up-badge" aria-hidden="true">
    <svg viewBox="0 0 24 24"><path d="M4 8h3l2-3h6l2 3h3v11H4z"/><circle cx="12" cy="13" r="3.5"/></svg>
  </span>
  <span class="avatar-up-text">Upload photo</span>
</label>
```

## CSS

```css
.avatar-up {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  color: #0f766e;
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
}

.avatar-up input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.avatar-up-photo {
  display: grid;
  place-items: end center;
  width: 88px;
  height: 88px;
  overflow: hidden;
  border: 2px dashed #5eead4;
  border-radius: 50%;
  background: #ccfbf1;
  transition: border-color 0.2s ease;
}

.avatar-up-photo svg {
  width: 70px;
  height: 70px;
  fill: #99f6e4;
  stroke: #5eead4;
  stroke-width: 1;
}

.avatar-up-badge {
  position: absolute;
  top: 60px;
  left: calc(50% + 18px);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid #f0fdfa;
  border-radius: 50%;
  background: #0d9488;
  transition: transform 0.2s ease;
}

.avatar-up-badge svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linejoin: round;
}

.avatar-up:hover .avatar-up-photo {
  border-color: #0d9488;
}

.avatar-up:hover .avatar-up-badge {
  transform: scale(1.1);
}

.avatar-up:has(:focus-visible) .avatar-up-photo {
  outline: 3px solid #0d9488;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .avatar-up-badge {
    transition: none;
  }
}
```

## Notes

- This CSS Avatar Upload is 78 lines of pure CSS (1.3 KB) with no JavaScript and no dependencies. It uses transitions, transforms, CSS Grid and the :has() selector.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
