CSS Avatar Upload

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

  • avatar
  • profile photo
  • upload
  • file input
  • camera
  • circle
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
.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;
  }
}

About this CSS Avatar Upload

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. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #0f766e
  • #5eead4
  • #ccfbf1
  • #99f6e4
  • #f0fdfa
  • #0d9488
  • #fff

How to use this avatar upload

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .avatar-up class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback