I’ve been thinking of this for a while now, and it’s finally time to part ways with the overflow: hidden (and overflow: auto) clearing hack. Jeff Starr’s recent and excellent post – The New Clearfix Method – and the ensuing comments were enough to finally prompt me to write about it here. (And since I started writing this, Jonathan Snook has started a Twitter dialog about overflow vs. clearfix).
While the clearfix method is a tried and true hack, I’ve always disliked muddying up my HTML markup with crufty “clearfix” classes strewn about. So I ended up using overflow: hidden as much as I could. But overflow: hidden is not without its drawbacks. Although there is no extra class to apply in the HTML (win!), there may be situations when you want to have child elements positioned partially (or entirely) outside of their overflow: hidden wielding parent (or other ancestor) container. In these cases, the container with overflow: hidden will clip the element that you’re trying to partially (or entirely) position outside of it. (Case in point: If you use suckerfish dropdowns, try setting overflow: hidden on the outermost list).
So although overflow: hidden is not usable in all situations, I used to prefer it over using the “clearfix” class method. But in reality I ended up with both: I had overflow: hidden where I could get away with it, and “clearfix” classes where I couldn’t use overflow: hidden. It bothered me a bit to mix and match two different clearing methods, but I was happy to have fewer “clearfix” classes violating my otherwise semantic markup Kumbaya festival.
Then in his presentation at An Event Apart 2008 in San Francisco, Dan Cederholm suggest using the class name “group” rather than “clearfix” – a suggestion which later made it into his book Handcrafted CSS. It’s a minor thing, but I do like the improved semantics (in most cases) of the “group” class name over the “clearfix” class name, so I adopted this approach and felt okay about using it as a fallback when overflow: hidden wasn’t feasible.
In his talk and in his book, Cederholm also walks through the “big long list” idea of applying the rules for the clearfix (renamed to “group”) class directly to the selectors that need them in the CSS.

This keeps the HTML more pure while avoiding the drawbacks of overflow – a total win-win. But it does mean extra bloat in the CSS. Probably okay for smaller sites, but it can quickly get unruly with larger sites. I tried this approach on a few projects and decided the CSS bloat was indeed too much, so I stuck with the mix of overflow: hidden and the “group” class.
The Catalyst
But I’m now saying goodbye to overflow: hidden and the deciding factor for me is CSS3. Specifically box-shadow. At least in the sense that box-shadow was the first property I noticed being negatively impacted by the use of overflow: hidden. Like the positioned child elements mentioned above, box-shadow can get clipped when the parent (or other ancestor) element has overflow applied.
And there are several other things to consider as we move forward using more CSS3. Text-shadow and transform can also potentially be clipped by overflow: hidden (see the demo).
As we rely more and more on CSS3 properties we can rely less and less on overflow as a clearing method. So I’ll be abandoning overflow and relying upon clearfix (Jeff Starr edition) via a mix of the “.group” class in the markup and the “big long list” approach.
Suggested Reading
- Handcrafted CSS: More Bulletproof Web Design (book) by Dan Cederholm. Includes and example of the ‘.group’ clearfix class.
- Bulletproof Web Design: Improving flexibility and protecting against worst-case scenarios with XHTML and CSS (book) by Dan Cederholm.
- Designing with Web Standards (3rd Ed.) (book) by Jeffrey Zeldman.
- The New Clearfix Method (article) by Jeff Starr.

Comments, Quips & Protestations
1 December 10, 2009 1:50 pm Mark Aplet
2 December 10, 2009 2:52 pm Andy Ford
3 December 11, 2009 4:10 am Jonas
4 December 11, 2009 4:48 am Goran Tepshic
5 December 11, 2009 6:07 am Kyle Rush
6 December 11, 2009 6:19 am Barney
7 December 11, 2009 7:54 am Andy Ford
8 December 11, 2009 11:45 am Anthony Calzadilla
9 December 12, 2009 5:11 pm Ivan
10 December 13, 2009 10:30 am Andy Ford
11 December 14, 2009 1:14 am Webstandard-Team
12 December 14, 2009 11:10 am Jeff Starr
13 December 14, 2009 5:06 pm alex
14 December 14, 2009 5:08 pm alex
15 December 16, 2009 1:50 pm rodman
16 January 27, 2010 2:30 am Webstandard-Blog
17 May 6, 2010 12:07 pm blowfish
18 May 10, 2010 10:50 am eednew
19 July 27, 2010 5:12 pm Chris Eppstein
20 July 27, 2010 5:43 pm Andy Ford
21 September 1, 2010 11:16 am Catherine Azzarello
22 January 17, 2011 3:48 pm Phillip
23 January 18, 2011 8:11 am Andy Ford
24 July 26, 2011 5:08 pm Esmalte
25 February 12, 2012 2:45 am Norbert
26 April 25, 2012 10:45 am Feria de artesanos