The designer’s guide to pixel hinting

Pixel-perfect icons and typography stand out among the crowd online. Obviously we all want to strive for such refined work, but sometimes even after trying we still end up with something a little… less. Pixel Hinting is one of the skills that takes an automatic feature and improves upon its results. Despite the ultra high resolution of displays today—like Apple’s retina displays—we still need to “fake” smooth curves lest we end up with a pixelated mess.

Many designers and developers are moving more towards SVG and vector based approaches now; with the support only getting better by the day. But even so, vector based solutions have a long way to go before they’re mature enough to use in production. SVG is great for displaying vector shapes, but not so hot at resizing those shapes. So like everything else out there, there is a time and place for each solution.

 

What are vectors?

Vectors are essentially rendered results of the mathematical representation of a shape. When you see anything on your screen, it’s because your computer rendered those objects and bound them to the pixels on your display. In doing so, your computer has also made decisions on what should, and shouldn’t, be displayed as whole pixels. For example, the uppercase letter “D” has both a perfectly straight line, and a curved one.

001

As you can see, without anti-aliasing the curved line on the “D” is quite pixelated. So to compensate, when vector shapes are rendered they are usually anti-aliased to provide a more… robust appearance. Instead of only displaying pixels that fall within the vector outline entirely, pixels are gradually shaded out. This tricks your brain into seeing a smoother line on curved shapes that don’t snap to the pixel grid perfectly.

002

Above you can see how the rendered “D” is given what is called half-pixels to help remove the jagged pixelation. However, this same feature also introduces a problem: computers are awful at figuring out what is visually appealing. So while adding these half-pixels makes the rounded corners look fantastic, it also makes the top/bottom inner line look blurred. The automatic anti-aliasing that occurs when a vector shape is rendered ends up making most parts of shapes and typography look great, but leaves others at an even worse quality than it started with.

 

Hello, pixel hinting.

Now that you have a short background on vector shapes and how they work, let’s jump into the real work. Pixel hinting involves moving the vector’s anchor points to rest on pixel borders in a more aesthetically pleasing way. Making those straight lines more perfect, while still leaving the half-pixels to the curves. Most commonly, pixel hinting is used on typography and shapes for raster images (logos, icons, branding, etc). Now, most importantly, in order to properly adjust your vector it must be in the size and shape you want it. Once you’ve pixel hinted your work, rotating or resizing it could—and probably would—throw all that work away by automatically anti-aliasing it again. Before we get started make sure the following settings are adjusted (I’ll be using Photoshop for this task):

  • Turn on your pixel grid (View > Show > Grid, also make sure Extras is checked above the Show menu)
  • Make sure your grid has a gridline every 10 pixels, with 10 subdivisions. Or something similar so that there is a line between each pixel.
  • Disable snapping (View > uncheck snap). We don’t want anchor points snapping at 1px increments, we want to move points within pixels.

Pixel hinting typography

The process for doing shapes vs typography is slightly different, so I’ll walk you through both. Ideally with typography, you want to kern your type before or during your hinting process. Regardless, pixel hinting should be one of the last things you do.

First, select the typography you want to pixel hint and make a copy of the layer, then transform that layer into a shape.

003

You can see that the text falls awkwardly off the grid, both on the horizontal as well as the vertical axis. To fix this, we’re going to gently nudge each letter’s anchor points until they align more closely with the pixel grid laid out. The goal, is to get the shape lines close, if not directly on, the grid lines. Zoom in to nudge anchor points more precisely. While doing this, frequently zoom out to ensure your adjustments look alright.

You don’t want to conform precisely to the grid, as that takes away the advantages of anti-aliasing in the first place. Instead, try to simply keep things consistent—only allow half-pixels on one side of each axis. For example, I always allow half-pixels to the right and top of letters, while forcing the left and bottom edges flush to the grid.

004

As you can see, the “get in” has been roughly adjusted, while the “touch” remains as is. Just like kerning, pixel hinting is much more of a craft than a science. It takes a keen eye to look and discern whether the work looks better or worse after adjustment. Don’t be discouraged if you find typographical pixel hinting rough, iterate and keep working with it. If your result still looks sub-par, you can always delete the layer and copy fresh from the original again. It takes some time to get typography in particular to look great, just keep going and sooner or later your hard work will pay off.

Pixel hinting vector shapes

Generally, pixel hinting shapes is reserved for icons or logos. Again, you want to make sure your shape is at the size and rotation you want it before starting as adjusting it later could throw away all your hard work. Adjusting shapes is a lot easier and requires less of an eye for intrinsic detail. That being said, more complex shapes take longer and are harder to adjust, so it’s best to start with something simple.

005

Above, you can see that our arrow and circle sit just slightly off where we would like them. The half-pixels created by anti-aliasing are causing the entire shape to look blurry as a result. So let’s nudge everything to fall on the grid a little better.

006

There we go! By adjusting the anchor points to line up with the grid, we end up with a much sharper icon. It’s important to mention that since this icon is a circle, any adjustments to the width had to also be mirrored to the height as well. Also, don’t forget to make sure the inside of the shape looks good and consistent as well. If you look at the previous image you’ll notice the inside sides of the circle aren’t anti-aliased the same.

007

 

In conclusion

With the work above, the result is an image that looks sharper and more professional. Of course, you can apply these techniques to much more important things than a button.

While the automatic anti-aliasing done by your computer looks acceptable, it could be better. So when it comes to your logo or important icons/typography in raster form, pixel hinting is more than just a niche skill; until the day we’re all using high pixel density displays, it’s essential.

0 shares
  • http://www.12snaps.com/ Paweł Grzybek

    Would be cool to see and advices how to handle pixel hinting in HTML document. In Photoshop is easy to manage our pixels but how to make sure its going to look nice on webproject….

    • https://niku-solutions.nl Nick Kuijpers

      Indeed!

    • http://noxxten.com/ Dustin Cartwright

      Unfortunately there isn’t any semantic way to pixel hint with HTML/CSS. I believe I’ve seen one or two fancy JS solutions if those are of interest to you… But really, pixel hinting is more used for images and print. Generally speaking, there isn’t much optimization left to do in the browser since rendering engines there are much more mature.

  • Alex

    Got a problem with that though. The letters look squished on the hinted version. It looks just as bad, sadly.

    • http://noxxten.com/ Dustin Cartwright

      Admittedly, I’m not the greatest at pixel hinting typography. It’s a super useful skill to have, but one that grows less and less needed as time wears on. It’s similar to kerning as well, in that it’s a matter of taste and preference (:

  • jacksbox

    Just a tipp which saves a lot of time: instead of moving the objects by hand just hit cmd+t, set the anchor point to the top left corner, and change the x and y values to full pixels (no decimals) – thats all, no zooming, grid, fiddling with the handish moving

    • http://noxxten.com/ Dustin Cartwright

      Great tip! This serves to set a good foundation for further refinement. Just keep an eye out and make sure Photoshop doesn’t try to automatically snap your shapes to pixels and end up stretching them. I usually use this method first, and then move into individually adjusting each letter after.

  • Nibinear

    It looks virtually the same and your instructions don’t make sense. Why is the pixel hinted better than the original?

    • http://noxxten.com/ Dustin Cartwright

      It’s a very minute difference, and on something as casual as a button it’s usefulness is lost. Pixel hinting is primarily used on logos and in print. Sometimes Photoshop can do a great job of setting typography, but usually it does so poorly. Pixel hinting serves to manually adjust the anti-aliasing preformed on the type in order to make it more clear looking.

      If you’re looking for examples in the wild, Hulu didn’t pixel hint their logo for a very long time. The difference there is quite obvious. Dustin Curtis also wrote an informative guide on pixel hinting in 2012: http://dcurt.is/pixel-fitting

      • Nibinear

        I can see the point for one offs like a logo.

        On instructions
        I had to look up how to alter the PS grid, because by default it gave me a grid line every 20 pixels instead of 10.

        For anyone else you have to go to: Edit > Preferences > Guide, Grid and Slices > Gridline every 10 pixels, with 1 or 10 subdivisions.

        Where it says “There we go!”, it is more off the grid in the after shot, horizontally speaking. Vertically it’s the same. I’m just not getting the idea with these instructions at the moment.

      • http://noxxten.com/ Dustin Cartwright

        It’s hard to grasp at first. I should have included instructions to the grid settings in Photoshop as well.

        When you’re hinting, you don’t want to align the paths directly to the grid everywhere – that defeats the purpose of the automatic anti-aliasing you’re trying to correct. Instead, I usually opt to align text to the bottom and left sides, leaving the top and right sides to retain the shapes the original designer intended for the typography.

        Hinting is much more relevant for icons and logos. If you grab any vector icon pack and use one at two different sizes, you’ll see the automatic anti-aliasing Photoshop preforms. The shapes will be similar, but the half pixels around the edges won’t be the same on both icons.

  • anne

    Why would you ever need pixel hinting in print? Vectors work just fine there.