How to Add a Hyperlink in LaTeX

Load \usepackage{hyperref} and write \href{https://example.com}{link text} for a link with your own text, or \url{https://example.com} to print the address itself. With hyperref loaded, \ref, \cite and the table of contents also become clickable.

hyperref commands

  • \usepackage{hyperref}
    Text mode, no math preview

    Load in the preamble, normally as one of the last packages.

  • \href{https://example.com}{text}
    text

    Clickable text pointing to a URL.

  • \url{https://example.com}
    Text mode, no math preview

    Print the URL in monospace and make it clickable; breaks at / and similar.

  • \href{mailto:name@example.com}{Email me}
    Text mode, no math preview

    Link that opens the reader's email program.

  • \autoref{sec:intro}
    Text mode, no math preview

    Internal link with the name added: "Section 2".

  • \hyperref[sec:intro]{this part}
    Text mode, no math preview

    Internal link with your own text to a \label.

  • \hypersetup{colorlinks=true, urlcolor=blue}
    Text mode, no math preview

    Colored link text instead of boxes.

  • \usepackage[hidelinks]{hyperref}
    Text mode, no math preview

    Links stay clickable but show no box or color.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Hyperlinks examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

  • Linked formula

    e i π + 1 = 0
    LaTeX
    \href{https://en.wikipedia.org/wiki/Euler_identity}{e^{i\pi} + 1 = 0}

    MathJax can link any part of a formula with \href; click the preview to try it.

  • Linked word inside a formula

    x ∈ R
    LaTeX
    x \in \href{https://en.wikipedia.org/wiki/Real_number}{\mathbb{R}}
  • Linked text label

    Overleaf guides
    LaTeX
    \href{https://www.overleaf.com/learn}{\text{Overleaf guides}}
  • Link on a symbol

    ∇ f
    LaTeX
    \href{https://en.wikipedia.org/wiki/Nabla_symbol}{\nabla} f
  • Link in a sum

    ∑ n = 1 ∞ 1 n 2 = π 2 6
    LaTeX
    \sum_{n=1}^{\infty} \href{https://en.wikipedia.org/wiki/Basel_problem}{\frac{1}{n^2}} = \frac{\pi^2}{6}

In a LaTeX document

These commands work in the text of a .tex document (Overleaf, TeX Live, MiKTeX), not inside math. The box on the right shows what the compiled PDF looks like.

  • Link with custom text

    LaTeX
    \documentclass{article}
    \usepackage{hyperref}
    \begin{document}
    Read the \href{https://www.latex-project.org/help/documentation/}{LaTeX documentation}.
    \end{document}
    Compiled result

    Read the LaTeX documentation.

  • Printed URL

    LaTeX
    Source: \url{https://ctan.org/pkg/hyperref}
    Compiled result

    Source: https://ctan.org/pkg/hyperref

  • Link to a section

    LaTeX
    \section{Method}\label{sec:method}
    ...
    As shown in \autoref{sec:method}, ...
    Compiled result

    As shown in Section 2, ...

  • Colored links instead of boxes

    LaTeX
    \usepackage{hyperref}
    \hypersetup{
      colorlinks=true,
      linkcolor=blue,
      urlcolor=blue,
      citecolor=blue
    }

\href or \url

Use \href{URL}{text} when the reader should see words, and \url{URL} when the address itself must be printed, as in a reference list. \url sets the address in monospace and allows line breaks after characters like / and .; the xurl package lets long URLs break anywhere.

Always give the full address including https://. Without a scheme, hyperref treats the target as a file on disk and the link opens nothing in most PDF viewers.

Internal links and link style

Once hyperref is loaded, every \ref, \eqref, \cite, footnote mark and table-of-contents entry links to its target. \autoref{label} adds the right name ("Figure 3", "Section 2") to the link, and \hyperref[label]{text} links any text.

By default hyperref draws a colored box around links on screen (boxes are not printed). Use \hypersetup{colorlinks=true} for colored text or the hidelinks option for no marking at all.

Common mistakes

  • Without the package LaTeX stops with "Undefined control sequence".

    Instead of
    \href{https://example.com}{text}  (no hyperref)
    Write
    \usepackage{hyperref}
  • A link without https:// is read as a local file path and does not open the website.

    Instead of
    \href{www.example.com}{text}
    Write
    \href{https://www.example.com}{text}
  • hyperref patches many commands, so it generally goes last in the preamble (a few packages, such as cleveref, must come after it).

    Instead of
    \usepackage{hyperref}
    \usepackage{other-packages}
    Write
    \usepackage{other-packages}
    \usepackage{hyperref}
  • Inside another command's argument, % and # in a URL can break; escape them with a backslash there.

    Instead of
    \footnote{\url{https://example.com/a%20b}}
    Write
    \footnote{\url{https://example.com/a\%20b}}

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    Needs \usepackage{hyperref}. Overleaf's PDF preview shows the link boxes; they do not appear when printed. \url alone also works with the lighter url package, but without clickable links.

  • MathJax and KaTeX

    MathJax supports \href{URL}{math} inside formulas, as in the examples above, but not \url or the internal-link commands. KaTeX supports \href and \url only when its trust option allows links. In Markdown, write links with [text](URL).

  • Microsoft Word

    In Word insert a link with Ctrl+K. Links inside LaTeX formulas are not carried over when an equation is pasted into Word.

Hyperlinks in LaTeX: questions

How do I add a hyperlink in LaTeX?
Add \usepackage{hyperref} to the preamble, then write \href{https://example.com}{link text} where the link should appear.
How do I remove the red boxes around links?
Load hyperref with \usepackage[hidelinks]{hyperref} for no marking, or use \hypersetup{colorlinks=true} to color the link text instead.
How do I link to a section or figure?
Put \label{sec:x} after the section or caption, then use \autoref{sec:x}, \ref{sec:x} or \hyperref[sec:x]{text} — all are clickable with hyperref.
What is the difference between \href and \url?
\href shows your own link text; \url prints the address itself in monospace. Both are clickable.
How do I make an email link?
Use the mailto scheme: \href{mailto:name@example.com}{name@example.com}.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX