Change link colours in LaTeX (hyperref, hypersetup)

By default hyperref draws a coloured frame around every link. \hypersetup{hidelinks} removes the frames, and \hypersetup{colorlinks=true} colours the link text instead.

Preamble

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

\usepackage{xcolor}
\usepackage{hyperref}

Remove the frames

The frames are red for links inside the document, green for citations and cyan for web addresses. They appear on screen only and are not printed. hidelinks removes them and leaves the links in the colour of the text; the same word works as a package option, \usepackage[hidelinks]{hyperref}.

This goes into the preamble.

\hypersetup{hidelinks}

Open in the editor

Colour the link text

colorlinks=true switches from frames to coloured text. linkcolor applies to links inside the document (red by default), citecolor to citations (green) and urlcolor to web addresses (magenta). allcolors=blue sets all of them at once.

This goes into the preamble.

\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=teal,
  urlcolor=violet
}

Open in the editor

Use your own colours

Define a colour with \definecolor from xcolor and use its name in \hypersetup. A dark colour stays readable in print.

This goes into the preamble.

\definecolor{linkblue}{HTML}{1A5FB4}
\hypersetup{colorlinks=true, allcolors=linkblue}

Open in the editor

Change the frames or underline the links

The frame colours are linkbordercolor, citebordercolor and urlbordercolor. Each takes three numbers from 0 to 1 for red, green and blue. pdfborderstyle={/S/U/W 1} replaces the frame with an underline that is 1 pt thick.

This goes into the preamble.

\hypersetup{
  linkbordercolor={0 0 1},
  urlbordercolor={0 0.5 0},
  pdfborderstyle={/S/U/W 1}
}

Open in the editor

Another colour for the table of contents

\hypersetup inside a group applies only up to the closing brace. This keeps the table of contents black while the links in the text stay blue.

Complete document:

\documentclass{article}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue}
\begin{document}
{\hypersetup{linkcolor=black}
\tableofcontents}

\section{Introduction}\label{sec:intro}
A link in the text: section~\ref{sec:intro}.
\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages