A stylesheet can lose to the markup it styles, and the mechanism is easy to forget: HTML width and height attributes are presentational hints, and an explicit height beats an aspect ratio.
The prototype for this site crops card images wide. Every visual context carries its own ratio in the stylesheet: sixteen-to-ten on cards, sixteen-to-nine on the feature, a cinematic sixteen-to-seven on article heroes, with object-fit cover doing the cropping. The production implementation rendered the same images as tall blocks that dwarfed the text around them. Same CSS file, byte for byte. Same image files, byte for byte. The difference was entirely in the img element.
The prototype uses plain img tags with no dimension attributes, so the stylesheet owns the box completely. The implementation used a framework image component that injects width and height attributes for layout stability. Those attributes become presentational hints at the lowest cascade priority, which sounds harmless. It is not harmless when the stylesheet never sets height explicitly, because nothing ever overrides the hint. The width attribute lost to width: 100% in the CSS, but the height attribute stood unopposed. And aspect-ratio, the rule the whole design depended on, only applies when at least one dimension is auto. An explicit height of 1024 pixels disqualified it silently.
The verification was two lines of computed style: the browser reported the correct aspect-ratio value and a height that ignored it. No cascade digging required once you know to ask which property actually won.
The fix was to remove the abstraction rather than fight it. The images are served by the content system without an optimization pipeline, so the component added nothing over a plain img; it only brought attributes the design could not tolerate. Plain img restored every crop in one commit.
The general lesson is worth keeping next to the cascade rules everyone remembers: attributes participate in the cascade too, at the bottom, and bottom still beats absent. A stylesheet that relies on aspect-ratio must make sure no height arrives from anywhere, including from a helpful component that was only trying to prevent layout shift.
Same image, different box
- Height attribute
- An explicit height keeps the rendered box tall even when the stylesheet specifies a wide ratio.
- CSS crop
- With height left to CSS, the 16:10 ratio sizes the box and
object-fit: covercrops the image within it.
