The name came into use in the 1680s in England when there was the threat of establishment of a line of Catholic Kings, starting with James II. The Protestant element, who held that Parliament could prevent such a succession, came to be called Whigs after a radical Presbyterian group in Scotland, the Whigamores, while the party tending to the doctrine of the rights of King James II (and naturally containing Catholic as well as simply royalist elements), were called Tories after some bands of Irish Catholics who had been driven to become outlaws due to the crusade of the English against the church they clung to.
The designation of British loyalists during the American Revolution - as Tories - is well known. And many on the revolutionary side must have identified with the English Whigs, which continued to be the party in favor of Parliament's keeping the king in check.
During Andrew Jackson's presidency the first really well organized political parties came into existence. The Democratic Party, with Jackson himself as the rallying point, brought about radical changes, including a presidency that for the first time threatened to overshadow Congress.
Jackson changed the perception of the presidential veto. It had been interpreted as something the president could do if he considered a bill unconstitutional, though the Constitution doesn't really state it that way. Jackson eventually laid down the precedent that the president could veto a bill on basically any grounds.
Jackson also took a free hand in changing the membership of his cabinet in a way that no other President had done. He had his first cabinet resign en masse, which to many at the time looked like the "fall of the government", but he treated it as something a President had the right to do.
All of this lead the opposition, to speak of King Andrew I, and to picture Jackson that way in political cartoons.
Henry Clay and others had called themselves National Republicans - based on their vision of the United States as nation while others saw it as a confederation of states - taking strong national measures like building inter-state roads. When a number of southern Democrats like John C. Calhoun, threw their lot in with the National Republicans, they were united only by their opposition to the growing "kinglike" strength of the president. Thus they came to be called Whigs, implying that the Jacksonians were Tories, in favor of "King" Andrew.
The Whig party ran, for some years, mostly in strong second place to the Democrats. They elected William Henry Harrison, in the famous "Tippecanoe and Tyler Too" campaign of nonsense, copied from the Jackson Democrats, but Harrison (the hero of Tippecanoe) died just days into his presidency, and was succeded by Tyler, one of the anti-Jackson democrats, who showed himself to be basically a firm Democrat, and was "read out of the Whig party". They also elected Zachary Taylor (another war hero and no politician) who was died fairly early in the term, making Millard Filmore president.
After the Jackson era, the Whig party drifted towards its strongest elements, the national improvements men. That tendency was strongest by far in the North; the South being in those days almost purely agrarian.
In the 1850s when the nation became increasingly divided over slavery, a new Republican party formed, primarily to keep slavery quarantined off in the South, while Southern sentiment was for their right to move, with their way of life, into any new territory. Their methods of agriculture and their best cash crops tended to deplete the soil, so that Southerners were among the most aggressive Western expansionists.
The Republican Party, while it also attracted many anti-slavery Democrats, drew off so many Whigs that they effectively killed the Whig party. The Whigs were also badly hurt by the short-lived Native American or Know-Nothing party, which was primarily anti-immigrant and anti-Catholic. This party was strong in urban areas, which had also been a Whig stronghold. The last year the Whigs had a presidential candidate was in 1856.