Give a container aspect-ratio: 16 / 9 and only its width needs setting — height is computed from the ratio automatically. The trouble is when the image or video inside has a different native ratio: stretch it (width: 100%; height: 100%) and it distorts; preserve its ratio (object-fit: contain) and the frame gets letterboxed with empty space.
object-fit: cover is the most common answer of the three. It keeps the native ratio but scales the content up until it completely fills the frame, then crops whatever overflows — much like overflow: hidden would. object-position controls which part survives the crop (for a portrait, usually top, or something like 50% 30% to favor the face). For a plain <div> background rather than an <img> or <video>, background-size: cover does the identical job.
Change the frame's own ratio later — a square thumbnail becomes a wide banner — and the content inside needs no code changes at all, because object-fit: cover recrops it automatically every time. Drop a grid of differently-sized source images into the same frame, and the grid still reads as visually even.
When to use
Essential whenever you can't control the source dimensions — user-uploaded photos, video thumbnails of mixed ratios — and still need them to line up evenly in a grid or card layout.