Yes, you can compost dandelions – but a bit of care is needed.
Dandelions with their roots attached should be avoided as they have a tendency to regrow. Ditto heads of dandelions that have gone to seed: being put into a resource-rich growing medium then spread it around your garden is basically the seeds’ biggest wish come true.
Don’t forget though that for weeds, dandelions are actually pretty useful: the root can be dried and used as a coffee substitute, the flowers can be used to make tea or wine, and the leaves can be eaten in a salad or as a cooked green. And if you don’t fancy eating them, chickens, rabbits and the like enjoy them as a green snack too. It’s better to use them if you can, rather than just composting them.