According to my knowledge, when clouds get charged, they produce sparks, which look like lightning to us. My question is, why does lightning have a color? It consists of electrons, and should not radiate light. If it radiates light after hitting air particles, then it should radiate only X-rays. Is that correct?
TL;DR: Air in lightning gets hot. Hot things (like the Sun) emit light in a broad spectrum; including visible. You are right there will be emissions outside the visible - but your eye doesn't pick that up. So the flash looks blue-ish white to the human eye.
More complete answer:
The light you see is the result of the air getting very, very hot.
And just like the sun, which is very hot, is white - so is lightning.
Electrons can emit radiation in a wide range of energies, depending on the rate of deceleration. When they hit a tungsten target in an X-ray tube, they decelerate very suddenly from a very high starting point - thus Xrays. If they start with "high thermal" energies, and decelerate by hitting (lower Z, lower density) air molecules, their spectrum will be more like a black body spectrum. A hot black body - white. But there is some X-ray component in lightning as well - you just can't see it, and most of it is absorbed in the air before it reaches you.
Also - remember that if an object is very bright, with just a small fraction of its emission in the visible spectrum, it will still "look" white (or blue-ish). As an illustration, here is a calculation of the spectrum for sunlight (5700 K) and lightning (very approximately 30,000 K - obviously the temperature changes during the strike, and from one strike to another; but most of the light is generated while it is hottest, with the usual $T^4$ relationship of the Stefan-Boltzmann Law dominating). I scaled the plot for lightning to a max of 1.0 for comparison of shape, and then scaled it so you can compare its shape against the shape of sunlight. In fact, the intensity at 30,000 K is MUCH brighter than sunlight - if I used the same scale factor for all curves you would not see much...
You can see that lightning (assuming a temperature of 30,000 K) gives off mostly "light" in the UV - but there is a component in the visible, which will be bluish - but which our eyes perceive as white.
Putting the curves on the same log scale, you can see that the intensity is greater at the higher temperature for all wavelengths:
Further reading: http://phys.org/news/2008-07-scientists-source-x-rays-lightning.html
Quoting from that article:
"Nobody understands how lightning makes X-rays," said Martin Uman, a professor of electrical and computer engineering. "Despite reaching temperatures five times hotter than the surface of the sun, the temperature of lightning is still thousands of times too cold to account for the X-rays observed."
Two final thoughts:
- At the pressure and temperature inside the lightning bolt (instantaneous heating to 30,000 K should raise the pressure locally to 100 bar), you will get significant spectral broadening - that is, Doppler broadening (atoms moving towards or away from the observer with equal probability, at velocity around 5000 m/s), and collision broadening (short time between collisions "resets" the natural oscillations - at high temperature and pressure, the characteristic time between collisions can become short enough to matter). These things play inside the high intensity discharge lamps used in demanding lighting applications (spectrum from http://www.lamptech.co.uk/Images/Illustrations/SO%20SPD's.jpg):
Such spectral broadening will help "whiten" the light some more.
- The question of X rays was brought up in the quote above. It is quite possible that some of the high energy electrons (which after all accelerate in a field of thousands of V/m) travel considerable distance (and therefore obtain significant energy) before hitting an air molecule - their sudden deceleration can then give rise to higher energy emissions, including X rays. The presence of such accelerated electrons is not well described by the black body radiation model, and it should therefore come as no surprise that there are things "beyond the predicted spectrum".
The high voltage of the lightning arc separates electrons and ions, briefly forming a plasma. When the electrons and ions recombine back into a gas, the formerly free electrons drop to a lower energy state in orbit around their ions, and the energy difference is emitted as light. This is the bright flash that you see. Also, the newly recombined gas will be very hot, so it will glow briefly. The volume of hot gas is fairly small, so it can cool quickly and stop glowing.