Insert hyperlinks in LaTeX (hyperref, href, url)

Load hyperref. \url{address} prints a web address as a clickable link, and \href{address}{text} puts the link on a text of your choice.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{hyperref}

Link to a web page

\url prints the address in a monospaced font and may break it at slashes and dots. \href takes the address first and the visible text second.

Complete document:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
The documentation is at \url{https://www.example.org/docs}.
News is posted on \href{https://www.example.org}{the project page}.
\end{document}
Result
The compiled example

Open in the editor

Link to an email address

Write mailto: before the address in the first argument. A click then opens the mail program.

Contact: \href{mailto:anna@example.org}{anna@example.org}
Result
The compiled example

Open in the editor

Links inside the document

With hyperref loaded, every \ref, \cite, footnote mark and entry in the table of contents is a link. \hyperref[key]{text} puts the link to a \label on any text.

\section{Method}\label{sec:method}
Text of the section.

\section{Results}
See section~\ref{sec:method} or read
\hyperref[sec:method]{the description of the method}.
Result
The compiled example

Open in the editor

Special characters in an address

In the running text, write the address as it is: \url and \href accept _, &, ~, # and % without a backslash. Inside the argument of another command, such as \footnote, # and % need a backslash.

\url{https://www.example.org/search?q=a_b&page=2#results}

A note.\footnote{\url{https://www.example.org/a\%20b\#results}}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages