  We modelled recent observations of UV absorption of HD and \HH\ in the Milky
Way and toward damped/sub-damped Lyman alpha systems at z=0.18 and z $>$ 1.7.
N(HD)/N(\HH) ratios reflect the separate self-shieldings of HD and \HH\ and the
coupling introduced by deuteration chemistry. Locally, observations are
explained by diffuse molecular gas with $ 16 \pccc \la$ n(H) $\la 128 \pccc $
if the cosmic-ray ionization rate per H-nucleus \zetaH $= 2\times 10^{-16}\ps$
as inferred from \H3\p\ and OH\p. The dominant influence on N(HD)/N(\HH) is the
cosmic-ray ionization rate with a much weaker downward dependence on n(H) at
Solar metallicity, but dust-extinction can drive N(HD) higher as with N(\HH).
At z $>$ 1.7, N(HD) is comparable to the Galaxy but with 10x smaller N(\HH) and
somewhat smaller N(\HH)/N(H I). Comparison of our Galaxy and the Magellanic
Clouds shows that smaller \HH/H is expected at sub-Solar metallicity and we
show by modelling that HD/\HH\ increases with density at low metallicity,
opposite to the Milky Way. Observations of HD would be explained with higher
n(H) at low metallicity but high-z systems have high HD/\HH\ at metallicity
0.04 $\la$ Z $\la$ 2 Solar. In parallel we trace dust-extinction and
self-shielding effects. The abrupt \HH\ transition to \HH/H $\approx$ 1-10%
occurs mostly from self-shielding although it is assisted by extinction for
n(H) $\la 16 \pccc$. Interior \HH\ fractions are substantially increased by
dust extinction below $\la 32\pccc$. At smaller n(H), \zetaH, small increases
in \HH\ triggered by dust extinction can trigger abrupt increases in N(HD).
