At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
The density of what? There are slightly different mechanisms, depend on what you mean.
The easiest is teh density of a gas. The density of a gas is just determined by the size of the container it's in, since gases always expand to fill the container. Now, if the container is exerting a constant pressure, and can expand and contract, such as when the gas is contained in a balloon, then the gas can expand (and lower its density) at higher temperatures because it exerts a higher pressure on the walls of the container.
And the reason the gas exerts a higher pressure at higher temperatures is because the gas exerts pressure by its constituent atoms or molecules colliding with the walls. When you raise the temperature, the atoms and molecules travel on average at a higher speed, so each collision gets a little harder -- exerts more force.
Now if you are talking about a liquid or solid, the process is sligthly different, although conceptually similar. In this case, the "container" for each atom or molecule in the liquid or solid is the other, surrounding, atoms or molecules, which press in on it on all sides, or in some cases (metals and network solids, like diamond or glass) the chemical bonds holding the entire solid together. When you heat these substances, then once again the atoms and molecules start moving faster, and when they "collide" with the "walls" holding them in position -- nearby atoms and molecules, or the limits of the chemical bond "chain" holding them in place, like a dog yanking on its leash -- then because they are going faster and have more energy, they will push back those walls a little further. On average, then, the positions of the atoms and molecules will be a little further apart -- which means the solid or liquid has expanded.
In either case, the essential driving force is the fact that the speed of atoms and molecules increases with temperature, and the expansion is a result of the fact that things buzzing around at higher speed take more force to hold in a given volume. If the confining force is constant -- does not itslf change with temperature -- which is often the case, then the constant force will be unable to confine the substance to as small a volume.
In a small minority of cases, certainly peculiar situations may lead to substances *contracting* with temperature. The most famous is the melting of ice: when you heat ice, it turns to water, which is *more* dense than ice, so in this case the substance contracts with heating. But that's somewhat unusual.