惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
C
CERT Recently Published Vulnerability Notes
Forbes - Security
Forbes - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 最新话题
The Hacker News
The Hacker News
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Last Watchdog
The Last Watchdog
S
Schneier on Security
T
Troy Hunt's Blog
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Schneier on Security
Schneier on Security
P
Privacy & Cybersecurity Law Blog
T
Tor Project blog
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
Arctic Wolf
S
Secure Thoughts
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Latest
Security Latest
Scott Helme
Scott Helme
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog

Ahmad Shadeed

Better fluid sizing with round() Use Cases for Field Sizing The Basics of Anchor Positioning Item Flow CSS Relative Colors Balancing Text In CSS Should masonry be part of CSS grid? CSS display contents CSS Grid Areas CSS Cap Unit An Interactive Guide to CSS Container Queries CSS :has() Interactive Guide CSS Nesting UX in DevTools CSS Nesting Future CSS: State Container Queries Rebuilding a comment component with modern CSS Conditional CSS with :has and :nth-last-child CSS Text balancing with text-wrap:balance CSS Masking Do we need CSS flex-wrap detection? My CSS Wishlist Conditional CSS CSS Style Queries Inside the mind of a frontend developer: Article layout Inside the mind of a frontend developer: Hero section CSS container queries are finally here The CSS behind Figma First Look At The CSS object-view-box Property Learn CSS Subgrid CSS :has Parent Selector Aligning Content In Different Wrappers Flexbox Dynamic Line Separator Hello, CSS Cascade Layers Building UI Components With SVG and CSS A Deep CSS Dive Into Radial And Conic Gradients Defensive CSS Building Real-life Components: Facebook Messenger Conditional Border Radius In CSS CSS Container Query Units Less Absolute Positioning With Modern CSS Aligning a Button Label Vertically Using HSL Colors In CSS Custom Scrollbars In CSS Let CSS Container Queries For Designers The State of CSS Cross-Browser Development Overflow Issues In CSS Inspect Element As A Way To Increase Your Curiosity Handling Text Over Images in CSS Digging Into CSS Logical Properties Clipping Scrollable Areas On The inline-start Side Understanding Clip Path in CSS The Art of Building Real-life Components Handling Short And Long Content In CSS CSS Scroll Snap A Deep Dive Into CSS Grid minmax() CSS Variables 101 Finding The Root Cause of a CSS Bug Learn CSS centering How to detect browser support for Flexbox Gap CSS Mistakes While On Autopilot Digging Into the Flex Property Understanding CSS Multiple Backgrounds Aligning Logo Images in CSS Grid for layout, Flexbox for components Colors in CSS Thinking About The In-between Design Cases min(), max(), and clamp() CSS Functions Image Techniques On The Web Everything About Auto in CSS Learn Box Alignment Let Learn CSS Positioning Intrinsic Sizing In CSS CSS Grid Template Areas In Action Hiding Elements On The Web Creating a Variable Color Font From Scratch Building a Football Ticket With CSS and SVG Blending Modes in CSS CSS Variables With Inline Styles Implementing Dark Mode For My Website Rebuilding Apple Music Header in HTML & CSS Accessible Checkbox Layout Flickering On Browser Resize Enhancing The Clickable Area Size Custom Underlines with SVG Part 3: The Process of Implementing A UI Design From Scratch Part 2: The Process of Implementing A UI Design From Scratch Building An Old Nav Design CSS Flexbox: 5 Real World Use Cases I Used CSS Inline Flex For The First Time The Process of Implementing A UI Design From Scratch Common CSS Issues For Front-End Projects Handling Long and Unexpected Content in CSS How to Build Web Form Layouts With CSS Grid Grid Layout Ah-ha Moment Enhancing Our Components with CSS :empty Building Resizeable Components with Relative CSS Units CSS Writing Mode The Journey of Learning Front End Web Development on a Daily Basis
Comparing Design Mockups To Code Result
Ahmad Shadeed · 2021-07-13 · via Ahmad Shadeed

The Layout Maestro

I spent years teaching CSS layout on this blog. I put everything I know into The Layout Maestro course: 70+ lessons and 150+ interactive examples that teach you how to think CSS layouts, not just memorize syntax.

Get the course

If you are a UI designer who codes HTML or CSS, then you are likely familiar with how to compare the coded design result to the original design mockup. The designer eye is more trained to notice differences in alignment, font size, color, and alignment. The eye just gets used to it.

However, if the person in charge of the UI development doesn’t have any design experience, it becomes more challenging. It has happened to me that developers claimed the coded result was consistent with the original design, but it wasn’t. This article will share my experience as a designer who codes on how to compare a design mockup to the coded result, along with some tips and tricks.

Let’s get started!

Introduction

Comparing a design mockup to the coded result is as important as designing a polished UI. If each component in a web page has something different from the design, then you will end up with a slightly different result from the design mockup. This isn’t good.

Let’s take the following example.

Can you guess what is the difference(s) between the design and the code result? It can be tricky, but there are four differences.

Here are a few hints keywords:

  • Radius
  • Color
  • Font Size
  • Shadow

Ok, enough guessing. Here are the differences:

If you pay closer attention, you will notice what is different from the design. You may not see them at the first glance though. I placed the design above the coded result, notice the areas where they don’t match.

This isn’t accepted by a front-end developer. A designer has spent time and effort working on a consistent design. As a developer, we expect that you will give it the same attention and care.

I’m not an advocate of pixel perfection as a term. In fact, I wrote a deep dive article about that and I recommend you to read it. Instead of focusing on the whole process of comparing a design on measuring pixels, it can be focused on look & feel and we can take pixel perfection only when it’s really needed.

Consider the following example.

The differences in the coded result can’t be overlooked. There are some clear details that make the result looks unprofessional. Such things should be perfect as per the design.

Here is a figure that shows the spacing design details in the previous mockup.

The same applies to the font sizes. Such details can’t be missed, and they must be an exact implementation as per the design as they can change the look & feel of the proposed design.

With that, let’s explore the different ways to compare a design to the implemented result.

How to compare

I will focus on how we can compare a design against implementation. Being able to decide if two things are the same is not easy, and I hope that the next few ways of doing so will make it clear for you.

Overlapping design and implementation

In this method, we need to place the implementation above the design and try to spot the differences. To do that, we can do one of the following:

  1. Take a screenshot for either a full page or a specific component and place it in a design app
  2. Exporting the design and adding it in the browser as a background-image or an <img> in the browser
  3. Open the design and the code result in separated tabs

First, I want to show you the UI that will be used as an example in this article. It’s an imaginative delivery website, and I will focus on the header and hero section. Here it is:

I got inspired by this tweet by Brad Frost to write about the techniques I’ve using for years as a designer/developer. Let’s get into comparing.

Taking a full-page screenshot

The first thing that I want to focus on is the width screenshot. Let’s suppose that in the design app, the page width is 1440px (The default in Sketch and Figma).

To get a clear comparison, the screenshot and the design width should be identical. I’m using Chrome DevTools for taking the screenshot, but you can use the same feature in different browsers (e.g: Firefox).

Once we capture a full-page screenshot, we need to drag it into the design app and place it above the page. In the design app (Figma, in my case), we need to drag the screenshot above the page:

Then, all we need to do is to lower the opacity to 50%. This will make it possible to spot the differences between them. Let’s take a look:

Notice how the top image with 50% opacity is showing the spots that are the different. Isn’t that useful, and easy to be implemented? From the figure above, we can spot that:

  1. Logo is smaller than expected
  2. Navigation padding is smaller
  3. Headline font size is too small
  4. The icon isn’t vertically centered
  5. Form is smaller

Even better, we can change the blend mode of the design to be Difference which highlights the main differences between the two images.

Taking a partial screenshot

We can also take a screenshot of a specific section or component, and compare it against the design mockup. In the DevTools, select the HTML element you want and then select “Screenshot Node” from the dropdown menu.

For this example, I’m comparing the header element. By dragging it into the design app, we can notice the differences and work on fixing them.

Adding the original design as an image in the browser

For this method, we will do the opposite of the previous one. Instead of taking a screenshot from the browser to a design app, we need to take the original design and place it above the page in the browser.

Thanks to CSS backgrounds and pseudo-elements, this is possible. The following is the coded design in the browser.

Again, please make sure that the browser width is equal to the design width for better comparison.

body {
  position: relative;
}

body:after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  z-index: 100;
  width: 100%;
  height: 100%;
  background-image: url("img/home.png");
  background-size: 100% auto;
  background-repeat: no-repeat;
  opacity: 0.5;
}

We can also do the same thing using an <img> element if you prefer that. In the end, the benefit is to compare the two designs. Make sure that no other element in the same stacking context has a higher z-index than the pseudo-element.

Adding on that, we can change the blending mode to make the differences stand out more. In CSS, we need to use the mix-blend-mode property.

body:after {
  /* other styles, plus */
  mix-blend-mode: difference;
}

I wrote a detailed article about blending modes in case you want to learn more.

Also, you will notice that nothing is hoverable or clickable, that’s because the pseudo-element is covering the page. We can allow interactivity by setting pointer-events to none.

body:after {
  /* other styles, plus */
  mix-blend-mode: difference;
  pointer-events: none;
}

Open the design as a tab in the browser

Another less known tip that I use a lot while designing a new web project is to open the mockup in the browser. As always, make sure that the mockup width is equal to the browser.

By switching between the actual code result and the mockup, we can notice the differences. This works for designers or developers with basic design experience.

Getting an element size via DevTools

When inspecting an element in the DevTools, we can get its width and height and compare them with the design. Consider the following figure:

There is a 12px difference between the code and design. This is a mistake and something that can be ignored.

PerfectPixel Extension

This is a free and very good extension that can help in comparing design versus code result. Check it out

Polypane Browser

One of the useful features in Polypane is the ability to add a reference image that can be compared against the code.

Read more about it in the docs.

Quick tips

Font issues

There are fonts with large spaces around the baseline and cap areas. They cause issues when being used in CSS. In a design app, the designer can control the text height easily, but in CSS it’s a bit tricky.

Consider the following figure where a button has vertical padding of 8px.

There is a difference between the design and the coded one, even though the padding is equal to the design. Unfortunately, there is no direct solution to this except tweaking the vertical padding. In the future, we might get a property called leading-trim that can fix that. Read about it here.

Having a consistent icons size

It’s important to have icons with the same width and height to achieve consistency in aligning them. This will help to avoid working on a custom alignment for a specific icon.

The first will make the icons easier to use. Their surrounding box has padding, and they’re properly aligned. While the second ones are custom-sized which will make it hard to deal with them in CSS.

Thank you for reading!

I wrote an ebook

I’m excited to let you know that I wrote an ebook about Debugging CSS.

If you’re interested, head over to debuggingcss.com for a free preview.