X-rays are ionizing radiation, so they introduce a small risk of harm such as cancer. The risk is negligible at the individual level, especially compared with the benefit of imaging when you're sick. Ultrasound is a form of sound, so it's not ionizing radiation. High intensities of ultrasound can be used to intentionally break up tissue (therapeutic ultrasound), but this doesn't occur with the intensities used in imaging.
X-rays give contrast based on the density and atomic number of the material, so they show bones clearly. They don't work well at showing the structure of soft tissues. To an x-ray, all soft tissue tends to look like an equivalent mass of water, which is just a weak absorber.
Ultrasound gives contrast based on changes in acoustic impedance, which is a different property of matter. Different types of soft tissue that would have almost the same x-ray absorption can have different enough impedances that they can be distinguished. Ultrasound is easily reflected and refracted by body structures, not just absorbed, so the images can look more distorted and messy.
Ultrasound has a resolution that's limited by its wavelength. It will diffract around structures comparable in size to the wavelength. X-rays are limited in resolution by other factors such as the finite width of the beam emitted by the x-ray tube. X-rays either get absorbed or travel straight.