Perhaps it's no surprise that a Frenchman, Melchisedec Thevenot, invented the first spirit vial by filling a glass tube with wine. When he lashed the vial to a flat stone ruler in the 1660s, astronomers had an accurate tool with which to orient their newfangled telescopes. Today's vials are still full of booze, because alcohol doesn't freeze.
Vials these days are made out of glass (a), bored-out blocks of solid acrylic (b), or injection-molded plastic (c). Any one of these can do the job, but acrylic block vials are generally the most accurate and durable.
In addition to a bubble, a vial needs at least two lines approximately one bubble's length apart to show us when the level is, indeed, level. Some vials, such as the the Vari-Pitch (c), have extra lines to show gradations of pitch for specialized applications like drain pipes, gutters, patios, or any other job that requires a precise but nonstandard slope.