The S&P 500 had a good month of July, but on a year-to-date basis, it's still down 13%. And the challenge is that with inflation still running high and companies facing headwinds due to rising costs, the worst may still be ahead. Many stocks could continue to fall further in value. 

Typically, you might think that growth stocks are better options to hold, and lead to better gains. But this year, investors have been clamoring for safety, which dividend stocks can sometimes offer as their businesses normally are profitable and have better fundamentals.

Two dividend stocks that have been beating the markets by wide margins this year include Eli Lilly (LLY -2.02%) and ExxonMobil (XOM -0.26%). And here's why they could still climb higher as the year goes on.

1. Eli Lilly

Drugmaker Eli Lilly has seen its share price rise 9% thus far in 2022. Those are modest gains, but that's still a market-beating return that doesn't include its dividend, which yields 1.3% (slightly below the S&P 500 average of 1.6%).

The healthcare sector has been a relatively safe place to invest in this year as hospitals have resumed their normal day-to-day operations, prescriptions are up, and businesses are doing better. This month, Eli Lilly released its second-quarter numbers, which showed sales of $6.5 billion for the period ended June 30, down 4% year over year; however, this falls to a decline of just 1% when factoring out the impact of foreign currency exchange.

Many of the company's top-selling drugs generated impressive growth; diabetes treatment Trulicity brought in $1.9 billion in sales, which rose by 25% year over year. Breast cancer medicine Verzenio rose at a rate of 72%, with its sales coming in at $588.5 million. Eli Lilly is forecasting that its earnings per share will rise 14% to 16% this year.

In addition, the company also has many catalysts for long-term growth, including Mounjaro, a diabetes treatment that has also shown to be effective as a weight loss medication. The Food and Drug Administration is also reviewing its Alzheimer's drug donanemab, which could also give the company's top line a big boost -- analysts project that peak annual sales could hit $6 billion. 

There have been plenty of reasons to invest in Eli Lilly this year as it offers both stability and some terrific growth potential. And that's why it wouldn't be surprising for this to continue being a market-beating investment this year and beyond.

2. ExxonMobil

There's no mystery behind ExxonMobil's increasing share price -- oil prices are at levels they haven't been at in years. Even with the recent decline in the price of West Texas Intermediate (WTI), a key benchmark, it's still at around $88/barrel, which is higher than the $60/barrel or lower that it often traded at before the pandemic began.

As a result, the oil and gas producer's shares are up an impressive 44% this year. Rising oil prices have been a catalyst for the stock as the company can sell its products for more. Its second-quarter results last month confirmed a strong performance by the business with earnings of $17.9 billion for the period ended June 30, more than triple the $4.7 billion that ExxonMobil netted in the prior-year period.

Depending on how Exxon does from here on out is going to largely depend on the outlook for oil prices. And as of now, with the war in Ukraine looking like it isn't coming to an end anytime soon and pent-up travel demand being strong, I would expect oil prices to remain elevated (e.g. higher than pre-pandemic levels) in the short term.

ExxonMobil is also a top dividend stock to own. Today, it yields around 4% per year, which is far better than the S&P 500 average of 1.6%. It's also a Dividend Aristocrat, having increased its payouts for multiple decades.