Websites and banners, made understandableImages · Code · WordPress
Home / Guides
Images

Image borders: decide where they belong

A border can belong to the photograph or to the interface. Keep the distinction: card borders are easier to change in CSS; artistic framing belongs in an editable document.

Before you begin

Measure the source and choose a thickness. To preserve the complete photograph, add space outside it instead of covering edges with an internal stroke.

Image borders: decide where they belong. Photo 800 × 600 → Border 20 px → File 840 × 640
Photo 800 × 600 → Border 20 px → File 840 × 640
Text explanation of the diagram

Photo 800 × 600 → Border 20 px → File 840 × 640. An 800 × 600 photo with an external 20 px frame becomes 840 × 640. Drawing the same frame inside instead covers 20 px of the photograph on every edge.

The procedure

  1. For an exported file, expand the canvas or add a separate layer beneath the photo. Preserve the subject’s proportions rather than stretching it together with the frame.
  2. For a page, use border and box-sizing: border-box. Check that the image, border and spacing fit the container together.
  3. Compare on light and dark backgrounds. If the image is a link, preserve keyboard focus; a decorative border should not be the only indication of interaction.
Code example
.photo { box-sizing: border-box; border: 1px solid #27241f; max-width: 100%; }

A worked example

An 800 × 600 photo with an external 20 px frame becomes 840 × 640. Drawing the same frame inside instead covers 20 px of the photograph on every edge.

Check the result

Dimensions fit the layout, no image edge is accidentally lost, and mobile pages have no horizontal scrolling.

A common mistake

Applying the same border in both the file and CSS doubles its thickness. Inspect the exported file on a neutral background before changing styles.

Sources and next steps

Diagram and examples: Web Article. The diagram explains a principle; it is not an interface capture or a software test result.

Check a transparent edge against both light and dark

An editor’s checkerboard does not prove the exported edge is clean. Compare the same PNG on two backgrounds at the same scale. These two original teaching files are RGBA 64 × 64: A has a dark partly transparent edge; B deliberately stores white in those edge pixels. This is a synthetic demonstration, not a Photoshop screenshot.

  1. Keep the layered original separately. Export a PNG with alpha and open the actual output, not only the editor document.
  2. Place it on light and dark backgrounds. Inspect the outer contour and internal openings at 100% scale, then at the intended page size.
  3. If a light halo appears on dark, inspect the partly transparent pixels and former matte. Do not hide the problem with another CSS border.
  4. Check that the checkerboard was not baked into the file and that dimensions and alpha survived. One white page is insufficient.

Checkable pixel: black RGB 0 with alpha 128 over white 255 gives approximately 127; over black 0 it gives 0. White edge RGB 255 with the same alpha gives approximately 128 over black. The simplified teaching calculation is α × foreground + (1 − α) × background, with α = 128/255. Equal alpha does not mean an equal edge.

PNG A · PNG B with a deliberate defect. Record file/dimensions __; alpha __; light background __; dark background __; intended scale __; edge observation __. Do not attribute the same fault to a real photograph before inspecting its file.

Check a transparent edge against both light and dark
A: dark RGB, alpha 128 · B: white RGB, same alpha · Two backgrounds, same scale.

Source: developer.mozilla.org.

Keep making