Change SVG fill color in :before or :after CSS Change SVG fill color in :before or :after CSS javascript javascript

Change SVG fill color in :before or :after CSS


The accepted answer is incorrect, this is actually possible by applying a workaround with an SVG mask and background-color:

p:after {  width: 48px;  height: 48px;  display: inline-block;  content: '';  -webkit-mask: url(https://mmathys.github.io/heart.svg) no-repeat 50% 50%;  mask: url(https://mmathys.github.io/heart.svg) no-repeat 50% 50%;  -webkit-mask-size: cover;  mask-size: cover;}.red:after {  background-color: red;}.green:after {  background-color: green;}.blue:after {  background-color: blue;}
<p class="red">red heart</p><p class="green">green heart</p><p class="blue">blue heart</p>