# Styled File Input

> A native file input restyled with ::file-selector-button, keeping the browser's own file name display.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: file input, upload, file-selector-button, attachment, browse, form
- Live preview: https://copy-css.com/snippets/styled-file-input
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="file-pick">
  <span>Attach a file</span>
  <input type="file" name="attachment" accept=".pdf,.png,.jpg">
  <small>PDF, PNG or JPG, up to 10 MB</small>
</label>
```

## CSS

```css
.file-pick {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 280px;
  color: #0f172a;
  font: 600 13px system-ui, sans-serif;
}

.file-pick input {
  min-width: 0;
  padding: 6px;
  border: 1.5px dashed #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: #64748b;
  font: 13px system-ui, sans-serif;
  cursor: pointer;
}

.file-pick input::file-selector-button {
  margin-right: 10px;
  padding: 7px 12px;
  border: 0;
  border-radius: 7px;
  background: #0f172a;
  color: #fff;
  font: 600 13px system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.2s ease;
}

.file-pick input:hover::file-selector-button {
  background: #334155;
}

.file-pick input:focus-visible {
  border-color: #0f172a;
  outline: 2px solid #0f172a;
  outline-offset: 2px;
}

.file-pick small {
  color: #64748b;
  font-size: 12px;
  font-weight: 400;
}
```

## Notes

- This CSS Styled File Input is 47 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses transitions, CSS Grid and keyboard focus styles.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
