22 Votes

CSS: Style for fixed character width font

Question by Compi | Last update on 2021-05-14 | Created on 2017-08-18

Is CSS offering any possibility for generally defining a font with a fixed character width for a text? Of course, I could also set the font-family to "Courier" or a similar font, but I do not know whether this font is installed on the user's device.

Therefore, I am searching for a more general way. Is there anything available in CSS for this?

ReplyPositiveNegative
2Best Answer2 Votes

You can specify a generic font family as CSS's font-family.

In your case this would be "monospace":

<span style="font-family: monospace">Text</span>

With specifying "font-family: monospace", the browser will care about selecting a fixed character width font for your text. Depending on the browser settings and the device, this may be "Courier New", "Consolas" or something else.

Other generic values are "serif" for fonts with serifs, "sans-serif" for a font without serifs, "cursive" for a handwriting script like Comic Sans or "fantasy" for a general uncommon font.
Last update on 2021-05-14 | Created on 2017-08-19

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.