What is the difference between CSS pixels and device pixels?

A CSS pixel is the logical unit used for layout, while a device pixel is a physical dot on the screen. High-density displays use several device pixels to render one CSS pixel, producing sharper text and graphics without making every CSS measurement physically tiny.
A box declared as width: 200px occupies 200 CSS pixels. On a screen with a device pixel ratio of 2, its rasterized width can use about 400 device pixels before other scaling factors. Browser zoom changes how CSS pixels map to the display, so the relationship is not permanently fixed.
Use CSS pixels for component sizes, media queries and spacing. Do not target physical screen resolutions when choosing layout breakpoints. The browser’s logical viewport already accounts for density, allowing the same 48 CSS-pixel button to remain a similar usable size across many displays.
Bitmap assets need enough source resolution to look sharp at their rendered CSS size. Responsive images with srcset can let the browser select an appropriate density or width. SVG graphics usually scale cleanly because their shapes are vector based.
Canvas is a common exception that needs deliberate backing-store scaling to avoid blur. Size the canvas in CSS pixels, multiply its internal dimensions by the current pixel ratio and scale the drawing context. Recalculate when the window moves between displays or zoom changes if the application needs that fidelity. Verify the final behavior across the full width range, including the spaces between preset devices and design breakpoints. Long labels, translated copy and enlarged text often reveal constraints that short demo content does not exercise.