In English, ⟨gh⟩ historically represented [x] (the voiceless velar fricative, as in the Scottish Gaelic word loch), and still does in lough and certain other Hiberno-English words, especially proper nouns. In the dominant dialects of modern English, ⟨gh⟩ is almost always either silent or pronounced /f/ (see Ough). It is thought that before disappearing, the sound became partially or completely voiced to [ɣx] or [ɣ], which would explain the new spelling — Old English used a simple ⟨h⟩ — and the diphthongization of any preceding vowel.
It is also occasionally pronounced [ə], such as in Edinburgh as well as [θ] in Keighley.
When gh occurs at the beginning of a word in English, it is pronounced /ɡ/ as in "ghost", "ghastly", "ghoul", "ghetto", "ghee" etc. In this context, it does not derive from a former /x/.
American Literary Braille has a dedicated cell pattern for the digraph ⟨gh⟩ (dots 126, ⠣).
Middle Dutch
In Middle Dutch, ⟨gh⟩ was often used to represent /ɣ/ (the voiced velar fricative) before ⟨e⟩, ⟨i⟩, and ⟨y⟩. This usage survives in place names such as Ghent.
The spelling of English word ghost with a ⟨gh⟩ (from Middle Englishgost) was likely influenced by the Middle Dutch spelling gheest (Modern Dutchgeest).
The Maltese language has a related digraph, ⟨għ⟩. It is considered a single letter, called għajn (the same word for eye and spring, named for the corresponding Arabic letter ʿayn). It is usually silent, but it is necessary to be included because it changes the pronunciation of neighbouring letters, usually lengthening the succeeding vowels. At the end of a word, when not substituted by an apostrophe, it is pronounced [ħ]. Its function is thus not unlike modern English gh, except that the English version comes after vowels rather than before like Maltese għ (għajn would come out something like ighn if spelled as in English).
The Ukrainian National transliteration system uses ⟨gh⟩ to avoid occurrence of another digraph, usually ⟨zh⟩ which is used for another type of phoneme. Such as the word "pack" (a group of animals) in Ukrainian would be Romanized as zghraia (Ukrainian: зграя) rather than zhraia, which could be misconstrued to intend *жрая. The Ukrainian transliteration standard DSTU 9112:2021 (based on ISO 9:1995) uses ⟨gh⟩ to represent common Ukrainian letter г (the voiced glottal fricative/ɦ/).