Design glossaryA pixel is the smallest dot of color on a screen. In CSS, a px is a reference unit that may cover several physical pixels on high-density screens.
"Pixel" is short for picture element: the smallest unit of a digital image or display. A digital photo is a grid of pixels, each holding one color value, and a screen is a grid of tiny lights, each made of red, green, and blue subpixels that mix to show any color. Zoom far enough into any photo and the pixels appear as small squares of flat color.
In web work, "pixel" can mean three different things, and mixing them up causes most image problems.
Three kinds of pixel
- Image pixels: the dimensions of an image file, such as 1,600 by 900. More pixels mean more detail and, usually, a larger file. See image resolution.
- Device pixels: the physical pixels on a screen. How tightly they are packed is the screen's PPI.
- CSS pixels: the
pxunit used in web design. It is a reference unit, defined so that text and layouts look about the same size on different devices, not one physical dot.
CSS pixels and high-density screens
On older desktop monitors, one CSS pixel matched one device pixel. Most phones, tablets, and many laptops now have high-density screens that use two or three device pixels across, in each direction, for every CSS pixel; that factor is the device pixel ratio. A button 100 CSS pixels wide is drawn 200 or 300 physical pixels wide, which is why text looks so sharp on these screens.
Images are where this shows. An image displayed 400 CSS pixels wide needs about 800 image pixels to look crisp on a 2x screen, or it looks slightly soft. Sending that larger file to every visitor wastes data on screens that cannot use it, so the answer is responsive images: the srcset attribute lists several sizes and the browser picks the one that suits the screen.
WordPress does this automatically. It creates several resized copies of each uploaded image, set by its thumbnail sizes, and adds them to srcset on images in posts and pages.
Pixels in CSS
- Layout details such as borders, shadows, and small gaps are commonly set in
px. - Font sizes are better in
rem. Text sized inpxstill grows when someone zooms the page, but it ignores the default text size a reader sets in the browser, which some people with low vision rely on. - Vector graphics such as SVG logos and icons are not made of pixels at all, so they stay sharp at any size and density. See vector image.
Tracking pixels
"Pixel" also names something unrelated: a tracking pixel, such as the Meta Pixel, is a snippet of code (originally a tiny invisible image) that reports visits and conversions to an advertising or analytics platform. It has nothing to do with image quality, but it does add requests to the page and usually needs consent under privacy laws.