Lawrence Dol Lawrence Dol - 1 month ago 11
CSS Question

How do I get an HTML Text Area with monospaced text using CSS?

This may be a dumb noob question, but I can't figure out how to make my text area use a monospaced font.

Answer

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.

Comments