TheRogerLAB Codes

Set a default image in HTML

  July, 2021

Introduction

Sometimes we want to set an image by default in case that our original src does not load. We can achieve this using a simple line of code: the onerror event. The only thing that we have to do is setting the onerror event and changing the image src in case that this event triggers

Step 1: Setting the deafult image

<img src="images/originalPic.jpg" onerror="this.src='images/blankPic.jpg'">
RATE THIS ARTICLE
4.6
18
TheRogerLAB Codes
Powered by TheRogerLAB Sandbox

info@therogerlab.com