The answer, as with many such equations, depends largely on the variables, and one option doesn't win outright over another. We'll ponder the energy required to do both, and a few variables that change with every purchase, like packaging, and a few that are tough to put a number value on, like the relative value of supporting a local Mom & Pop Shop down the block. With that in mind, and, as always, considering that the greenest purchase is the one you've already made, let's begin.
The case for online shopping
This really comes down to scale. All products have to be shipped from the warehouse where they're stored after manufacture, and it can be quite a bit greener to cut the retail store -- and all the building, lighting, cooling, heating, and so forth that the store requires -- out of the equation. According to the Center for Energy & Climate Solutions, shipping two 20 pound packages by overnight air -- the most energy-intensive delivery mode -- still uses 40 percent less fuel than driving 20 miles round-trip to the mall or store or wherever you're going; ground shipping -- which is much more efficient than overnight air -- checks in at just one-tenth the energy used driving yourself.
How does that work? While your car is likely to get more miles per gallon than the truck that's likely shipping your stuff (truck freight accounts for about 2/3 of U.S. domestic shipping), your car only has you (and maybe a passenger), while the truck can be hauling up to about 30 tons of cargo (that's a fully-loaded truck at the legal limit for gross vehicle weight). So you, your buddy, your car, and your 40 pounds of package (on the way home) burn about one gallon of gasoline in those 20 miles.
Shipped 1,000 miles in a truck, your package accounts for about 0.1 gallon, and if you choose to ship by air freight, that number hops to 0.6 gallons; it's all thanks to the hundreds of other packages that are presumably along for the ride. And, even though your online order doesn't go from warehouse to your front door in the same loaded truck or airplane, companies likeFedEx and UPS are working to upgrade the efficiency of their routes and fleets, since faster, more-efficient service saves them money.
The case for shopping in stores
This comes down to real-world details. It'd be great if everything could be as efficient as the numbers above bear, but there's more to the process than just shipping. Shopping online results in 2.5 times more packaging than shopping in stores, so having many separate packages shipped can really add up. New Yorkers, for example, left more than 8,300 tons of cardboard and mixed paper to be recycled in the first full collection week after Christmas 2005, a 21 percent increase over the previous year. While all that can be recycled, it takes energy and infrastructure to do so.
Plus, every trip you make to the store isn't 20 miles round-trip, and every mile you don't drive to the store cuts back on the energy required to retrieve your stuff. If you live in a dense urban area, or have access to reliable public transportation, then a portion (or just about all, if you're walking) of your transportation energy is negated, and can tip the scale toward the brick 'n mortars.
A few other options to consider buying from retail stores include: Goods made locally; stuff that you are more likely to return (like clothes) if you can't try it on first; and, supporting stores who are owned and operated by locals, pay local taxes, and make where you live a more interesting and vibrant place. It's tough to put a price tag, environmentally or otherwise, on the social aspect, but it's important to consider.
Green shopping: and the winner is...
...different depending on what your priorities are, and how you do it.
Shopping online is better: If you live in the suburbs, or are surrounded be Mega-Marts, have to drive more than six or eight miles each way to go shopping, are scrupulous about bundling online orders, choose ground shipping rather than overnight air, and are more concerned about fossil fuel use than packaging waste/recycling.
Shopping in-store is better: If you can get what you need at a location that shows up on within walking distance, can ride your bike (or take the bus or subway) to your store of choice, or are buying goods made locally, you're better off trundling down to the Stop 'n Shop.