Stores are struggling, but the office market is booming.

Those two trends aligned this week when the San Francisco Planning Commission unanimously approved the conversion of two upper floors at Westfield mall, the city’s largest shopping center, into office space.

It’s the latest example of sites built for retail making way for offices. The recently sold 6X6 mall, a block away at Sixth and Market streets, has received approval to convert nearly 50,000 square feet of space to offices. The former Macy’s Men’s Store at 120 Stockton St., the former Saks Fifth Avenue Men’s Store at 220 Post St., the former Britex Fabrics building at 146 Geary St. and former retailer Loehmann’s outpost at 222 Sutter St. have all sought approval to convert some of their upper floors to offices.

The Westfield mall plans to convert 49,999 square feet of space on the seventh and eighth floors to offices. The floors, currently used for retail, storage and meetings, are part of a larger $75 million renovation that includes a facade with more glass and three rooftop terraces facing Market Street.

The mall, formally known as Westfield San Francisco Centre, consists of two parts: the nine-story 865 Market St. building anchored by Nordstrom, and the former Emporium building at 845 Market, anchored by Bloomingdale’s and Century Theatres. The Nordstrom building on the corner of Fifth and Market is where the changes are planned, essentially converting the department store’s top two floors.

“Office use is good for retail. In this case, offices on the upper floors will benefit Nordstrom and the other retail tenants by increasing the community of consumers around and directly within the center,” Chris Kitchen, Westfield’s vice president for development, told The Chronicle.

San Francisco office buildings have filled up with tenants in the fast-growing tech industry. Demand is soaring, but a 1986 city law, Proposition M, limits the total amount of office space that can be approved each year.

By proposing about 50,000 square feet, Westfield had an easier time with the Prop. M restriction than some larger projects.

In October, Mayor London Breed put a measure on the March ballot that would have increased the amount of office space the city can approve, which is now 875,000 square feet annually. The mayor dropped the measure this week. It would have competed with San Francisco nonprofit Todco’s measure restricting office development if the city fails to meet its affordable housing goals.

The Bay Area is home to the nation’s most competitive office market, according to a recent report by Colliers International, a commercial real estate firm. A third-quarter report showed the Bay Area with the lowest office vacancy rate, at 5.4%, and an average asking rent of $86.22 per square foot, ahead of Manhattan and Seattle, its closest competitors.

“The biggest demand for office space comes from tech companies,” said Stephen Newbold, director of office research for Colliers.

Meanwhile, retail isn’t doing too well. San Francisco is littered with empty storefronts as retailers grapple with the shift to online shopping, along with city permit processes that can take up to 18 months and sky-high rents. Unused or underused retail space could help meet office demand, Newbold said.

Even the posh Union Square shopping district has seen more offices arrive.

“There is less demand for retail space in Union Square, and it is particularly hard to find retail tenants who are interested in filling the upper floors of a building — even in a shopping center,” said Karin Flood, executive director of the Union Square Business Improvement District. She said she supports Westfield’s efforts and would rather see spaces filled than be empty or underused.

Jesse Gundersheim, San Francisco director of market analytics at CoStar, said in an email that while there is strong demand for office space, compared with retail, it is “directly beneficial to fewer (people), and adds little to neighborhood appeal.” But the space being converted to offices was unsuccessful at drawing retail, he noted — so offices are certainly better for the neighborhood and the economy than vacant store space.

Some malls, like Stonestown Galleria on the west side of San Francisco, are looking to add housing, in another attempt to stabilize the customer base for stores. Other malls nationwide are even turning to hotels, according to Julie Taylor, executive vice president at Colliers.

“I think people desire a setting where they can live, work and play all within walking distance,” she said.

“A large-size mall property allows the creation of an urban village that can’t really be developed elsewhere in major cities,” she added. “Mall properties are often easy to access and they are close to freeways. When you bring in housing, jobs and hotel rooms, you’re extending how much time people spend at the mall itself, creating more opportunities for businesses, which can be crucial, for retailers particularly.”

At the Westfield mall, Nordstrom will remain the second-largest tenant behind Bloomingdale’s despite losing floors 7 and 8. It would occupy floors 4 through 6. The shopping center already has office tenants on its Emporium side, including San Francisco State University, SF Media Co., TrustArc and Hyperdrive Agile Leadership.

Kitchen said there is already strong interest in the new office space from a variety of different businesses, though he declined to give names.

“The location, its direct connection to transit and the shopping center amenities make it particularly appealing to office tenants,” Kitchen said.

Shwanika Narayan is a San Francisco Chronicle staff writer. Email: shwanika.narayan@sfchronicle.com Twitter: @shwanika