Beginnernote 03 of 1703 reasons · 03 notes
CSSBeginner
Reserve dimensions before polish
Aspect ratios and grid constraints prevent layout shifts before shadows and colors arrive.
Code example
Copy, adapt, and ship.
Read the numbered lines, copy the complete snippet, then adjust the values for your project.
.media-frame { aspect-ratio: 16 / 9; overflow: hidden;} .media-frame > img { width: 100%; height: 100%; object-fit: cover;}Why this matters
The production reason.
- 01
Layout shift usually starts before visual polish: images without dimensions, grids without stable tracks, and embeds without aspect ratios.
- 02
Reserve the space first, then make it beautiful. Users should not lose their reading position because an image finally loaded.
- 03
This is especially important for product cards, blog thumbnails, ad slots, and dashboards.
How it holds up outside a demo.
- Next.jsAlways provide width and height to Image.
- ShopifyReserve product image ratios so collection grids do not jump.
- WordPressAdd width/height attributes or aspect-ratio wrappers for custom blocks.
Explore other stacks
Jump into a different technology.
17 CSS notes on this shelf, and six more stacks beside it.
Use next/image for image optimization
Next.js image optimization starts with next/image sizing, lazy loading, modern formats, and predictable dimensions.
Open the noteKeep state close to the interaction
Local state avoids unnecessary parent renders and keeps component intent obvious.
Open the noteAbort stale fetch requests
Cancel outdated browser requests so fast UI changes do not render old data.
Open the noteFix WordPress H1 SEO issues
Fix WordPress SEO issues by keeping one clear H1, escaping template output, and compressing images before WordPress upload.
Open the noteReduce LCP with image optimization
Reduce LCP with image optimization by resizing, converting, and compressing images before they reach production.
Open the noteUse real buttons for actions
If it changes state, use button. If it navigates, use a link.
Open the note