Why are URLs typeset with monospace fonts by default?

The default was chosen by the package author, according to the common way of setting URLs. Using a monospaced font helps distinguishing them, and this is the main reason.

However the font can be changed with \urlstyle that accepts one argument among

tt
rm
sf
same

The default is equivalent to \urlstyle{tt}; with \urlstyle{rm} and \urlstyle{sf} the font will be the roman or sans serif upright font. With \urlstyle{same} the current font will be used.

\documentclass{article}
\usepackage{url}
\begin{document}
\url{http://tex.stackexchange.com}

\urlstyle{rm}
\url{http://tex.stackexchange.com}

\urlstyle{sf}
\url{http://tex.stackexchange.com}

\urlstyle{same}
\url{http://tex.stackexchange.com}

\bfseries\urlstyle{same}
\url{http://tex.stackexchange.com}

\itshape\urlstyle{same}
\url{http://tex.stackexchange.com}

\mdseries\itshape\urlstyle{same}
\url{http://tex.stackexchange.com}

\end{document}

enter image description here


The first version of url.sty was written in 1996. While nowadays URLs are common and recognized by everyone, this wasn't the case at that time. At that time URLs were still heavily connected to computer code.


I'm guessing, but...

Computer code has traditionally been printed in a monospace (typewriter) font and in some sense a URL is computer code. I certainly think that a URL should be easily distinguished from surrounding text and using a font change does that (as would a change in colour, or underlining, or ...) but I think that monospace (typewriter) is now the expected means. Not all URLs as written include the http://www. preliminaries so a traditional scheme gives clues to even abbreviated URLs.

I know that not all computer code is in typewriter/monospaced as the literate programming systems (and the listings package) use different non-monospaced fonts when printing but I find code in that form much more difficult to understand than the simple (plagiarising Ford's remark on the colours of his cars) "any font you want provided it is monospaced".