CSS and the Paradox of Hilbert’s Grand Hotel

BrianDGLS
2 min readApr 21, 2016

--

The Grand Hotel has an infinite amount of rooms. All of which are occupied. However there is a room available to each new guest. One would assume this is impossible. A fully booked hotel cannot accommodate a new guest. The Grand Hotel is no ordinary hotel. As stated it houses an infinite number of rooms. But aren’t all the rooms occupied? Yes. So there are no rooms available? No.

In order to accommodate a new guest the staff at the Grand Hotel simply have to move the guests in room 1 to room 2. In room 3 to room 4 and so on. Repeating this pattern infinitely until all the guests have made the move from room n to room n + 1. After all this room 1 is now empty and ready to be occupied.

So what does a fully booked hotel that can accept an infinite number of new guests have in common with CSS?

Firstly lets take a moment to clarify specificity in CSS. Specificity is a weighted value applied to a CSS declaration. This weighted total is based off the selectors that have been used. When multiple rules target the same element this total is used by browsers to determine which rule should take precedence.

Theoretically a CSS declaration can have an infinite specificity. So if a declaration is infinitely specific it’s rules will be applied to the HTML element? Not necessarily. Just like the guests at the Grand Hotel if another infinitely specific declaration appeared further along the cascade it would be given precedence. Resulting in all preceding infinitely specific declarations moving from precedence n to n + 1.

If you understand CSS then this makes sense. There is no ground breaking revelation here. It simply describes the cascading nature of CSS.

The paradox of Hilbert’s Grand Hotel shares a lot in common with CSS. Which is interesting due to the fact that Hilbert’s Grand Hotel is used to describe the counter intuitive nature of infinite sets.

Web developers work with CSS on a day to day basis. It is a core technology of the web and it is fundamentally counter intuitive. Despite this web developers style huge and complex applications.

They do this without ever giving a thought to the paradox in which they are working.

So I extend my sympathy to those who write CSS and ask that they give a thought to the guests of Hilbert’s Grand Hotel, the next time they stare baffled at a cascading stylesheets.

--

--

BrianDGLS

Web Developer | Edinburgher | Pug Owner | Working @inviqa