Normalize Image Captions in Drupal with a Cleaner CSS Approach
Mario Hernandez shares a concise CSS technique to ensure image captions never exceed the width of their images. By using the inline-size: fit-content property on the <figure> element and contain: inline-size on <figcaption>, developers can keep captions aligned with their images regardless of container width. This approach maintains semantic HTML, enhances accessibility, and improves rendering performance.
The method relies on logical CSS properties that are modern, semantic, and easy to implement across projects. Hernandez also recommends optional enhancements like smaller, italicized text and additional padding to improve readability without complicating the layout.
This technique works particularly well in Drupal or any CMS environment where content display consistency matters. It reduces the need for over-engineered layout workarounds and helps teams maintain visual alignment between image assets and their captions. It's a simple, elegant solution that pays off in clarity and efficiency.


