Context : Aims : A novel method of using hard X-rays as a diagnostic for chromospheric density and magnetic structures is developed to infer sub-arcsecond vertical variation of magnetic flux tube size and neutral gas density . Methods : Using Reuven Ramaty High Energy Solar Spectroscopic Imager ( RHESSI ) X-ray data and the newly developed X-ray visibilities forward fitting technique we find the FWHM and centroid positions of hard X-ray sources with sub-arcsecond resolution ( \sim 0.2 ^ { \prime \prime } ) for a solar limb flare . We show that the height variations of the chromospheric density and the magnetic flux densities can be found with unprecedented vertical resolution of \sim 150 km by mapping 18-250 keV X-ray emission of energetic electrons propagating in the loop at chromospheric heights of 400-1500 km . Results : Our observations suggest that the density of the neutral gas is in good agreement with hydrostatic models with a scale height of around 140 \pm 30 km . FWHM sizes of the X-ray sources decrease with energy suggesting the expansion ( fanning out ) of magnetic flux tube in the chromosphere with height . The magnetic scale height B ( z ) \left ( dB / dz \right ) ^ { -1 } is found to be of the order of 300 km and strong horizontal magnetic field is associated with noticeable flux tube expansion at a height of \sim 900 km . Conclusions :