To contribute to a Traditional or Roth IRA, you must have earned income. Earned income is based on what you reported on your tax return, and it means money that you earned from a paycheck or self-employed income.
The only exception to this is if you are married and you're a non-working spouse. In that case, you can open what's called a spousal IRA and contribute to that even though you do not have earned income.
Also, keep in mind that you can't contribute more to your IRA than you have in earned income.
Example #1: You are unemployed at the moment, but you were employed for a few weeks in 2020. You reported (or will report) $4,000 on your 2020 tax return. Since you have earned income for 2020, you qualify to make a 2020 contribution to your Roth or Traditional IRA. But since you can't contribute more than you have in earned income, the most you can contribute for 2020 is $4,000.
Example #2: You were unemployed for all of 2020, but you started working again in 2021. Since you don't have any earned income for 2020, you don't qualify to make a 2020 IRA contribution. You can, however, start making 2021 contributions once you start earning money at your new job.
Example #3: You do not work (i.e. you're a student, stay-at-home parent, etc.), but you are married and your spouse has earned income. Thus, you qualify to make a contribution to a spousal IRA (which can be either a Roth or Traditional).