we are getting the carpet replaced on the steps - excuse the picture, they are in bad shape!

Should I paint the white part before or after the new carpet gets installed?

I was thinking before but not sure if it will get scratched during the install?