Skip to content Skip to sidebar Skip to footer

Determine The Number Of Characters Per Line Given A Width (based On Font-size, Font-family)

Is there a way we can determine the number of characters per line for a given width of div based on parameters like font-size, font-family, etc? Please give a cross browser solutio

Solution 1:

Unless you're talking about a monospace* font, this answer isn't knowable without taking into consideration the specific text in question. As a basic example, note the difference between:

  • 10 MONOSPACE X'sXXXXXXXXXX
  • 10 MONOSPACE I'sIIIIIIIIII
  • 10 VARIABLE X's_ XXXXXXXXXX
  • 10 VARIABLE I's_ IIIIIIIIII

With a variable-width* font, the same number of characters, in the same font, may be two different widths. (hence the name)

*the term "monospace", "fixed-width", "fixed-pitch", or "non-proportional" font, is a font whose characters each take up the same amount of horizontal space. Conversely, "proportional", or "variable-width" fonts contain characters whose width may take up a varying amount of horizontal space.

Post a Comment for "Determine The Number Of Characters Per Line Given A Width (based On Font-size, Font-family)"