Why does liquid take the shape of the container?

Because the atoms of the substance are able to spread out and move freely.