3

Some images not working in background-image:url(), i cant figure out that does i need to remove ( and ) from image name or anything else is an issue?

any help will be appreciated.

here is an working and not working examples.

<!-- Not Working -->

<div style="background-image:url(https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg)"> img </div>


<!-- Working -->

<div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div>
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37

4 Answers4

9

Escape special characters (\ in front of ( and )) in the URL.

<!-- Use CSS escape character to escape special characters -->

<div style="background-image:url(https://ignite.galify.com/images/tx9gyzjfb24712-\(1\).jpg)"> img </div>


<!-- Working -->

<div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div>

Alternatively, use single quote (') to enclose the image URL:

<!-- Use single quote (') to enclose image URL -->

<div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div>
<!-- Working-->

<div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1
</div>
fiveelements
  • 3,649
  • 1
  • 17
  • 16
5

Just add single quotation marks around the url. If you have special characters in your URL, you should use quotes or escape the characters. Give this a read for further information.

Now Working

<div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div>


Working

<div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div>
Javapocalypse
  • 2,223
  • 17
  • 23
4

Try to add single quotes into url:

<div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div>
StepUp
  • 36,391
  • 15
  • 88
  • 148
1

In my case I had an issue with some urls containing a single quote. Fixed it surrounding the url with &quot;:

<div style="background-image: url(&quot; ${url} &quot;);"></div>
nikiforovpizza
  • 487
  • 1
  • 7
  • 13