Sitemap

Create Pixel Art with CSS

2 min readApr 1, 2021
Press enter or click to view image in full size

Try it here.

You may have seen articles about using the box-shadow property in CSS to make pixel art. The process involves creating an element with the width and height of a pixel, and creating a box-shadow for each pixel. It looks something like this:

Press enter or click to view image in full size

As you can imagine, it gets pretty tedious to type it all out manually. So, I automated the process. You can try it out for yourself here.

There are other websites that allow you to convert, but mine is the first one I’ve seen that handles transparency.

The first step is to set up a file upload:

Press enter or click to view image in full size

Next we’ll draw the image onto a canvas so that we can iterate over each pixel:

Press enter or click to view image in full size
Press enter or click to view image in full size

Iterate over each pixel and output a box-shadow for each one in the convertData function:

Press enter or click to view image in full size

On line 58 we set the result to a textarea element for the user to copy.

As a bonus, we render a preview so the user can see what the result looks like:

Press enter or click to view image in full size

And to make it easy to choose the pixel scale, we make changing scale rerender the preview and textarea:

Press enter or click to view image in full size

--

--

No responses yet