Sub topic 6
Transparency: background layers, alpha, and formats that support it
This chapter assumes you can create and open documents, know what a layer is, and have seen the Layers and Channels panels. It explains where transparency comes from in a Photoshop document, why the Background layer blocks it, and what each file format does with transparent pixels.
What transparency means in Photoshop
A transparent pixel is a pixel that lets whatever is behind it show through. Photoshop draws a gray and white checkerboard where pixels are fully transparent. The checkerboard is only a display aid. It is not stored in the file.
Transparency is stored per layer. Each pixel on a normal layer has red, green, and blue values and an opacity value. The opacity part is called the alpha. Alpha 0 means fully transparent, alpha 255 (in 8-bit) means fully opaque, and values between give partial transparency such as soft shadows and antialiased edges.
The word "alpha" appears in two places, and they are easy to confuse:
- Layer transparency is the alpha built into a layer's pixels. It travels with the layer.
- Alpha channels are extra grayscale channels in the Channels panel, usually saved selections. They are not shown in the image and do not make anything transparent on their own.
When a flattened file such as a PNG has transparency, its alpha is stored as a fourth channel next to red, green, and blue (often called RGBA). That channel comes from the combined layer transparency, not from your saved selections.
The Background layer
A document created with a white or colored Background Contents setting starts with a layer named Background. It differs from a normal layer in several ways:
- It is locked. You cannot move it, and you cannot change its stacking order.
- It cannot hold transparent pixels. Erasing on it paints the current background color instead of removing pixels.
- It always sits at the bottom of the stack.
- A document has at most one Background layer.
You can see the difference with the Eraser tool. On a normal layer it reveals the checkerboard. On the Background layer it leaves a solid patch of the background color.
Converting between Background and a normal layer
To make a Background layer editable, double-click it in the Layers panel and click OK. You can also choose Layer > New > Layer from Background. Photoshop renames it Layer 0 and lifts the lock. Its pixels stay the same until you erase or mask them.
The reverse is Layer > New > Background from Layer. Photoshop fills any transparent pixels with the current background color and moves the layer to the bottom. Do this with care, because the transparency is gone and cannot be recovered from that layer.
Starting without a Background layer
In the New Document dialog, set Background Contents to Transparent. The document then opens with one empty transparent layer and no Background layer. Choose this whenever you know the result needs transparency, such as a logo or a cutout.
| Background Contents | Result |
|---|---|
| White | Background layer filled with white |
| Black | Background layer filled with black |
| Background Color | Background layer filled with the current background color |
| Transparent | One empty normal layer, no Background layer |
Ways to make pixels transparent
Several tools create transparency. They differ in whether you can undo them later.
- Eraser on a normal layer deletes pixels permanently.
- Layer mask hides pixels without deleting them. Black in the mask hides, white shows, and gray gives partial transparency. This is the non-destructive choice.
- Layer opacity and Fill reduce the strength of a whole layer. Opacity also affects layer styles such as shadows. Fill affects only the pixels.
- Delete after a selection removes the selected pixels on a normal layer.
- Image > Trim with the Transparent Pixels option crops away empty edge rows and columns. This is useful before exporting a logo so it has no extra empty margin.
A mask or a reduced opacity becomes real alpha when the file is flattened or exported to PNG. In a PSD the mask stays editable.
Which formats keep transparency
The format you choose decides whether transparency survives.
| Format | Layer transparency | Partial transparency (soft edges) | Alpha channels |
|---|---|---|---|
| PSD | Yes, on every layer | Yes | Yes, optional |
| PNG | Yes, as one flat alpha | Yes | Not as separate channels |
| JPEG | No | No | No |
| GIF | Yes | No, each pixel is fully on or off | No |
| TIFF | Yes, if you choose to save transparency or layers | Yes | Yes, optional |
| WebP | Yes | Yes | No |
The important points for this tutorial:
- PSD keeps everything: separate layers, each with its own transparency, plus masks and alpha channels.
- PNG keeps the final look of the transparency but merges layers into one image. Layers and masks are not kept.
- JPEG cannot store transparency. Photoshop must replace transparent pixels with a solid color.
What happens when you save a transparent image as JPEG
When a document with transparent areas is saved as JPEG, Photoshop flattens it onto a solid color called the matte. In the JPEG Options dialog the Matte menu lets you choose None, White, Black, Background, Foreground, 50% Gray, or Custom. Pick a color that matches the page where the image will appear. Partially transparent edges blend into the matte color.
If you export with Export As, the result is also a flat image with the transparent areas filled. Check the output rather than assuming the color. Open the saved file and look at the corners.
The transparency is lost for good in that file. Keep your layered PSD, and treat the JPEG as a delivery copy.
Edge halos and fringes
Antialiased edges are partially transparent pixels that still carry color from where they were created. If you cut a subject from a white background, the edge pixels can be tinted white. On a dark web page you then see a light outline, a halo.
You can reduce this in a few ways:
- Refine the selection before cutting, and use Select > Modify > Contract by 1 or 2 pixels.
- Use Layer > Matting > Remove White Matte or Remove Black Matte on the layer, depending on the old background.
- Use Layer > Matting > Defringe to replace edge colors with nearby colors from inside the subject.
- Preview on the background color where the image will be used, not only on the checkerboard.
How transparency moves through a save
Scripting a transparent document
The following ExtendScript creates a document with transparent contents, fills a square on its layer, and saves a PNG copy. Run it through File > Scripts > Browse.
// ExtendScript: transparent document, one filled square, PNG copy
var doc = app.documents.add(
new UnitValue(400, "px"),
new UnitValue(400, "px"),
72,
"Badge",
NewDocumentMode.RGB,
DocumentFill.TRANSPARENT
);
var red = new SolidColor();
red.rgb.red = 220;
red.rgb.green = 40;
red.rgb.blue = 40;
doc.selection.select([[100, 100], [300, 100], [300, 300], [100, 300]]);
doc.selection.fill(red);
doc.selection.deselect();
var pngOpts = new PNGSaveOptions();
pngOpts.interlaced = false;
doc.saveAs(new File("~/Desktop/badge.png"), pngOpts, true, Extension.LOWERCASE);The saved PNG shows a red square with transparent pixels around it. If you open it over a colored page or another Photoshop layer, that color shows through the corners.
To convert an existing Background layer from a script, set its isBackgroundLayer property to false:
// ExtendScript: turn the Background layer into a normal layer, if there is one
var doc = app.activeDocument;
try {
doc.backgroundLayer.isBackgroundLayer = false;
} catch (e) {
// The document has no Background layer, so there is nothing to convert.
}Converting the layer does not remove any pixels. The white (or other) pixels stay opaque until you erase or mask them.
Common mistakes
- Erasing the Background layer and getting a colored patch. Convert it to a normal layer first.
- Expecting a JPEG to be transparent. JPEG never is. Use PNG, or PSD for editing.
- Expecting a PNG to keep layers. It stores one merged image. Keep a PSD master.
- Confusing alpha channels with transparency. A saved selection in the Channels panel does not make the image see-through. Turn it into a layer mask or a selection and delete or mask the pixels.
- Judging edges only on the checkerboard. Preview them on the real destination color.
- Saving a cutout with a white Background layer still present. The PNG then has no transparency at all. Turn off or delete the white layer, or convert it, before saving.
Exercise
You delivered a logo as a JPEG and the client reports a white box around it on their dark website. The layered PSD still has a transparent background. What should you deliver instead, and what must be true in the PSD before you save?
Show answer
Deliver a PNG (or WebP), because JPEG cannot store transparency and fills the transparent area with a matte color. Before saving, the PSD must have no opaque Background layer: the logo's layer should sit on transparent pixels, and any white layer should be deleted or hidden. Also check the edges on a dark background for a halo and use Layer > Matting > Remove White Matte or Defringe if one appears.
Exercise
You select the Eraser and drag across your photo, but it paints a white stripe instead of showing the checkerboard. Why does this happen, and how do you fix it?
Show answer
The photo is on a Background layer, which cannot hold transparent pixels, so erasing paints the current background color. Double-click the Background layer (or choose Layer > New > Layer from Background) to make it a normal layer, then erase again. A layer mask is better if you want to keep the original pixels.