Overuse of floats considered harmful (23:58 -0500)
I've been meaning to write about this for the past few months, since
Alex Robinson's article
In
search of the One True Layout came out (after some discussion on it
in a bug).
Better late than never, anyway.
The article describes a technique that uses floats very
differently from their intended use. Floats were intended to be used to
take small pieces of content out of the flow and let the rest of the
text wrap around them. They were not intended to be used for the main
content of a page, nor were they designed for it. Nevertheless, use of
floats for the main content of a page is quite common today.
Worse, it is relying on extremely
obscure details of how floats are currently implemented: details so
obscure that nobody had previously thought to describe them in the CSS specification. This means
that widespread use of this technique will mean that all future browsers
have to get all of those obscure details correct.
I see this situation as similar to the use of tables for layout that
is now quite widely accepted as misuse. The current overuse of floats
is often done with the goal of fixing one of the problems
caused by the misuse of tables: incorrect use of semantic markup.
However, it is repeating other problems caused by misuse of tables:
- Makes it harder to write Web browsers
- It means Web browsers (and specification authors) need to get details
the same when those details shouldn't even matter. It means that more
work needs to be put into a smaller number of features, and the new
features (which might alleviate the need for this misuse) don't get any
attention (and aren't implemented) or get less attention (and have more
bugs).
- Makes it harder to improve Web standards
- Authors' dependence on very obscure details of how floats lay out
means that those details can't be improved later (just as the default
presentation of tables on the Web cannot be improved). It means that
future versions of CSS can never improve what happens when authors
want to take a small piece of text or an image out of the flow
(the intended use of floats) without requiring those authors to specify
an extra property that says "do it right". Authors (collectively) need
to either avoid misuse of existing standards or recognize that the
default behavior of standards, once implemented, can never be improved.
I hear demand for both from authors, but it's a choice that can't go
both ways.
- Reduces pressure for implementation of better technology
- In addition to taking resources away from building better solutions
to the problem, misuse of existing techniques reduces pressure for
standards organizations and browsers to develop such new solutions. In
this case, that means a better solution for content reordering. For
other uses of floats, it means a better way of doing page layout based
on intrinsic sizes.
In summary, misuse of Web standards both (1) hurts the intended use
and (2) reduces the chance that a better solution for the problem will
exist in the future. Slowing down the rate of “progress”
today might help speed it up in the future.