As demand for traditional brick-and-mortar retail dwindles, San Francisco’s Union Square is peppered with vacant storefronts and partially empty buildings. Meanwhile, there’s plenty of demand to fill the vacancies another way — office space.

But Supervisor Aaron Peskin bristles at the idea of the historic shopping mecca becoming overrun with desks and computers. So in an attempt to insulate Union Square as a place for retail, he proposed legislation Tuesday that would ban new offices from occupying the first three floors of buildings in the area.

“Contrary to the emerging thinking and reporting, retail is not dead,” Peskin said. “And San Francisco is really getting ahead of the curve and making sure that we preserve some of the best destination retail spaces that San Francisco and urban America has.”

The retail landscape has experienced an upheaval over the past few years as shopping has moved online, leaving stores with fewer customers. That has caused longtime tenants in Union Square, such as Macy’s and Saks Fifth Avenue, to downsize in recent years.

But some experts worry that banning office tenants on the lower floors would actually increase vacancies in the area.

Karin Flood, the executive director of the Union Square Business Improvement District, said that while she agrees the ground-floor spaces in buildings should be reserved for retailers, property owners should have flexibility in deciding how to fill the floors above.

“We strive to have a very vibrant and dynamic district, but at the same time our property owners would like some flexibility in use, as we know that retail is shrinking,” she said. “In some cases it will be very hard to lease space, especially on the edges of our district.”

Non-retail spaces are currently allowed on ground floors in Union Square buildings if they offer on-site services to the general public, such as nail and hair salons. All types of non-retail, such as office space, are allowed on the floors above and only requires a specific authorization from the Planning Commission if the space is larger than 5,000 square feet.

Under Peskin’s proposal, all types of new office space would be prohibited on the first three floors. Office space would be allowed only on floors four through six if the tenant occupies less than 5,000 square feet or allowed over that size if the Planning Commission concludes that the space “does not detract from the retail environment” in Union Square. Offices would be allowed on floors seven and above.

Existing non-retail on the first three floors would be grandfathered in, but would not be able to expand.

The legislation would also add a one-time infrastructure impact fee of $4 per square foot, which would provide funding to improve existing public spaces in the area, such as Hallidie Plaza.

Buildings such as 222 Sutter St., the former Britex Fabrics building at 146 Geary St. and the Macy’s men’s store were all seen as potential office spaces.

After a number of proposals to convert retail space into office use, Peskin proposed interim zoning controls, which put a halt on applications to convert retail. These controls were approved by the Board of Supervisors in May for 18 months or until permanent permitting controls are passed.

While Peskin said retail is not dead, he agrees that it has certainly changed.

“As the Amazon effect is becoming more pronounced, the nature of retail in a place like Union Square is changing to be more of an experiential retail experience,” he said. He mentioned the Apple and Nike stores as examples where customers often go in to try a product before going home and buying it online.

Even though some of the biggest names in retail — such as Macy’s, J.C. Penney and Sears — have experienced sweeping closures in recent years, niche, online-only companies are increasingly seeing the value in opening up actual stores that mostly act as showrooms. Some recent examples include the eyewear company Warby Parker in Union Square and online clothier Everlane in the Mission.

But Matt Holmes, a principal with the retail brokerage Retail West, said it is unrealistic to expect such retailers — who often prefer smaller, and sometimes temporary spaces — to fill up multiple floors in Union Square.

“You’ve got retailers who are getting much more efficient on how they are operating brick-and-mortar,” Holmes said. “It’s less of a shopping experience and more of an information showroom.”

Instead, he said, office space could actually be a good way to liven up the area, as it would attract a consistent population of people who come in and out every day and add traffic to the streets during lunch and coffee breaks.

“Union Square would benefit greatly from getting locals down there who work five days a week to mesh in with the tourists, and put more bodies on the streets,” he said. Forcing retailers to occupy the first three floors is “force-feeding them into an operating matrix that is so out of vogue.”

After walking through Union Square on Tuesday afternoon, Julie Taylor, the executive vice president of Colliers International real estate, said while there was a lot of foot traffic, the area’s vacancies looked like they are nearing “recession levels.”

But she said that allowing only retailers to occupy the bottom floors is like holding “spaces hostage and preventing them from being occupied.” Another factor hurting business in Union Square, she said, is the number of homeless people and amount of open-air drug use.

What the city should be focusing on, she said, is attracting retailers to the ground floors — and cleaning up the streets around them.

“You care about what you see through the storefront windows; you don’t care about who is on those upper floors,” she said. “As long as it is a vibrant, clean and safe area ... that is what the city should be focusing on.”

Trisha Thadani is a San Francisco Chronicle staff writer. Email: tthadani@sfchronicle.com Twitter: @TrishaThadani