Some of the earliest buildings that could be called apartments were seen in ancient Rome and the cities of the Roman empire; five or six-story brick structures called "insulae" (islands) housed multiple families. However, as these cities fell to ruin, the concept of the apartment house disappeared until the 1800s, when European cities were getting crowded. At that time, particularly in France, the idea recurred.

The first American apartment building (as opposed to a boarding house) appeared in the United States in the 1850s. Gwendolyn Wright's Building the Dream claimed the first was in 1855 in Boston; it was called the Hotel Pelham. However, panamaus notified me of the two Pontalba Apartment Buildings in New Orleans, which were constructed 1848 to 1850 by the French baroness Micaela Pontalba.

The idea of having three or more sets of tenants under a single roof, with more than just a bedroom for each set, was controversial; it was seen as a flighty single or newlywed's way of putting off real domestic life. It was also seen as slightly risque to live all on the same floor and so close to one's neighbors. They were called "French flats" for some time, as a way to evoke sophistication and also because that's where the idea had come from. And the early "apartment-hotels" were aimed at the rich; by 1869 when the Stuyvestant Flats were being built in New York, their rents were $900 to $1800 per year, when the entire five-floor building had cost only $150,000 to build. (In addition to being popular, they made efficient use of scarce city real estate.)

In the latter half of the 1800s, apartment houses contained luxuries that most houses did not have yet, such as running water and central gas mains -- even electric lights run from a generator for the building, since there were no street lines before the 1890s. Most of them had, in addition to common laundry rooms, kitchens in the basement where food was made for all the occupants, to be delivered to their apartments; in fact, in 1878 a New York court ruled that the presence of central kitchen and other services was what made a building an apartment (high-class) rather than a tenement (definitely low-class). However, there were still some similarities to tenement buildings -- very few windows (or windows that opened out onto the air shafts instead of the outside), thin walls which let sound carry, dark halls, and cramped rooms. However, there were usually impressive public lounges where one could entertain.

Some people felt that apartment buildings were a step forward; authors like Edward Bellamy in his Looking Backward painted a future where everyone had the advantages of technology and centralized services. However, many others felt that apartments were slightly decadent, that they encouraged women, particularly, to neglect household duties, and that the close quarters encouraged promiscuity. Architects tried to counteract these impressions by putting servants' quarters on separate floors from their employers' apartments, adding a homey look to rooms by putting in fireplaces, and increasing privacy with better sound insulation. But as in Edith Wharton's book The Age of Innocence, the closeness of public and private areas in one person's home seemed "architectural incentives to immorality such as the simple American had never dreamed of. That was how women with lovers lived in the wicked old societies, in apartments with all the rooms on one floor, and all the indecent propinquities that their novels described."

By the beginning of the 1900s, apartment buildings in American cities were getting taller, and becoming more separate, with individual kitchens. By the 1920s, despite continued criticism from those who felt the crowded quarters stifled normal family relations, many cities had more apartments being built than single-family homes. They had became more middle-class by that point; a 1928 Chicago women's organization passed a resolution that "parents living in kitchenette apartments, presumably for economic reasons, but in reality because of the inconvenience of home-making in a cottage home or bungalow...be urged to become home owners for the sake of the younger generation." Ladies' Home Journal said apartments were a Bolshevik influence. However, despite the portrayal of a house as the real location of the American Dream, the apartment building was here to stay.

Sources:
Wright, Gwendolyn. Building the Dream: A Social History of Housing In America. New York, Pantheon Books, 1981.
http://www.historyforkids.org/learn/architecture/houses.htm