CSS, Lazy Loading, JavaScript, Tutorial, Javascript Tips.
var ratio = +img.getAttribute('data-height') / +img.getAttribute('data-width'); img.style.paddingTop = ratio * img.getBoundingClientRect().width + 'px'; After adding some CSS we can see a grey box, the size of the image. img[data-src] { background: #aaa; If you want a nice looking loading animation