In its most generic form the term “HMS” stands for “Her (or His) Majesty’s Ship“. This abbreviation has been part of any sea-going vessel’s name belonging to the British Royal Navy since 1789. HMS Phoenix was the first ship to bear the name and the tradition continues to this day.
Officially the “H” in “HMS” stands for either “Her” or “His”, depending on who’s the ruling monarch of Great Britain and its many colonies at the time. However, since Her Majesty Queen Elizabeth the Second has been ruining the upholstery of the royal throne for the last 63 years and also because in English language a ship is normally referred to as “she”, “HMS” pretty much stands for “Her Majesty Ship” these days. And since Granny Liz is also technically the ruling queen of many colonies, the Navy ships of Canada and Australia bear the designations of HMCS and HMAS respectively.
Other countries adopted similar naming conventions, most notably the Swedish Royal Navy ships were bearing “HMS” designation as well (Hans Majestäts Skepp), later changed to “HSwMS” to avoid confusion with “HMS”. The United States has adopted a similar prefix “USS”, but not until 1907. Many other countries never bothered.
Of course the Brits being what they are, there are always exceptions to the rule. You see, the same Queen used to have a wee yacht. Built in Scotland in 1953, this little tub is only 126 meters long (412 ft) and she can only hold about 300 crew and up to 250 passengers. Plus a platoon of Royal Marines, just in case some pirates from the colonies get uppity. Her official name is “HMY Brittania”, as in “Her Majesty’s Yacht” and officially she never had any Navy sailors on board, only “yachtsmen”. She is a museum now, permanently moored to the pier in Edinburgh Scotland, sharing the fate with USS Hornet, US Navy aircraft carrier permanently stationed at the harbor in Alameda, California