Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing HTML textarea to use a monospace font using CSS

Tags:

html

css

How can I make my text area use a monospaced font?

like image 381
Lawrence Dol Avatar asked Jan 09 '10 07:01

Lawrence Dol


People also ask

What is monospace font in CSS?

Courier New is the most widely used monospace serif font. Courier New is often used with coding displays, and many email providers use it as their default font. Courier New is also the standard font for movie screenplays.

How do I make my font monospaced?

Basically, for a font to be considered monospace, every glyph has to be the same width, right down to the exact same number of units. This includes even glyphs that should normally be zero width, or a certain width (such as em spaces, em dashes, etc).


2 Answers

If I'm understanding properly, it should already inherit default user-agent styles, but if you want to explicitly, just specify a font-family ( styles jacked from Stackoverflow stylesheet )

textarea {   font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace; } 

Specify the more specific (monospace-specific) font families first, and if the user agent doesn't have that available it will keep trying them until the end, in which case it would default to the default user agent font family for that element, if any was specified.

like image 77
meder omuraliev Avatar answered Oct 14 '22 00:10

meder omuraliev


You can also use the standard generic font-family: monospace, but be careful -- there are some severe side effects (sadly) in Chrome, Safari and anything WebKit based.

see:

  • http://webkit.org/blog/67/strange-medium/
  • http://archivist.incutio.com/viewlist/css-discuss/103606
like image 40
Jeff Atwood Avatar answered Oct 13 '22 22:10

Jeff Atwood