SVG Color

You can easily set the fill color of an svg by using it as a mask.

by Guillaume Seguin

HTML

Original:
<div class="icon original"></div>
<br>

Custom:
<div class="icon colored"></div>
<br>


<a href="https://icons8.com" target="blank">Icons 8</a>

CSS

/* IMPORTANT */

/* Colored Icon */
.colored {
  background-color: orange; /* defines the background color of the image */
  mask: url(https://pix.yanport.com/assets/icons/bed.svg) no-repeat center / contain;
  -webkit-mask: url(https://pix.yanport.com/assets/icons/bed.svg) no-repeat center / contain;
}


/* ADDITONAL */

body {
  font-family: 'Roboto', sans-serif;
}

.icon {
  width: 24px;
  height: 24px;
  margin-top: 4px;
}


/* Original Icon */
.original {
  background: url(https://img.icons8.com/stackoverflow) no-repeat center / contain;
}