# Grayscale to Color

> An image that sits in black and white and smoothly fades into full color on hover or keyboard focus.

- Category: [CSS Effects](https://copy-css.com/category/effects)
- Tags: grayscale, filter, image hover, black and white, gallery, logos
- Live preview: https://copy-css.com/snippets/grayscale-to-color
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<a class="gray-hover" href="#">
  <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Cdefs%3E%3ClinearGradient id='s' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23f472b6'/%3E%3Cstop offset='1' stop-color='%23fdba74'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='60' height='40' fill='url(%23s)'/%3E%3Ccircle cx='42' cy='15' r='7' fill='%23fef08a'/%3E%3Cpath d='M0 40V26l12-8 10 7 9-5 14 9 15-6v17z' fill='%237c3aed'/%3E%3Cpath d='M0 40v-8l16-5 12 4 14-6 18 6v9z' fill='%234c1d95'/%3E%3C/svg%3E" alt="Purple hills under a pink sunset" width="240" height="160">
</a>
```

## CSS

```css
.gray-hover {
  display: block;
  width: 240px;
  overflow: hidden;
  border-radius: 16px;
}

.gray-hover img {
  display: block;
  width: 100%;
  height: auto;
  filter: grayscale(1) contrast(1.05);
  transition: filter 0.5s ease;
}

.gray-hover:hover img,
.gray-hover:focus-visible img {
  filter: none;
}

.gray-hover:focus-visible {
  outline: 3px solid #7c3aed;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .gray-hover img {
    transition: none;
  }
}
```

## Notes

- This CSS Grayscale to Color is 30 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses transitions, filters, keyboard focus styles and reduced-motion support.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
