https://samnot.es/p/object-fit-css/

⚠️ All typical warnings apply when you’re taking web-dev advice from me ⚠️ What’s Object Fit? You can use it to fill a container with an image (or any replace element ). Unless you’re exceptionally lucky, your images don’t always fit perfectly into the containers you need them to. For example, here I’m trying to get this egg to fit into a nice round parent. But it’s not the right size.

Sam

# Why isn't object-fit doing anything? CSS Diaries

⚠️ All typical warnings apply when you’re taking web-dev advice from me ⚠️

What’s Object Fit?

You can use it to fill a container with an image (or any replace element ).

Unless you’re exceptionally lucky, your images don’t always fit perfectly into the containers you need them to.

For example, here I’m trying to get this egg to fit into a nice round parent. But it’s not the right size.

The photo doesn’t fit nicely in the circle

Even a cheeky attempt to replicate the curvature with “border-radius” ends badly,

The photo still doesn’t fit nicely in the circle

But with object-fit: cover;, magic!

The photo fits nicely into the circle

That’s just the start of object-fit’s powers, read more here.

You can check this demo here.

But wait it still doesn’t work for me

Fast forward to me anguishing for 30 minutes about why the card images on my home page aren’t filling the card!

The card isn’t filled

MDN Docs couldn’t help.

Turns out, for object-fit to work, the image itself needs both a height & a width set. Without them, no fit. In most cases, you will probably be setting to 100% for both, to match the parent size. I’m not sure why that’s not the default. Alas, I hope this will save you a few minutes of despair.

ARCHIVE

15 Apr 2026 A Little Humanity 13 Apr 2026 Hamlet - William Shakespeare 13 Apr 2026 The Rise and Fall of the Third Reich - William L. Shirer 13 Apr 2026 The Secret History - Donna Tartt 11 Apr 2026 A Year of Living Simply - Kate Humble 08 Apr 2026 40 Before 40 08 Apr 2026 Montaigne - Stefan Zweig 04 Apr 2026 William Shakespeare: A Very Short Introduction - Stanley Wells 19 Mar 2026 Unreasonable Hospitality - Will Guidara 15 Mar 2026 Hitler's Secret - Rory Clements 15 Mar 2026 Nemesis - Rory Clements 08 Mar 2026 HRV & Me: Taming a messy stressy mind 02 Mar 2026 Nucleus - Rory Clements 19 Feb 2026 Corpus - Rory Clements 08 Feb 2026 Resonance 16 Jan 2026 A Night to Remember: Sinking of the Titanic - Walter Lord 01 Jan 2026 Everything I've read in 2026 (so far) 15 Dec 2025 Someone from the Past (British Library Crime Classics) - Margot Bennett 01 Dec 2025 Death in Ambush (British Library Crime Classics) - Susan Gilruth 23 Nov 2025 A Cold Wind From Moscow - Rory Clements 10 Nov 2025 The Boleyn Traitor - Philippa Gregory 24 Oct 2025 Death Makes a Prophet (British Library Crime Classics) - John Bude 13 Oct 2025 The Cheltenham Square Murder (British Library Crime Classics) - John Bude 04 Oct 2025 Sussex Downs Murders (British Library Crime Classics) - John Bude 22 Sep 2025 The Lake District Murder (British Library Crime Classics) - John Bude 15 Sep 2025 The Mayor of Casterbridge - Thomas Hardy 10 Sep 2025 The Murder of Roger Ackroyd - Agatha Christie 30 Aug 2025 Marble Hall Murders - Anthony Horowitz 25 Jul 2025 Where Angels Fear to Tread -- EM Forster 10 Jul 2025 Steve Jobs -- Walter Isaacson 10 Jul 2025 The Fifth Risk -- Michael Lewis 10 Jul 2025 The Ride of a Lifetime -- Bob Iger 03 Jul 2025 James -- Percival Everett 01 Jul 2025 Great Expectations -- Charles Dickens 23 Jun 2025 Hillbilly Elegy -- JD Vance 10 Jun 2025 Principles 09 Jun 2025 Revenge of the Tipping Point -- Malcolm Gladwell 06 Jun 2025 The Grand Babylon Hotel -- Arnold Bennett 04 Jun 2025 The Seven Husbands of Evelyn Hugo -- Taylor Jenkins Reid 03 Jun 2025 Rebecca -- Daphne du Maurier 29 May 2025 A Promised Land - Barack Obama 29 May 2025 Less - Andrew Sean Greer 13 May 2025 Careless People - Sarah Wynn-Williams 07 May 2025 Looking Glass War - John Le Carre 04 May 2025 A Murder of Quality - John Le Carre 01 May 2025 London Marathon 2025: Training Retrospective 29 Apr 2025 The Human Factor - Graham Greene 28 Apr 2025 London Marathon 2025: Race Review 27 Apr 2025 Photos: London Marathon 2025 27 Apr 2025 Spectating the London Marathon 2025 [Sunday 27th April] 26 Apr 2025 London Marathon 2025: Week 16 23 Apr 2025 Call for the Dead - John Le Carre 21 Apr 2025 London Marathon 2025: Week 15 16 Apr 2025 The Manchurian Candidate - Richard Condon 13 Apr 2025 London Marathon 2025: Week 14 05 Apr 2025 London Marathon 2025: Week 13 30 Mar 2025 London Marathon 2025: Week 12 26 Mar 2025 Effortless - Greg Mckeown 23 Mar 2025 London Marathon 2025: Week 11 16 Mar 2025 London Marathon 2025: Week 10 09 Mar 2025 London Marathon 2025: Week 9 02 Mar 2025 London Marathon 2025: Week 8 22 Feb 2025 London Marathon 2025: Week 7 16 Feb 2025 London Marathon 2025: Week 6 16 Feb 2025 Problems & [Meta] Problem Solving 14 Feb 2025 Little Dribbling - Bill Bryson 10 Feb 2025 Bring Up the Bodies - Hilary Mantel 09 Feb 2025 London Marathon 2025: Week 5 09 Feb 2025 Three Zero 03 Feb 2025 The iPad mini has genuinely changed my life [no hyperbole] 02 Feb 2025 London Marathon 2025: Week 4 28 Jan 2025 Coming AI: Valuing Humans in a world where they have no economic value 28 Jan 2025 Value & Price 27 Jan 2025 The Vegetarian - Han Kang 27 Jan 2025 Wolf Hall - Hilary Mantel 26 Jan 2025 London Marathon 2025: Week 3 19 Jan 2025 Deriving my own proof for Unitary matrices 19 Jan 2025 London Marathon 2025: Week 2 17 Jan 2025 David Copperfield - Charles Dickens 12 Jan 2025 London Marathon 2025: Week 1 09 Jan 2025 NYC & DC '24 08 Jan 2025 Linear Algebra Playground 07 Jan 2025 Configuring an IKEA wireless light switch: Saving you the pain 07 Jan 2025 Goals & Goal-setting 06 Jan 2025 Digital Feeds 05 Jan 2025 London Marathon 2025: Training Begins 01 Jan 2025 Everything I've read in 2025