Stock market indices like the S&P 500 and Nasdaq Composite are excellent benchmarks for tracking how the broader market is doing. But so are stock market sectors.

Each component of the S&P 500 is assigned to one of 11 sectors. For example, Apple is in the technology sector, ExxonMobil is in energy, JPMorgan Chase is in financials, etc. Tracking how a sector is doing relative to the market is a good way to gauge investor sentiment.

The utilities sector and the consumer staples sector both hit 52-week highs on Friday. That may come as a surprise given the growth-fueled narrative of today's market.

Here are the pros and cons of each sector, and why some investors are gravitating toward defensive pockets of the market.

A person smiles while leaning back in a chair and sitting at a table with a tablet with multiple plants in the background.

Image source: Getty Images.

The utilities sector

Many of the top holdings in the utility sector are regional electric utilities that work with regulatory agencies to set prices. The nature of their businesses ensures steady cash flows at the expense of limited growth. But some utilities, like NextEra Energy for example, are investing in renewable energy projects in a variety of geographies to spur growth and profit from the energy transition.

Many utilities use dividends to pass along profits to shareholders. In fact, utilities have the second-highest yield of any sector, behind only real estate and just ahead of energy. However, utility stocks tend to be far less cyclical than real estate and energy, making the sector one of the safest places for generating passive income.

Utilities make money from higher resource consumption, whether it's electricity, water, gas, etc. But they don't benefit as much from economic growth, which usually means utilities can underperform in strong bull markets. Seeing the utility sector hit a 52-week high on Friday is a sign that some investors are looking for value and a sector that can provide steady income no matter what the market is doing.

Two exchange-traded funds (ETFs) that could provide good starting points for investing in the sector are the Utilities Select Sector SPDR Fund (XLU -0.10%) and the Vanguard Utilities ETF (VPU -0.17%). Both funds yield 3.3% and have expense ratios of 0.1% or less.

The consumer staples sector

The consumer staples sector is often seen as one of the most recession-proof places to invest. And for good reason. This includes such companies as Procter & Gamble, Costco Wholesale, Walmart, Coca-Cola, and PepsiCo. These companies have some discretionary products that benefit from higher consumer spending. But in general, consumers are likely to cut their spending on goods or services they don't need more so than on groceries, household essentials, or relatively low-cost food and beverages like soda and snacks.

Many top consumer staples companies have multi-decade track records of paying and raising their dividends. For example, P&G, Walmart, and Coke are Dividend Kings with over 50 consecutive years of dividend increases.

With investing, it's crucial to understand what you own and why you own it. You're probably familiar with most, if not all, of the top holdings in the consumer staples sector. But probably not as much with the utilities sector. Therefore, the consumer staples sector definitely tops utilities regarding relatability. The sector has a slightly higher price-to-earnings ratio than utilities and a slightly lower yield -- but not by much.

Top ETFs like the Consumer Staples Select Sector SPDR Fund (XLP -0.78%) and the Vanguard Consumer Staples ETF (VDC -0.88%) yield over 2.5% and have expense ratios of 0.1% or less.

An added benefit of choosing consumer staples over utilities is that these companies generally have more upside. Utilities and consumer staples both benefit from higher consumption and a growing population. But consumer staples have more control over their businesses. P&G and Coke did a phenomenal job of using their pricing power to offset the impact of inflation. Utilities tend to not have that much flexibility.

Investors looking for a little less income and value but a little more growth may prefer consumer staples over utilities.

Sector rotation can move the market

Stock prices can do just about anything in the short term. Sector price action is similar, just on a larger, more correlated scale.

Traders will often rotate in and out of sectors depending on what's working or not working in the stock market. The issue with that strategy is you have to be right twice -- knowing when to sell and knowing when to buy back in. There are also potential tax consequences, like short-term gains and wash sales. It's just an overall stressful strategy that is too dependent on the whims of the market rather than fundamentals.

A far better and simpler approach is to build positions in companies you like and compound wealth over time. A key aspect of that strategy is to put more capital to work in the market through regular savings. That way you don't have to sell a position to buy another.

Investors looking for safer options amid increased market uncertainty could choose a utility or consumer staples ETF or stock. However, it's important to understand why these sectors are popular right now and the motives behind the recent run-up in prices.

The balance between greed and fear can pull on the market and create drastic price volatility. But fundamentals often smooth out these ebbs and flows over the long term. So if you decide to buy a utility or consumer staple security, make sure it's for the right reasons, and is backed by a sound investment thesis.