What Is Salat al-Kusuf (Solar Eclipse Prayer)?
Question

What is the ruling on salat al-kusuf (solar eclipse prayer)?  How should we offer it? What should be recited during this prayer?
Praise be to Allah.Sun and Moon are two signs from Allah
Allah says (interpretation of the meaning):
“It is He Who made the sun a shining thing and the moon as a light and measured out for it stages that you might know the number of years and the reckoning. Allah did not create this but in truth. He explains the signs in detail for people who have knowledge.” [Yunus 10:5]
“And from among His Signs are the night and the day, and the sun and the moon. Prostrate yourselves not to the sun nor to the moon, but prostrate yourselves to Allah Who created them, if you (really) worship Him.” (Fussilat 41:37)
Is Salat al-Kusuf sunnah?
Salat al-Kusuf is a confirmed Sunnah according to the consensus of the scholars. The evidence for this is the Sunnah reported from the Messenger of Allah (peace and blessings of Allah be upon him)
Eclipses are signs from Allah
Eclipses are signs from Allah by means of which Allah makes His slaves afraid . Allah says (interpretation of the meaning): “And We sent not the signs except to warn, and to make them afraid (of destruction)” [al-Isra 17:39]
How was Salat al-kusuf legislated?
When the sun was eclipsed at the time of the Messenger of Allah (peace and blessings of Allah be upon him), he went out rushing nervously to the mosque, dragging his cloak behind him, and led the people in prayer. He told them that the eclipse was one of the signs of Allah, with which Allah makes His slaves afraid, and that it may be the cause of punishment coming upon the people. He commanded them to do that which could prevent the punishment, so he commanded them to pray when an eclipse happens, and to make du`a, seek His forgiveness, give charity, free slaves and do other righteous deeds so that the punishment would go away and not befall the people. So the eclipse is a reminder to people, making them afraid so that they will turn back to Allah and pay attention to Him.
Divine wisdom behind the occurrence of eclipses
During the Jahiliyyah, people used to believe that eclipses happened to mark the birth or death of a great person, but the Messenger of Allah (peace and blessings of Allah be upon him) declared this belief to be false and explained the divine wisdom behind the occurrence of eclipses:
Imam al-Bukhari and Muslim narrated that Ibn Mas’ud al-Ansari said: the sun was eclipsed the day Ibrahim, the son of the Messenger of Allah (peace and blessings of Allah be upon him) died, and the people said, The sun is eclipsed because of the death of Ibrahim. The Messenger of Allah (peace and blessings of Allah be upon him) said: The sun and the moon are two signs from Allah, and they do not become eclipsed for the death or the birth of anyone. If you see that, hasten to remember Allah and to pray.
According to another hadith in al-Sahihayn, “Call on Allah and pray until [the eclipse] is over.”
It is reported in Sahih al-Bukhari that Abu Musa said: These signs that Allah sends are not for the death or life of anyone, but Allah makes His slaves afraid through them, so if you see anything of that [eclipses], then hasten to remember Allah and call on Him and seek His forgiveness.
Allah causes eclipses to happen to these two mighty signs, the sun and the moon, to teach His slaves and show them that these things are created and are subject to imperfections and changes just like any other created entities. Thus He shows them His perfect ability and that He Alone is deserving of worship, as Allah says (interpretation of the meaning): “And from among His Signs are the night and the day, and the sun and the moon. Prostrate yourselves not to the sun nor to the moon, but prostrate yourselves to Allah Who created them, if you (really) worship Him.” (Fussilat 41:37)
The time for Salat al-Kusuf
The time for Salat al-Kusuf lasts from the beginning of the eclipse until it is over, because the Prophet (peace and blessings of Allah be upon him) said: When you see that, then pray. (Agreed upon) According to another hadith, “If you see anything of that, then pray until it is over.” (Reported by Muslim)
Salat al-Kusuf should not be done once the eclipse is over, because the time has gone. If an eclipse ends before one knows about it, one does not have to pray, because the reason for this prayer is no longer there.
How to perform Salat al-Kusuf
The way in which  Salat al-Kusuf is done is to pray two Rak’ahs in which Quran is recited aloud, according to the correct one out of the two scholarly opinions. 
In the first Rak’ah, one should recite al-Fatihah and a long surah such as Surat al-Baqarah or the equivalent, then do a long ruku’, then raise one's head and say, Sami’a Allahu liman hamidah, Rabbana wa lakal-hamd (Allah listens to the one who praises Him; our Lord to You be praise) after standing upright, as in other prayers. 
Then one should then recite al-Fatihah and another long surah, shorter than in the first recitation, equivalent in length to Surat Al ‘Imran. Then one should do another long ruku’ shorter than the first, and when raising one's head, say, Sami’a Allahu liman hamidah, Rabbana wa lakal-hamd hamdan kathiran tayyiban mubarakan fih, mil al-samawati wa mil al-ard wa mil ma shita min shayin ba’d (Allah listens to the one who praises Him; our Lord to You be praise, much good and blessed praise, filling heaven and earth and whatever You will besides that). 
Then he should do two lengthy sujuds, without making the sitting between them too long. Then one should pray the second rak’ah like the first, with two long ruku’s and two long sujuds, as he did in the first rak’ah. Then he should recite the Tashahhud and say the salam.
This is the description of Salat al-Kusuf as prayed by the Messenger of Allah (peace and blessings of Allah be upon him), as was reported with a number of isnads. Some of these reports are in al-Sahihayn, including the hadith narrated by ‘Aishah (may Allah be pleased with her): The sun was eclipsed at the time of the Messenger of Allah (peace and blessings of Allah be upon him), and the Messenger of Allah (peace and blessings of Allah be upon him) went out, stood up and said Takbir (Allahu akbar), and the people formed rows behind him. The Messenger of Allah (peace and blessings of Allah be upon him) recited a lengthy recitation and did a lengthy ruku’, then he raised his head and said, Sami’a Allahu liman hamidah, Rabbana wa lakal-hamd. Then he stood upright and recited another lengthy recitation, shorter than the first. Then he said Allahu akbar and did another lengthy ruku’, shorter than the first. Then he said, Sami’a Allahu liman hamidah, Rabbana wa lakal-hamd. Then he did sujud. Then in the second rak’ah he did likewise, until he had completed four ruku’s and four sujuds, and the eclipse was over before he had finished. (Agreed upon)
Can you pray salat al-kusuf in congregation?
It is sunnah to pray Salat al-Kusuf in congregation, because this is what the Prophet (peace and blessings of Allah be upon him) did, but it is permissible to pray it individually, as with all other nafl prayers. However, praying it in congregation is better.
Should the imam give khutbah after salat al-kusuf?
It is sunnah for the imam to address the people after the prayer, and to warn them against negligence and being led astray, and to tell them to make lots of du’a and ask for forgiveness. In al-Sahih it is narrated from ‘Aishah (may Allah be pleased with her) that the Prophet (peace and blessings of Allah be upon him) finished his prayer then addressed the people and started by praising Allah then he said, The sun and the moon are two of the signs of Allah, and they do not become eclipsed for the death or the birth of anyone. If you see that, then call on Allah, perform salah, give charity
Should you repeat salat al-kusuf if the eclipse does not end?
If the prayer ends before the eclipse does, then remember Allah (dhikr) and call on Him (du’a) until the eclipse ends. The prayer should not be repeated. If the eclipse ends before the prayer, then the prayer should be completed quickly, but it should not be stopped or cut off abruptly, because Allah says (interpretation of the meaning): “and render not vain your deeds [Muhammad 47:33]. The prayer should be at the time of the eclipse, because the Prophet (peace and blessings of Allah be upon him) said: “until it (the eclipse) is over and he also said, until what you are going through is over.”
Shaykh al-Islam Ibn Taymiyah said: 
“Sometimes eclipses last for a long time, and sometimes for a short time, depending on how much of the sun or moon is eclipsed. The entire sun or moon may be eclipsed, or only half of it, or one-third. If it is a total eclipse, then the prayer should last long enough for all of al-Baqarah or something of similar length to be recited in the first rak’ah, and in the next rak’ah a shorter recitation is made. There are authentic hadiths narrated from the Prophet (peace and blessings of Allah be upon him), as we have mentioned, and it is prescribed to shorten the prayer if the reason for it [i.e., the eclipse] is no longer there. So if it is known that the eclipse will not last for long, or if it started to get less, one should still pray, but the prayer should be shortened. This is the opinion of the majority of scholars, because this prayer is prescribed for a specific reason, and if the reason is no longer there and the eclipse is over, one should not pray.” 
For more, please see these answers: 65719 , 20368 , 9954 , and 6124 .
And Allah knows best.