I'm a non-physicist with a basic high-school understanding of physics. I've always wondered what it is that makes things "solid". Why do molecules rebound from each other? There's just a bunch of tiny atoms there with (comparatively) large spaces between them. Why don't they just "slide" around or between each other?
What makes it solid is a combination of the uncertainty principle and Pauli's exclusion principle.
According to the uncertainty principle, electrons can't have a well-defined position if they have a sufficiently well-defined momentum (mass times velocity). For the energy of electrons to be low enough, the momentum also has to be low enough. That also means that the uncertainty of the momentum has to be low enough.
The uncertainty principle then implies that the uncertainty of the position of the electron has to be large enough, at least 0.1 nanometers or so - the atomic radius - for the kinetic energy to be smaller than a few electronvolts, a decent amount of energy that is comparable to the potential energy of electrons near protons if the electron clouds is similarly large.
Pauli's exclusion principle then guarantees that in each volume comparable to the volume of an atom, there can be at most 1 (or 2) electrons. That's why matter is impenetrable.
By the way, to derive the actual maximum density of electrons, one also needs to know the strength of the electrostatic attraction between the electrons and the protons that neutralize the charge. The Bohr radius goes like $1/\alpha$ - the inverse fine-structure constant - so if the electric force were stronger, matter could actually become denser.
This was an explanation why matter based on nuclei and electrons can't really significantly exceed the density of ordinary materials. Still, there are different phases. In gases, the molecules are separated by big gaps - so most of the space is empty and the exclusion principle is not too important. For liquids, the distance between the molecules is near the saturation point - like dense gases - but they still don't keep the shape.
Glass is an example of a liquid, in some sense, that is however behaving almost as solids. The canonical solids prefer to be crystals - like metals or diamond. In that case, it's energetically favored for the atoms or molecules to be organized to regular cubic or hexagonal or similar lattices. They like to keep this shape because it saves energy. It's still true that such solids are impenetrable because of the explanations at the top.
5$\begingroup$ The idea that glass is really a liquid is controversial. $\endgroup$ Nov 14, 2011 at 3:44
$\begingroup$ "in each volume comparable to the volume of an atom, there can be at most 1 (or 2) electrons" - one atom may contain dozens of electrons $\endgroup$– M.MMar 9, 2016 at 3:46
1$\begingroup$ Dear @M.M - an atom may contain dozens of electrons but the volume of such an atom with a greater number of electrons is larger, too. The density of electrons per "volume of the hydrogen atom" is never too much higher. At the end, the density of elements is rather comparable. It's not an exact constant so there's a variability by an order of magnitude or so. But this is still a tiny variation relatively to the densities that are a priori possible - which may be smaller or greater by dozens of orders of magnitude, too. $\endgroup$ Mar 9, 2016 at 8:44