Force Non-Monospace Font into Fixed Width Using CSS

If this is for aligning digits in tables where some fonts (with traditional typography) render them by default with variable width (e.g. Segoe UI on Windows), you should look into CSS properties for: font-variant-numeric: tabular-nums; (this disables the proportional-nums default value for the numeric-spacing variant supported at least by OpenType fonts, and possibly by other … Read more

How do I style HTML5 canvas text to be bold and/or italic?

From the MDN documentation on CanvasRenderingContext2D.font: The CanvasRenderingContext2D.font property of the Canvas 2D API specifies the current text style to use when drawing text. This string uses the same syntax as the CSS font specifier. So, that means any of the following will work: ctx.font = “italic 10pt Courier”; ctx.font = “bold 10pt Courier”; ctx.font … Read more

How to properly set line height for Android?

I’ll explain this from Android Developer perspective. Line height usually means text size + “padding” top/bottom. So, if your designer write line height 19sp and text size 15sp, it means you need to have extra padding 4sp. 19sp – 15sp = 4sp. To implement it in your layout, use lineSpacingExtra attribute. <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:textSize=”15sp” … Read more