I am using background image in style tag.
<style> body { background-image: url("img.jpg"); background-size: cover; transition: background-image 4s linear; } </style>
I want the image to fade in without adding a separate div to the page. Can this goal be achieved?
Yes, it is possible. You can do this.
This is a CSS-only approach. However, there is a caveat, CSS cannot wait for events, so it has no way of knowing when the entire site has loaded.
Instead, in this snippet, it waits 1 second before starting to introduce the background image that is located on the body's before pseudo-element.