Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 13, 2022 11:07 am GMT

Pixel-pretty-close

I recently got the following message in a DM:
Ive been building with HTML and CSS for years, and I still dont know how to implement pixel-perfect designs

If you're not familiar with the term, "pixel-perfection" is the idea that your HTML/CSS implementation should be as close to the original mockup as possible. Measurements and spacing should be exact, down to the pixel.

I hear this concern a lot; even after years of experience, many front-end developers struggle to perfectly reproduce a design.

When designers hand us a completed mockup, they're trusting us to faithfully implement their vision. Their work is funneled through our implementation, and they're keeping their fingers crossed that we don't mangle it too much in the process.*

How exactly do we produce something that our designers will be proud of?
Is it even realistic to reproduce a design down to the pixel?
Why is this so hard?

Let's get this out of the way upfront: In a strict letter-of-the-law sense, I don't think pixel perfection is actually possible.

The HTML and CSS we write will need to run on a dizzying array of various devices. There are so many variables that impact how an implementation will render.

For fun, I captured screenshots of the exact same Amazon listing* across two different devices.

Image description

When viewed side-by-side, these two screenshots seem pretty darn similar, but when toggling between them, it's clear that they aren't identical. They contain very different pixels.

When I worked for DigitalOcean, I was able to go on a tour of one of their datacenters. It was wild and surreal; enormous rooms held hundreds of rows, each with dozens of racks, each with dozens of computers. Every machine was identical.

I get jealous of backend developers sometimes. There are plenty of hard problems on the backend, don't get me wrong, but at least they control the devices that their code runs on! It doesn't have to run on every imaginable device, from a 5" phone to a 72" TV to a smart-fridge.

In the demo above, I only changed two variables: The operating system and the browser. Think about how many other factors affect what gets painted:

  • Device type (desktop, laptop, tablet, phone, watch...)
  • Screen size / window size
  • Screen pixel density
  • Screen technology (OLED, LCD, CRT, E-ink)
  • User zoom level / default font size
  • Performance (device hardware, server load, network speeds...)
  • Device color correction (eg. Night Mode)

That's just off the top of my head; I bet you have a couple I missed!

So it's clear that we will never be able to ensure 100% consistency when it comes to the RGB values of the individual pixels on the screen. It's an impossible standard. But it's also not really the point.

Nobody is asking for things to look the same under a magnifying glass.* Mostly, designers want the implementation to look near-identical to the naked eye, and to have obvious misalignments and loosey-goosey spacings tightened. They want it to be pixel-pretty-close, not pixel-perfect.

Let's talk about how we can do that.


Original Link: https://dev.to/topcode007/pixel-pretty-close-2n2d

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To