Links in LaTeX: hyperref, \href, \url and Clickable References

Updated December 1, 2026

Quick answer

  • Package: \usepackage{hyperref}, near the end of the preamble, but before cleveref or bookmark.
  • Link with your own text: \href{https://example.org}{link text}. Show the address itself: \url{https://example.org}.
  • Link inside the document: \hyperref[sec:intro]{link text}, or \autoref{sec:intro} for “section 1”.
  • Colours instead of boxes: \hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue}; no boxes and no colour: \usepackage[hidelinks]{hyperref}.
  • URL font and line breaks: \urlstyle{same} for the text font, \usepackage{xurl} after hyperref for long URLs.

Start with the complete example, then adjust package order and link appearance for your document class.

LaTeX hyperref Package Order: Near the End, Not Always Last

Load hyperref after most packages, then its extensions. Put options in square brackets or a \hypersetup call:

\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{booktabs}
% ... all other packages ...
\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=blue,
}

Packages loaded after hyperref include cleveref, glossaries, bookmark, hypcap and algorithm (from the algorithms bundle). Check the package and class documentation for exceptions.

LaTeX Links to Websites: \href, \url and \nolinkurl

The three commands for external links differ in what they print and whether it is clickable:

% Print the address and link it
\url{https://www.useoctree.com/learn}

% Link arbitrary text to an address
\href{https://www.useoctree.com/learn}{the Octree learning hub}

% Print the address in URL style, but do not make it a link
\nolinkurl{https://www.useoctree.com/learn}
  • \url{...} typesets the address verbatim in a monospaced font and links it. Special characters such as %, #, ~, & and _ can be typed directly.
  • \href{URL}{text} shows text and links to URL. The text is ordinary LaTeX, so it can contain formatting, math or an image.
  • \nolinkurl{...} is \url without the link, useful for printed documents or for showing an address inside \href: \href{https://example.org}{\nolinkurl{example.org}}.

Without hyperref, the url package alone provides \url (no link, just correct typesetting). hyperref loads url for you.

Links to local files and relative addresses

\href is not limited to the web. A file: address opens another document, and run: asks the viewer to launch a file with its default application. Whether these work depends on the PDF viewer and its security settings, so use them only for documents that stay on one machine or intranet:

\href{file:./appendix.pdf}{the appendix}
\href{run:./analysis.xlsx}{the spreadsheet}

% A target without a scheme is treated as a local file, not a web URL
\href{appendix.pdf}{the appendix}   % same as file:appendix.pdf

For a document you will email or upload, prefer a full https:// address.

Line-Breaking Long URLs

Default URL breaks exclude hyphens and long alphanumeric runs, which can cause overfull lines. Three fixes:

% 1. Allow breaks at hyphens: pass the option to url BEFORE hyperref
\usepackage[hyphens]{url}
\usepackage{hyperref}

% 2. Add extra break points yourself (after loading hyperref)
\makeatletter
\g@addto@macro{\UrlBreaks}{\UrlOrds}   % also allow breaks after - * ~ ' "
\makeatother

% 3. Let URLs break anywhere: load xurl after hyperref
\usepackage{hyperref}
\usepackage{xurl}

xurl is the simplest modern answer and works with pdfLaTeX, XeLaTeX and LuaLaTeX. The older breakurl package is only needed for the latex → dvips → ps2pdf route, where links otherwise cannot span a line break; do not load it with pdfLaTeX.

URL font

\url uses a typewriter font. Change it for the whole document with \urlstyle:

\urlstyle{same}  % same font as the surrounding text
\urlstyle{tt}    % typewriter (default)
\urlstyle{rm}    % roman
\urlstyle{sf}    % sans-serif

Link to a Section, Figure or Equation: \hyperref, \autoref and \nameref

With hyperref loaded, every \ref and \pageref becomes a link to the corresponding \label. hyperref adds three more commands, and cleveref adds \cref:

\documentclass{article}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\section{Introduction}
\section{Method}\label{sec:method}

See Section~\ref{sec:method}.            % "Section 2" - only the number is a link
See \autoref{sec:method}.               % "section 2" - name + number, all linked
See \nameref{sec:method}.               % "Method" - the section title, linked
See \hyperref[sec:method]{the method}.  % your own link text

See \cref{sec:method}.                  % "section 2"
See \Cref{sec:method}.                  % "Section 2"
\end{document}

\autoref takes its words from macros such as \sectionautorefname and \figureautorefname. The default for sections is lowercase; to get “Section 2” add \renewcommand{\sectionautorefname}{Section} after loading hyperref. cleveref is more flexible (ranges, lists, capitalisation) and is the better choice for a new document.

Anchors for unnumbered sections: \phantomsection

With standard classes, hyperref creates an anchor for \section*, but no section number. Put \addcontentsline after the heading so it uses that target. Use \nameref or custom link text instead of expecting a numbered \ref. For a custom heading that does not create an anchor, insert \phantomsection at the intended destination before adding the contents entry:

\clearpage
\section*{Acknowledgements}\label{sec:ack}
\addcontentsline{toc}{section}{Acknowledgements}
See \hyperref[sec:ack]{the acknowledgements}.

Arbitrary targets: \hypertarget and \hyperlink

To link to a spot that has no counter at all, place a named target and link to it by name:

\hypertarget{data-note}{The raw data were collected in 2025.}
...
As noted \hyperlink{data-note}{earlier}, the data are recent.

Links in the table of contents

In the table of contents only the section title is linked by default. Make the page number clickable too with linktoc=all, or only the page number with linktoc=page:

\hypersetup{linktoc=all}

Link Colours: colorlinks, hidelinks and Removing the Boxes

Out of the box hyperref draws a colored rectangle around every link: red for internal links, green for citations, cyan for URLs. The boxes are PDF annotations – they show up in viewers but are never printed. Still, most people want them gone. Pick one of the following:

% Option A: no boxes, no colors - links are invisible but still clickable
\usepackage[hidelinks]{hyperref}

% Option B: colored link text instead of boxes (this color DOES print)
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,       % internal links: \ref, ToC, footnotes
  citecolor=teal,       % \cite
  urlcolor=magenta,     % \url and \href
  filecolor=magenta,    % links to local files
}

% Option C: keep boxes but make them invisible
\hypersetup{pdfborder={0 0 0}}

% Option D: black link text both on screen and in print
\hypersetup{colorlinks=true, allcolors=black}

A fourth style, common in theses, is an underline instead of a box or a color: \hypersetup{pdfborderstyle={/S/U/W 1}} draws a one-point line under each link. Like the boxes, it is an annotation and does not print.

allcolors sets every link type at once. For a document that will be printed, the usual choice is colorlinks=true with dark, readable colors, or hidelinks if the links should not be visible on paper at all. Colors can be any xcolor name or definition, e.g. \definecolor{linkblue}{RGB}{0,51,153}.

PDF Metadata and Bookmarks with \hypersetup

hyperref also writes the PDF's document properties and the bookmark panel. Set them once in the preamble:

\hypersetup{
  pdftitle={Fast Hyperlinks in LaTeX},
  pdfauthor={Ada Lovelace},
  pdfsubject={A guide to the hyperref package},
  pdfkeywords={LaTeX, hyperref, PDF},
  pdfpagemode=UseOutlines,   % open with the bookmark panel visible
  bookmarks=true,
  bookmarksopen=true,        % expand the bookmark tree
  bookmarksnumbered=true,    % show section numbers in bookmarks
  unicode=true,              % allow non-ASCII characters in metadata
}

If you would rather reuse \title and \author, load hyperref with the pdfusetitle option. Other useful values for pdfpagemode are UseNone, UseThumbs and FullScreen. The bookmark tree is built from the .out file, so it needs two compilation runs to be complete.

Email Links

An email address is just a URL with the mailto: scheme. Use \href for the link and, if you want the address in the URL font, \nolinkurl for the visible text:

\href{mailto:ada@example.edu}{ada@example.edu}
\href{mailto:ada@example.edu}{\nolinkurl{ada@example.edu}}
\href{mailto:ada@example.edu?subject=Question%20about%20the%20paper}{Email the author}

Separate printed headings, contents entries and bookmarks

A heading can have three outputs: typeset text, a table-of-contents entry and a PDF bookmark. A short optional title controls the contents and running headings; \texorpdfstring supplies a plain-text alternative for a PDF string. Neither is a general escape mechanism for arbitrary URLs. Keep a destination with percent signs outside moving arguments by defining it first.

\documentclass{article}
\usepackage[hidelinks]{hyperref}
\urldef{\dataseturl}\url{https://example.org/data_v2.csv?name=a%20b#results}
\begin{document}
\tableofcontents
\section{Results for \texorpdfstring{$\alpha>1$}{alpha greater than 1}}
\label{sec:results}
Download the data.\footnote{Source: \dataseturl.}
\begin{figure}[htbp]
\centering
\rule{3cm}{1cm}
\caption[Dataset overview]{Dataset overview; source: \dataseturl.}
\label{fig:data}
\end{figure}
See \autoref{fig:data} in \autoref{sec:results}.
\end{document}

The percent sign in this pre-defined address is part of the URL, not a source comment swallowed while reading a footnote argument. The short caption keeps the address out of the list of figures. Ordinary figure captions do not automatically become PDF bookmarks; section headings normally do. Avoid assuming the contents, list of figures and bookmark tree are interchangeable.

Compile twice, open the bookmark panel, and click the figure reference and the footnote URL. A clean compile proves the syntax, not that the remote resource exists. Check that the link annotation preserves the query and fragment as well as the visible label. If the viewer refuses an external link, try its permission settings or another viewer before rewriting working LaTeX.

Special Characters in URLs: % and #

Typed directly in the body of the document, \url and the first argument of \href both accept %, #, ~, & and _ as they are. The exception is when the command sits inside the argument of another command (a \footnote, a \newcommand definition, a \multicolumn or tabularx cell). There the characters are read by TeX before \url sees them. For \href the fix is simple: hyperref accepts the escaped forms \%, \#, \&, \_ and \~ in the URL argument. For \url in such a place, define the address once with \urldef and use the resulting command:

% Fine in running text:
\url{https://example.org/~ada/report_v2.pdf#page=3}
\href{https://example.org/search?q=latex&lang=en}{search}

% Inside another command's argument, escape in \href:
\newcommand{\homepage}{\href{https://example.org/\~ada/a\_b.html\#top}{home}}
Data at 100\% quality.\footnote{\href{https://example.org/?x=1\&y=2}{source}}

% For \url, pre-define the address with \urldef (in the preamble or body)
\urldef{\datalink}\url{https://example.org/~ada/report_v2.pdf#page=3}
\footnote{See \datalink.}

Common Errors

MessageCauseFix
Package cleveref Error: cleveref must be loaded after hyperref!Load order: cleveref came firstMove \usepackage{cleveref} below \usepackage{hyperref}
Links missing or \autoref names wrong after adding a packageA package loaded after hyperref redefined \section, \caption or \footnoteLoad hyperref last (except cleveref, glossaries, bookmark, hypcap, algorithm)
Illegal parameter number in definition of \Hy@tempa# in a \url inside \footnote or another command's argumentUse \href{...\#...}{text} or \urldef (see special characters)
File ended while scanning use of \@footnotetext% in a URL inside a footnote starts a comment and swallows the closing braceEscape it as \% in \href, or \urldef the address
Overfull \hbox, URL sticks into the marginThe URL has no allowed break point\usepackage{xurl} after hyperref
Token not allowed in a PDF string (Unicode): removing `math shift'Math or a command in a section title that goes into the bookmarksWrap it in \texorpdfstring{TeX}{plain text}
destination with the same identifier (name{page.1}) has been already used, duplicate ignoredTwo pages share the same number, e.g. the title page and the first page of the bodyUse \pagenumbering to switch styles (roman front matter, arabic body), or \hypersetup{pageanchor=false} around the unnumbered pages
Option clash for package hyperrefhyperref already loaded by the class or another package with different optionsRemove the options from \usepackage and use \hypersetup, or \PassOptionsToPackage before \documentclass
Rerun to get /PageLabels entry or outlines (.out) file has changedLinks and bookmarks need a second passCompile again
Links jump to the wrong placeMissing anchor, often an unnumbered section or a floatAdd \phantomsection; put \label after \caption
Link text is cut off at a line breakUsing latex + dvipsLoad breakurl after hyperref, or switch to pdfLaTeX

Complete Example

\documentclass{article}
\usepackage[hyphens]{url}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{cleveref}

\hypersetup{
  colorlinks=true,
  linkcolor=blue!60!black,
  citecolor=green!50!black,
  urlcolor=magenta!70!black,
  linktoc=all,
  pdftitle={Hyperlinks in LaTeX},
  pdfauthor={Ada Lovelace},
  pdfkeywords={LaTeX, hyperref},
  bookmarksnumbered=true,
}
\renewcommand{\sectionautorefname}{Section}
\urlstyle{same}

\title{Hyperlinks in LaTeX}
\author{Ada Lovelace\\ \href{mailto:ada@example.edu}{\nolinkurl{ada@example.edu}}}

\begin{document}
\maketitle
\tableofcontents

\section{Introduction}\label{sec:intro}
The \texttt{hyperref} manual lives on
\href{https://ctan.org/pkg/hyperref}{CTAN}; the plain address is
\url{https://ctan.org/pkg/hyperref}. Results follow in \cref{sec:results}.

\section{Results}\label{sec:results}
As promised in \autoref{sec:intro}, see \nameref{sec:intro} and
\hyperref[sec:intro]{the opening section}.

\clearpage
\section*{Acknowledgements}
\label{sec:ack}
\addcontentsline{toc}{section}{Acknowledgements}
Thanks to everyone who reads the manual before asking.
See \hyperref[sec:ack]{the acknowledgements}.
\end{document}

Compile twice, then test the contents and “Results” links in a PDF viewer. Compilation does not check external websites. Unresolved references need consistent labels and the auxiliary files from the previous run.

Frequently Asked Questions

How do I create a clickable link in LaTeX?

Load hyperref, then use \href{https://example.org}{descriptive text} for a named link or \url{https://example.org} for a printed address. Check the PDF annotation as well as the visible text.

How do I remove colored boxes without disabling links?

Load hyperref with hidelinks or set \hypersetup{hidelinks}. This hides the visible link decoration while retaining clickable PDF links.

How do I use a URL containing percent signs in a footnote?

Define it outside the footnote with \urldef{\dataseturl}\url{...}, then use \dataseturl inside the note. The address is read safely before the surrounding argument can interpret percent as a comment.

Why is math missing from a PDF bookmark?

Bookmarks use PDF strings rather than typeset mathematics. Use \texorpdfstring{typeset version}{plain-text version} in the heading and inspect the bookmark panel after compiling twice.

Next Steps

Documentation and a place to test

Consult the hyperref documentation and url documentation for supported options. Test a complete example in LaTeX Preview, then check the PDF with your final document class.

Fix hyperref problems faster with AI

Open the example in Octree, compile it, and use AI chat to ask about package order or a warning from your document. Check the resulting PDF links before sharing it.

Open Octree →