LaTeX Hyperlink: \href, \url and hyperref Examples

November 11, 2026 · 10 min read

LaTeX Hyperlink Guide: \href, \url and hyperref Setup

A LaTeX hyperlink comes from the hyperref package. Load it with \usepackage{hyperref}, then use \url to print a clickable address or \href to hide the address behind your own words. Once hyperref is loaded, cross-references to sections, figures and equations turn into links too, with no extra commands.

How Do I Add a Web Link in LaTeX?

A LaTeX hyperlink to a website needs hyperref in the preamble and one of two commands. \url takes only the address. \href takes the address first and the visible text second. Both work for email when you start the address with mailto:.

\documentclass{article}
\usepackage{hyperref}

\begin{document}
The package lives at \url{https://ctan.org/pkg/hyperref}.
Read the \href{https://ctan.org/pkg/hyperref}{hyperref documentation} first.
Send corrections to \href{mailto:editor@example.com}{the editor}.
\end{document}

Compile this with pdflatex and you get three clickable links. The first line prints the full address in typewriter font. The second prints only "hyperref documentation", and the third opens the reader's mail app.

Two small extras help here. Put \urlstyle{same} in the preamble if you'd rather print addresses in the body font. Use \nolinkurl when you want an address typeset like \url but not clickable, such as a placeholder in a tutorial.

Outside another command, you can paste a URL with % or # into \href exactly as it appears in the browser. Always include the scheme, though. In our test, \href{www.example.com}{...} produced a link that stored www.example.com as a relative address, so most PDF viewers won't open it as a website. Write https://www.example.com instead.

\url vs \href vs \hyperref: Which LaTeX Link Command to Use

LaTeX hyperlinks come in several kinds, and hyperref has a command for each target. This table shows what each one links to and what lands on the page.

CommandLinks toWhat the reader sees
\url{https://...}A web addressThe address, in typewriter font
\href{https://...}{text}A web address or mailto:Your text
\ref{sec:intro}A \labelThe bare number, such as 2
\autoref{sec:intro}A \labelType plus number, such as section 2
\nameref{sec:intro}A \labelThe heading's title text
\hyperref[sec:intro]{text}A \labelYour text
\hyperlink{glossary}{text}A \hypertarget anchorYour text
\href{appendix.pdf}{text}A local fileYour text

\hypertarget{glossary}{Glossary} sets a named anchor anywhere, even somewhere that has no counter. \nameref comes from the nameref package, which hyperref loads for you. For a local PDF, a relative path opens the other file in the viewer. A run: prefix, as in \href{run:notes.txt}{notes}, asks the viewer to launch the file, and some viewers warn first or refuse.

We prefer \autoref (or \cref from cleveref) over a bare \ref. The word "Figure" becomes part of the clickable area, so readers aren't stuck tapping a single digit on a phone screen.

Add a Hyperlink in LaTeX to a Section, Figure or Equation

An internal LaTeX hyperlink works through \label. Put the label right after the thing it names: after \section, after \caption inside a figure, or inside the equation environment. Then refer to it with any command from the table.

\section{Method}\label{sec:method}

\begin{figure}[h]
  \centering
  \rule{4cm}{2cm}
  \caption{Sensor layout}\label{fig:layout}
\end{figure}

\begin{equation}
  e^{i\pi} + 1 = 0 \label{eq:euler}
\end{equation}

\autoref{sec:method} explains \autoref{fig:layout}.
\hyperref[sec:method]{The method} ends with \eqref{eq:euler}.

With amsmath and hyperref loaded, the last two lines compile to "section 1 explains Figure 1. The method ends with (1)." The words "section", "Figure" and "The method" are part of their links. \eqref is an amsmath command, and hyperref makes its number clickable like \ref, though the parentheses stay plain text.

Notice the lowercase "section". hyperref's default name for it is lowercase, while figures and equations start with a capital. Add \renewcommand{\sectionautorefname}{Section} after loading hyperref to change it.

Unnumbered headings such as \section* have no number for \ref to print, though current hyperref still gives them a link target. For a contents entry that isn't a heading, like an index, put \phantomsection on the line before \addcontentsline so the entry jumps to the right page. hyperref also makes the table of contents clickable on its own.

How to Change Hyperlink Colors in LaTeX and Remove the Boxes

By default, hyperref draws a colored frame around each link: red for internal links, cyan for URLs and green for citations. The frames appear on screen only and vanish when you print. Most people want something else, and one \hypersetup line after \usepackage{hyperref} fixes it.

% Colored link text, no frames (the color also prints)
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue, citecolor=blue}

% Same idea, one key for every link type
\hypersetup{colorlinks=true, allcolors=blue}

% Links look like ordinary text but still work
\hypersetup{hidelinks}

% Keep plain text color and drop only the frames
\hypersetup{pdfborder={0 0 0}}

Turn on colorlinks without naming colors and you get the manual's defaults: red internal links, magenta URLs, green citations and cyan file links. Basic names such as blue and magenta work as is. Load xcolor before hyperref for names like teal. Our guide to colors in LaTeX lists the named colors you can use.

Which one should you pick? For a thesis that people read on screen and on paper, we'd set colorlinks with one dark color. Readers can still spot every link on a printout. Use hidelinks for documents where links should stay invisible, like a printed CV.

You can also ask for underlined links with pdfborderstyle={/S/U/W 1}. The hyperref manual warns that not every PDF viewer supports it, so test it before you rely on it. For an underline that's part of the text itself, see our guide to underlining in LaTeX.

Why Isn't My LaTeX Hyperlink Clickable?

Most dead LaTeX links trace back to a short list of causes. Check them in this order:

  • hyperref isn't the last package. It redefines many LaTeX commands, and a package loaded after it can undo that work. Move \usepackage{hyperref} to the end of the preamble.
  • The URL has no scheme. Add https:// or mailto: so the viewer knows it's a web or email address.
  • A % or # sits inside another command. The hyperref manual says they need no escaping unless \href or \url sits in another command's argument, like a footnote or caption. Escape them there.
  • You see ?? instead of a number. LaTeX writes labels to the .aux file on the first run, so compile twice.
  • You built a DVI. Compile straight to PDF with pdflatex, xelatex or lualatex. Links in a DVI depend on the driver and viewer.

Here's the footnote fix in practice. It printed the address and the percent sign correctly in our test.

\footnote{Results at \url{https://example.com/search?q=latex\#top}, 100\% free.}

For an address you reuse in captions, the url package's \urldef stores it once in a command that's safe to use inside arguments. A link inside a section title can also break the PDF bookmarks. Wrap it as \texorpdfstring{\url{https://ctan.org}}{CTAN} so the bookmark gets plain text.

Here's the limitation: "load hyperref last" isn't absolute. cleveref must load after hyperref, and a few other packages document their own order. There's no single rule that covers every preamble, so read the package docs when a new addition breaks your links.

Breaking Long LaTeX Links Across Lines

A long address in \url can run past the right margin, and the log reports an overfull box. The xurl package fixes this by allowing a break after any letter or digit, plus characters such as /, . and -.

\usepackage{xurl}
\usepackage{hyperref}

Add that one line, keep hyperref last as usual, and leave the rest of the document alone. Your existing \url commands pick up the new break points. \href text is ordinary prose, so it already breaks between words.

PDF Bookmarks and Metadata With \hypersetup

hyperref writes PDF bookmarks from your headings by default, so the viewer's sidebar mirrors your outline. The same \hypersetup command fills in document properties that show up in the viewer's info panel.

\hypersetup{
  pdftitle={Thermal Survey of the North Wing},
  pdfauthor={Ada Lovelace},
  bookmarksopen=true,
  bookmarksnumbered=true
}

bookmarksopen expands the bookmark tree, and bookmarksnumbered adds section numbers to it. Pass pdfusetitle as a package option instead if you'd like hyperref to copy \title and \author for you.

Hyperlinks in LaTeX Beamer Slides

Beamer loads hyperref for you, so a second \usepackage{hyperref} isn't needed. Set options with \hypersetup, or pass them through the class as \documentclass[hyperref={...}]{beamer}. \href works on any slide. To jump between frames, mark a target with \hypertarget and link to it with \hyperlink{details}{\beamergotobutton{Details}}.

From Markdown Links to LaTeX \href

Markdown and LaTeX write the same link in different shapes. Here's one Markdown link:

Read the [hyperref documentation](https://ctan.org/pkg/hyperref).

Pandoc turns it into the LaTeX below, and an address written as <https://pandoc.org> becomes \url{https://pandoc.org}.

Read the \href{https://ctan.org/pkg/hyperref}{hyperref documentation}.

Our Markdown to LaTeX converter does the same mapping in your browser and gives you a .tex file. It doesn't compile a PDF, so the links become clickable only when you compile that file with hyperref loaded. For Pandoc options and other elements, see converting Markdown to LaTeX. For the Markdown side, our Markdown links guide covers reference links and autolinks.

One catch if you write math in Markdown: KaTeX renders \href and \url only when its trust option allows them, and that option is off by default. Don't count on links inside $...$ in our editor's preview. Put links in normal Markdown text instead. Our KaTeX vs LaTeX comparison covers the trust option and other LaTeX features KaTeX won't render.

A LaTeX hyperlink takes one package and a handful of commands. Load hyperref last, use \href or \url for the web, \autoref or \hyperref for your own labels, and one \hypersetup line to replace the default frames. If you draft in Markdown, write it in the editor and convert it with the Markdown to LaTeX tool when you're ready to compile.