In fact there were two different styles of uniform, originating at different times. From this article:
The jumpsuit uniforms created for the first season had zippers on the front. When the newer uniforms (which zipped up in the back) were introduced in season 3, the older style uniforms continued to be used by background characters. Sometime after that, these uniforms were modified to more closely resemble the newer uniforms, however, they retained their front zipper. Interestingly this is also why some of the Science/Medical uniforms are a different color than others, as the new uniforms were made using a different fabric than the old ones.
One at least one occasion, a combination of the two styles (and some fancy camera work) was used to allow a crew member to open a uniform that appeared to be of the newer style from the front, as if by a hidden 24th century closure.
The short answer is that in-universe, they had an invisible zip up the front. Technology had advanced a long way by the 24th century, including apparently the ability to have invisible clothing closure. From Memory Alpha:
William Ware Theiss's original first and second season uniforms reportedly caused the cast discomfort as the tight-fitting (and revealing) spandex pulled down on the actors' backs. With his arrival at TNG during season three, costume designer Robert Blackman's first charge was the modification of the existing design to make Starfleet-wear more bearable. Experimenting with different materials, Blackman utilized a jumpsuit-style form-fitting wool gabardine material in the early days of season three, before ultimately settling on looser-fitting versions consisting of a jacket and trousers.
The Theiss-designed costume remained unmodified for use by background actors until season four, when they were altered to reflect the new look. They are easily spotted next to the two-piece uniforms, distinguished by their prominent front zipper.
In keeping with Gene Roddenberry's idea that there are no zippers or other contemporary closures by the time of Picard and company, the TNG-style uniform demonstrated the miraculous ability to open from the front like a jacket in the episode "Ensign Ro". To achieve this illusion, producers used both a jumpsuit-style uniform and a two-piece jacket and trouser combination, indicating amazingly undetectable closure technology.
For more details about the complaints generated by Roddenberry's Spandex uniforms, and the improvements made by Blackman, see this article. (Previously I quoted it at length in this answer, but - although it's interesting - I decided the Memory Alpha quote is good enough.)