"small, hanging piece from a garment," c. 1400, of uncertain origin but probably from a Scandinavian source (compare Norwegian tagg "point, prong, barb," Swedish tagg "prickle, thorn") and related to Middle Low German tagge "branch, twig, spike"), from Proto-Germanic *tag-. The sense development might be "point of metal at the end of a cord, string, etc.," hence "part hanging loose." Or perhaps ultimately from PIE *dek-, a root forming words referring to fringe, horsetail, locks of hair" (see with tail (n.1)).
Meaning "a label" is first recorded 1835; sense of "automobile licence-plate" is recorded from 1935, originally underworld slang. Meaning "an epithet, popular designation" is recorded from 1961, hence slang verb meaning "write graffiti in public places" (1990).