Retirement tax questions

To confirm, the earnings on an excess contribution to a Roth IRA are taxable in the tax year the contributions were made, correct? Not when they were removed? I contributed to a 2017 Roth IRA, but withdrew the excess contributions to that 2017 Roth IRA in 2018 prior to the tax due date. There were earnings on the excess contributions removed, but those are taxable in 2017 and NOT 2018 because I made contributions during the 2017 tax year. Is that correct?