Mughal rule in Himachal Pradesh
Prior to the arrival of the Mughals in the Indian subcontinent, the first instance of Islamic conquest of the region was during the 10th century when Mahmud Ghaznavi conquered Kangra. After the entry of the Mughals into the subcontinent, the region fell to Mughal authority as well. Later, due to internal conflicts within the Mughal dynasty the rulers of the hill provinces took complete advantage. Kangra regained its independence under Maharaja Sansar Chand who ruled for nearly 50 years. He was one of the most powerful administrators of the region. After he took the formal possession of Kangra fort, Maharaja Sansar Chand began to expand his territory. The states of Chamba, Suket, Mandi,  and , Guler, Jaswan, Siba and Datarpur came under the direct control of Maharaja Sansar Chand. Anglo-Gorkha war 
The Gorkhas (martial tribe) came to power in Nepal in 1768. The gorkhas consolidated their military power and expanded their territory. Over a period of time the Gorkhas annexed Sirmour and Shimla hill states. Under the leadership of Amar Singh Thapa, Gorkhas laid their siege to Kangra. They defeated Maharaja Sansar Chand who was the ruler of Kangra, in 1806 with the help of hill chiefs. However, Gorkhas were not able to capture Kangra fort which came under the direct control of Maharaja Ranjeet Singh in 1809. After the defeat the Gorkhas began to expand towards the southern provinces. This led to the Anglo-Gorkha war. They came into direct conflict with the British along the tarai belt after which the British expelled them. The British slowly emerged as the paramount powers in this conflict. Anglo-Sikh war 
After the Anglo-Gorkha war the common border shared by the British domain and Punjab became extremely sensitive. Both the Sikhs and British wanted to avoid a direct conflict, but after the death of Ranjit Singh, the Khalsa army fought numerous wars with the British. In 1845 when the Sikhs invaded the British territory by crossing the Satluj river, the rulers of many hill provinces sided with the British. Many of these hill state rulers entered into the secret communication with the British. After the first Anglo-sikh war, the British did not restore the hill territory, departed by the Sikhs, to the original owners. References

History of Himachal Pradesh
Mughal Empire