How to set the equivalent of a src attribute of an img tag in CSS?

Spread the love

To set the equivalent of a src attribute of an img tag in CSS, we set the content property.

For instance, we write

<img class="myClass123" />

to add the img element.

Then we write

.myClass123 {
  content: url("https://picsum.photos/30/30");
}

to select the img element with class myClass123 and set its image URL with content: url("https://picsum.photos/30/30");.

Leave a Reply

Your email address will not be published. Required fields are marked *