All of the below methods to accomplish this were provided by Temani, I've just gathered them in one place to make them easier to choose from based on your needs.
Solution 1
This solution replicates the effect exactly for Firefox, but can only approximate the effect for Chrome and Edge because they don't support sub-pixel values:
html {
height:100%;
/* fallback for Firefox */
background:
radial-gradient(#000 0.5px,transparent 0.5px) 0 0 /3px 3px,
radial-gradient(#000 0.5px,transparent 0.5px) 1px 1px /3px 3px,
radial-gradient(#000 0.5px,transparent 0.5px) 2px 2px /3px 3px,
url(https://i.picsum.photos/id/102/800/800.jpg) center/cover;
/*Chrome and the latest version of Edge*/
background:
conic-gradient(from -90deg at 1px 1px,#000 0 90deg,transparent 0) 0 0 /3px 3px,
conic-gradient(from -90deg at 1px 1px,#000 0 90deg,transparent 0) 1px 1px/3px 3px,
conic-gradient(from -90deg at 1px 1px,#000 0 90deg,transparent 0) 2px 2px/3px 3px,
url(https://i.picsum.photos/id/102/800/800.jpg) center/cover;
}
It works on all modern versions of Firefox and Chrome, but only the very latest version of Edge.
Note that the very latest version of Edge (the Chromium-based one, and what Microsoft calls the "New Microsoft Edge") is currently only available as a standalone installer that hasn't been actively pushed by Microsoft. Therefore, it's highly unlikely for your site's users to be using this version of Edge at this point, even if they're on Windows 10 and up to date.
Solution 2
This is the exact same method used by Bootstrap in pattern-mask-5
, and although it works on all modern browsers, it requires the use of an image in addition to adding a container <div>
to the markup:
HTML:
<div class="bg-container">
</div>
CSS:
.bg-container {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(local/img.png); /* download the image here: https://i.ibb.co/C0MjrsJ/05.png and link to it */
}
Solution 3
The solution posted by Temani here is by far the cleanest, most cross-browser solution to this issue.
html {
height:100%;
background:
url('data:image/svg+xml;utf8,<svg viewBox="0 0 3 3" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" /></svg>') 0 0 /3px 3px,
url('data:image/svg+xml;utf8,<svg viewBox="0 0 3 3" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" /></svg>') 1px 1px/3px 3px,
url('data:image/svg+xml;utf8,<svg viewBox="0 0 3 3" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" /></svg>') 2px 2px/3px 3px,
url(https://i.picsum.photos/id/102/800/800.jpg) center/cover;
}
It makes use of SVGs and therefore doesn't require any external images, and works on all modern browsers.