A melody (from Greek μελῳδία, melōidía, "singing, chanting"),  also tune, voice or line, is a linear succession of musical tones that the listener perceives as a single entity. In its most literal sense, a melody is a combination of pitch and rhythm, while more figuratively, the term can include other musical elements such as tonal color. It is the foreground to the background accompaniment. A line or part need not be a foreground melody.
Melodies often consist of one or more musical phrases or motifs, and are usually repeated throughout a composition in various forms. Melodies may also be described by their melodic motion or the pitches or the intervals between pitches (predominantly conjunct or disjunct or with further restrictions), pitch range, tension and release, continuity and coherence, cadence, and shape.
Johann Philipp Kirnberger argued:
The true goal of music—its proper enterprise—is melody. All the parts of harmony have as their ultimate purpose only beautiful melody. Therefore, the question of which is the more significant, melody or harmony, is futile. Beyond doubt, the means is subordinate to the end.
The Norwegian composer Marcus Paus has argued:
Melody is to music what a scent is to the senses: it jogs our memory. It gives face to form, and identity and character to the process and proceedings. It is not only a musical subject, but a manifestation of the musically subjective. It carries and radiates personality with as much clarity and poignancy as harmony and rhythm combined. As such a powerful tool of communication, melody serves not only as protagonist in its own drama, but as messenger from the author to the audience.
Given the many and varied elements and styles of melody "many extant explanations [of melody] confine us to specific stylistic models, and they are too exclusive."  Paul Narveson claimed in 1984 that more than three-quarters of melodic topics had not been explored thoroughly. 
The melodies existing in most European music written before the 20th century, and popular music throughout the 20th century, featured "fixed and easily discernible frequency patterns", recurring "events, often periodic, at all structural levels" and "recurrence of durations and patterns of durations". 
Melodies in the 20th century "utilized a greater variety of pitch resources than ha[d] been the custom in any other historical period of Western music." While the diatonic scale was still used, the chromatic scale became "widely employed."  Composers also allotted a structural role to "the qualitative dimensions" that previously had been "almost exclusively reserved for pitch and rhythm". Kliewer states, "The essential elements of any melody are duration, pitch, and quality ( timbre), texture, and loudness.  Though the same melody may be recognizable when played with a wide variety of timbres and dynamics, the latter may still be an "element of linear ordering." 
Different musical styles use melody in different ways. For example:
- Jazz musicians use the term "lead" or "head" to refer to the main melody, which is used as a starting point for improvisation.
- Rock music, and other forms of popular music and folk music tend to pick one or two melodies ( verse and chorus, sometimes with a third, contrasting melody known as a bridge or middle eight) and stick with them; much variety may occur in the phrasing and lyrics.
- Indian classical music relies heavily on melody and rhythm, and not so much on harmony, as the music contains no chord changes.
- Balinese gamelan music often uses complicated variations and alterations of a single melody played simultaneously, called heterophony.
- In western classical music, composers often introduce an initial melody, or theme, and then create variations. Classical music often has several melodic layers, called polyphony, such as those in a fugue, a type of counterpoint. Often, melodies are constructed from motifs or short melodic fragments, such as the opening of Beethoven's Fifth Symphony. Richard Wagner popularized the concept of a leitmotif: a motif or melody associated with a certain idea, person or place.
- While in both most popular music and classical music of the common practice period pitch and duration are of primary importance in melodies, the contemporary music of the 20th and 21st centuries pitch and duration have lessened in importance and quality has gained importance, often primary. Examples include musique concrète, klangfarbenmelodie, Elliott Carter's Eight Etudes and a Fantasy (which contains a movement with only one note), the third movement of Ruth Crawford-Seeger's String Quartet 1931 (later re-orchestrated as Andante for string orchestra), which creates the melody from an unchanging set of pitches through "dissonant dynamics" alone, and György Ligeti's Aventures, in which recurring phonetics create the linear form.
- Parsons code, a simple notation used to identify a piece of music through melodic motion—the motion of the pitch up and down.
- Sequence (music)
- Unified field
- μελῳδία. Liddell, Henry George; Scott, Robert; A Greek–English Lexicon at the Perseus Project.
- Forte, Allen (1979). Tonal Harmony in Concept & Practice, p. 203. ISBN 0-03-020756-8.
- Paus, Marcus (6 November 2017). "Why melody matters". Gramophone.
- Kliewer, Vernon (1975). "Melody: Linear Aspects of Twentieth-Century Music", Aspects of Twentieth-Century Music, pp. 270–301. Wittlich, Gary (ed.). Englewood Cliffs, New Jersey: Prentice-Hall. ISBN 0-13-049346-5.
- Narveson, Paul (1984). Theory of Melody. ISBN 0-8191-3834-7.
- Marquis, G. Weston (1964). Twentieth Century Music Idioms, p. 2. Prentice-Hall, Inc., Inglewood Cliffs, New Jersey.
- Apel, Willi. Harvard Dictionary of Music, 2nd ed., pp. 517–19.
- Cole, Simon (2020). just BE here – the guide to musicking mindfulness
- Edwards, Arthur C. The Art of Melody, pp. xix–xxx.
- Holst, Imogen(1962/2008). Tune, Faber and Faber, London. ISBN 0-571-24198-0.
- Smits van Waesberghe, Joseph (1955). A Textbook of Melody: A course in functional melodic analysis, American Institute of Musicology.
- Szabolcsi, Bence (1965). A History of Melody, Barrie and Rockliff, London.
- Trippett, David (2013). Wagner's Melodies. Cambridge University Press.
- Trippett, David (2019). "Melody" in The Oxford Handbook to Critical Concepts in Music Theory. Oxford University Press.