Home > other >  How to make   same width as regular space?
How to make   same width as regular space?

Time:12-30

When learning about HTML I thought and   had the same width but the following example show this does not hold.

<!DOCTYPE html>
<html lang="en">
   <meta charset="utf-8" />
</html>
<body style="font-family: Charter">
   Foo Foo&nbsp;Foo
</body>

The spaces are the same for most fonts, but not Charter for instance (it's pretty easy to find other examples). Why is that? And how can I fix it?

CodePudding user response:

From chapter 6 of the Unicode specification:

No-Break Space. U 00A0 no-break space (NBSP) is the nonbreaking counterpart of U 0020 space. It has the same width, but behaves differently for line breaking.

If the width of a space and a non-breaking space is different in a given font, then it is a bug in that font and there isn't much you can do beyond changing fonts.

CodePudding user response:

You can always change the font-size of the individual space

<!DOCTYPE html>
<html lang="en">
   <meta charset="utf-8" />
</html>
<body style="font-family: Charter">
   Foo Foo<span style='font-size:10px;'>&nbsp;</span>Foo
</body>

  • Related