Enum CssUnit
public enum CssUnit
Fields
Cap = 13The font's cap height.
Ch = 15The advance of the font's "0".
Cm = 3Centimeters (96px / 2.54).
Dvh = 321% of the dynamic viewport height.
Dvw = 311% of the dynamic viewport width.
Em = 9The element's font size.
[SuppressMessage("Naming", "CA1711", Justification = "The CSS unit's name.")] Ex = 11The font's x-height.
Ic = 17The advance of the font's "水" (CJK water ideograph).
In = 6Inches (96px).
Lh = 19The element's line height.
Lvh = 301% of the large viewport height.
Lvw = 291% of the large viewport width.
Mm = 4Millimeters.
None = 0A unitless number, such as SVG's user units or a line-height multiplier.
Pc = 8Picas (12pt).
Percent = 1A percentage of a reference length the property defines.
Pt = 7Points (1/72 in).
Px = 2CSS pixels.
Q = 5Quarter-millimeters.
Rcap = 14The root font's cap height.
Rch = 16The advance of the root font's "0".
Rem = 10The root element's font size.
Rex = 12The root font's x-height.
Ric = 18The root font's Ic.
Rlh = 20The root element's line height.
Svh = 281% of the small viewport height.
Svw = 271% of the small viewport width.
Vb = 241% of the viewport size in the block axis.
Vh = 221% of the viewport height.
Vi = 231% of the viewport size in the inline axis.
Vmax = 26Vmin = 25Vw = 211% of the viewport width.
Examples
bool isLength = CssLength.TryParse("1.5em", out CssLength length); // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px); // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle); // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);
// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
CssUnit.Percent => 3, // a percent of a 300px box
CssUnit.Em => 16,
CssUnit.Px => 1,
_ => double.NaN,
}); // 268