Monospace Cell Half-Em Width Rule
Half-em monospace approximation for caller known compatible metrics; actual glyph advances may differ.
Description
Estimate a monospace column span using a half-em cell assumption.
A half-em monospace cell is a simplifying width assumption. This tool estimates a column span under that assumption instead of measuring the actual font's advance width.
When to use this tool
Estimate a monospace column span using a half-em cell assumption. Use it when the input measurements and conventions below match the operation you need.
- Prepare fontPx, columns, respecting the measurement basis and boundaries below.
- Compare the worked example with your intended operation before reusing its result.
How to use the tool and how it works
- Enter every field in the input table using the stated units and exact supported selector spelling where applicable.
- Run the tool. Correct input errors before interpreting an output.
- Read the result fields below; use accompanying flags and the stated sign, boundary or model convention when interpreting a number.
fontPx must be positive and columns an integer from zero to one million. approximateWidthPx equals fontPx times 0.5 times columns.1
| Input field | Meaning and units | Accepted input |
|---|---|---|
| fontPx | Font px. Pixels. | Finite number; greater than zero |
| columns | Columns. | Integer; from 0 to 1000000 inclusive |
| Output field | Interpretation |
|---|---|
| result | Object containing the following named result fields. |
| result.approximateWidthPx | Approximate width px; use the stated units and sign convention. |
{
"input": {
"fontPx": 16,
"columns": 80
},
"output": {
"result": {
"approximateWidthPx": 640
}
}
} Limitations and assumptions
- Actual monospaced fonts need not use a half-em advance, and some characters occupy multiple cells. Shaping, tabs, fallback and terminal width conventions are not applied.
- Every declared field is required and unexpected fields are rejected. Numeric inputs must be finite; input errors are distinct from a valid false result or an explicitly qualified output.
- Extremely large inputs and nonfinite or excessively large outputs are rejected. List positions reported by the tool use zero-based indices unless stated otherwise.
Alternative or Complementary methods
Compare the metric calculation with the intended font and rendered text. Font shaping and layout inspection are more appropriate when the task depends on actual glyph positions or reading conditions. Compare the scope of the nearby tools below before substituting one.
References
Similar or alternative tools
- cap height percent of em
Cap-height percentage of em from measured cap-height and units-per-em font metrics.
- code inline monospace size match xheight
Matching inline code to body x-height requires independent metrics from both fonts.