stylistic:tone, structural:reformatting
Sources

Hamlet -like legends are so widely found (for example in Italy, Spain, Scandinavia, Byzantium, and Arabia) that the core "hero-as-fool" theme is possibly Indo-European in origin. Several ancient written precursors to Hamlet can be identified. The first is the anonymous Scandinavian Saga of Hrolf Kraki. In this, the murdered king has two sons— Hroar and Helgi —who spend most of the story in disguise, under false names, rather than feigning madness, in a sequence of events that differs from Shakespeare's. The second is the Roman legend of Brutus, recorded in two separate Latin works. Its hero, Lucius ("shining, light"), changes his name and persona to Brutus ("dull, stupid"), playing the role of a fool to avoid the fate of his father and brothers, and eventually slaying his family's killer, King Tarquinius. A 17th-century Nordic scholar, Torfaeus, compared the Icelandic hero Amlóði (Amlodi) and the hero Prince Ambales (from the Ambales Saga) to Shakespeare's Hamlet. Similarities include the prince's feigned madness, his accidental killing of the king's counsellor in his mother's bedroom, and the eventual slaying of his uncle.

Many of the earlier legendary elements are interwoven in the 13th-century "Life of Amleth" (Latin: Vita Amlethi) by Saxo Grammaticus, part of Gesta Danorum. Written in Latin, it reflects classical Roman concepts of virtue and heroism, and was widely available in Shakespeare's day. Significant parallels include the prince feigning madness, his mother's hasty marriage to the usurper, the prince killing a hidden spy, and the prince substituting the execution of two retainers for his own. A reasonably faithful version of Saxo's story was translated into French in 1570 by François de Belleforest, in his Histoires tragiques. Belleforest embellished Saxo's text substantially, almost doubling its length, and introduced the hero's melancholy.

According to one theory, Shakespeare's main source may be an earlier play—now lost—known today as the Ur-Hamlet. Possibly written by Thomas Kyd or by Shakespeare, the Ur-Hamlet would have existed by 1589, and would have incorporated a ghost. Shakespeare's company, the Chamberlain's Men, may have purchased that play and performed a version for some time, which Shakespeare reworked. However, no copy of the Ur-Hamlet has survived, and it is impossible to compare its language and style with the known works of any of its putative authors. In 1936 Andrew Cairncross suggested that, until more becomes known, it may be assumed that Shakespeare wrote the Ur-Hamlet. Eric Sams lists reasons for supporting Shakespeare’s authorship. Harold Jenkins considers that there are no grounds for thinking that the Ur-Hamlet is an early work by Shakespeare, which he then rewrote. Professor Terri Bourus in 2016, one of three general editors of the New Oxford Shakespeare, in her paper "Enter Shakespeare's Young Hamlet, 1589" suggests that Shakespeare was "interested in sixteenth-century French literature, from the very beginning of his career" and therefore "did not need Thomas Kyd to pre-digest Belleforest's histoire of Amleth and spoon-feed it to him". She considers that the hypothesized Ur-Hamlet is Shakespeare's Q1 text, and that this derived directly from Belleforest's French version.

The precise combination of Shakespeare's use of the Ur-Hamlet, Belleforest, Saxo, or Kyd's The Spanish Tragedy as sources for Hamlet is not known. However, elements of Belleforest's version which are not in Saxo's story do appear in Shakespeare's play.

Most scholars reject the idea that Hamlet is in any way connected with Shakespeare's only son, Hamnet Shakespeare, who died in 1596 at age eleven. Conventional wisdom holds that Hamlet is too obviously connected to legend, and the name Hamnet was quite popular at the time. However, Stephen Greenblatt has argued that the coincidence of the names and Shakespeare's grief for the loss of his son may lie at the heart of the tragedy. He notes that the name of Hamnet Sadler, the Stratford neighbour after whom Hamnet was named, was often written as Hamlet Sadler and that, in the loose orthography of the time, the names were virtually interchangeable.

Scholars have often speculated that Hamlet ' s Polonius might have been inspired by William Cecil (Lord Burghley)—Lord High Treasurer and chief counsellor to Queen Elizabeth I. E. K. Chambers suggested Polonius's advice to Laertes may have echoed Burghley's to his son Robert Cecil. John Dover Wilson thought it almost certain that the figure of Polonius caricatured Burghley. A. L. Rowse speculated that Polonius's tedious verbosity might have resembled Burghley's. Lilian Winstanley thought the name Corambis (in the First Quarto) did suggest Cecil and Burghley. Harold Jenkins considers the idea of Polonius as a caricature of Burghley to be conjecture, perhaps based on the similar role they each played at court, and perhaps also based on the similarity between Burghley addressing his Ten Precepts to his son, and Polonius offering "precepts" to his son, Laertes. Jenkins suggests that any personal satire may be found in the name "Polonius", which might point to a Polish or Polonian connection. G. R. Hibbard hypothesised that differences in names (Corambis/Polonius:Montano/Raynoldo) between the First Quarto and other editions might reflect a desire not to offend scholars at Oxford University. (Robert Pullen, was the founder of Oxford University, and John Rainolds, was the President of Corpus Christi College.)