Avoiding or legally minimizing capital gains taxes on stock investments involves utilizing specific structural strategies, such as holding securities within tax-advantaged accounts like Traditional or Roth Individual Retirement Accounts (IRAs) and employer-sponsored 401(k) plans where assets grow and can be sold tax-free or tax-deferred. Additionally, investors can implement tax-loss harvesting by offsetting realized profitable gains with portfolio losses, donate appreciated securities directly to qualified charitable organizations through donor-advised funds, or utilize long-term holding strategies that qualify for lower marginal tax brackets.