Short answer
In the Hanafi school, yes: playing musical instruments such as the piano, guitar, violin or drums for entertainment is haram, and so is learning them for that purpose. The duff (frame drum) at weddings and Eid is the exception. A minority of scholars allow instruments with clean content, so treat those who follow that view with respect.
Playing, learning and teaching musical instruments (ma'azif) for music is haram. The duff without jingles is permitted at a nikah and on similar occasions of joy.
The four schools agree on this.
Explanation
Playing an instrument is a more direct involvement in music than listening to it. The Hanafi position on instruments rests on the hadith in Sahih al-Bukhari in which the Prophet ﷺ foretold people of his ummah who would treat as lawful illicit sex, silk, wine and musical instruments. Instruments are listed with things that are clearly haram. The full reasoning is in why music is haram.
What this covers:
- Piano, keyboard, guitar, violin, flute, drums and digital instruments in music apps.
- Music lessons, school band and grade exams taken for the sake of music.
- Composing or producing instrumental music.
What it does not cover:
- The duff, a simple frame drum, at weddings and Eid.
- Nasheeds and singing with the voice alone, within the limits in is singing haram.
- Sounds that are not music, such as a doorbell, an alarm or a timer beep.
If you are a student in a required music class, explain your situation to the teacher. Many schools offer an alternative such as music theory, voice or percussion with the duff, or a written task. If you have already learned an instrument, you are not sinful for skills you hold. Leave playing it, and use the discipline you learned in better things.
A minority of scholars, past and present, allow instruments when the words and setting are clean, arguing that the Bukhari hadith has a break in its chain or refers to music joined with drinking and immorality. Most hadith experts answered that the hadith is authentic and that instruments are named on their own. The four schools agree in principle that instruments are forbidden. AmalKit follows the Hanafi position, while respecting Muslims who follow the other view.
The evidence
Quran, Surah Luqman 31:6
وَمِنَ ٱلنَّاسِ مَن يَشْتَرِى لَهْوَ ٱلْحَدِيثِ لِيُضِلَّ عَن سَبِيلِ ٱللَّهِ بِغَيْرِ عِلْمٍۢ وَيَتَّخِذَهَا هُزُوًا ۚ أُو۟لَٰٓئِكَ لَهُمْ عَذَابٌۭ مُّهِينٌۭ ﴿٦﴾
And of the people is he who buys the amusement of speech to mislead [others] from the way of Allah without knowledge and who takes it in ridicule. Those will have a humiliating punishment.
Early scholars explained 'amusement of speech' as singing and music that pull people from Allah's way.
Sahih al-Bukhari 5590
Sahih... يستحلون الحر والحرير والخمر والمعازف ...
"People of my ummah will treat as lawful illicit sex, silk, wine and musical instruments."
Instruments are counted among things that are prohibited.
Where the ruling is recorded
- al-Hidaya, Kitab al-Karahiyya. Instruments of play are counted among forbidden things.
- Radd al-Muhtar (Ibn Abidin), Kitab al-Hazr wa al-Ibaha. Playing and listening to instruments on purpose is sinful.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.