Why do egg whites turn white when you cook them?

When you crack open a raw egg, the egg white isn’t white at all—it’s more like a clear jelly. So why does it turn white when you cook it? Does that make it safe to eat? And what about egg yolks?