Can loss harvest tax for Capital Losses on stocks this year to offset Capital Gains from last year?

I have capital gains from selling stocks in 2021, but I have capital losses from stocks in 2022. Can I offset the gains from last year for tax purposes in current year?