How to expand / collapse fields in forms

How to expand / collapse fields in forms

I am creating a form where if I click on check box, certain fields on the form get visible. I have seen on certain apps on marketplace. Not sure how can this be done?
Any help would be appreciated