The twinkling of stars is caused by the Earth's atmosphere. As starlight passes through the different layers of the atmosphere, it gets refracted and creates the twinkling effect that we observe.