Creating and Customizing Hyperlinks in LaTeX

Creating and Customizing Hyperlinks in LaTeX

This post may contain affiliate links that allow us to earn a commission at no expense to you. Learn more

Hyperlinks in LaTeX offers many features for creating high-quality professional-looking documents. In the digital era, it is sometimes vital for documents to contain hyperlinks. These could be links to other websites that offer additional information about a particular topic, or they may be hyperlinks that direct to a certain file in your system. Let’s examine how to use hyperlinks in LaTeX properly.

LaTeX uses the hyperref package to cross-reference elements and create hyperlinks. You can include this package in your document preamble by using command \usepackage{hyperref}. The package enables you to add links into your document along with a custom description.

An example of how to use this is shown below:




Example of Hyperlinks in a document.


Once you have added the hyperref package, you can place hyperlinks in LaTeX in any part of your document by using the \href command. This is demonstrated in the example below:




Example of Hyperlinks in a document.

Here is the first hyperlink:  \href{}{Click This}


This should produce an output that resembles the following:

Embedding a URL Into Your Document

LaTeX allows you to insert bare URLs into your document using the command \url. For example:


Adding a simple URL without any additional description: \url{}


This should produce an output that resembles the following:

Adding an Email Address in Your Document

Adding an email address to LaTeX works a bit differently than adding a bare URL.  You will need to use the command \href as well as the attribute mailto to do this. This is shown in the following example:


This is an example of an email address: \href{mailto:[email protected]}{[email protected]}


When compiled, the output should resemble the following:

The email address in the above example will be clickable when compiled. It will direct users to create an email in their default email software or other program. This form of hyperlinks in LaTeX is useful when you need to embed an email address that directs users automatically.

How to Embed Files From Your System

LaTeX also allows you to link files from your system using the url and href commands. This starts by using the command run: at the start of a link string. An example of this is shown below:


\href{run:/path/to/sample/examplefile.ext}{your text shown}

You can also link documents through relative paths that lead to your current document. An example of this is shown below:

href{run:D:/doc_folder/doc_subfolder/yourexample_file.txt}{Windows, absolute path}

\href{run:doc_subfolder/yourexample_file.txt}{Windows, relative path}

\href{run:./doc_subfolder/yourexample_file.txt}{Windows, relative path, variant}

\href{run:/doc_folder/doc_subfolder/yourexample_file.txt}{Linux, absolute path}

\href{run:./doc_subfolder/yourexample_file.txt}{Linux, relative path}

LaTeX also allows you to create an anchor within your document and a corresponding link for it. You can create hyperlinks in LaTeX with an anchor using the following code:

\hypertarget{label}{target caption}

You can then create the corresponding link for this anchor using the command: \hyperlink{label}{link caption} 

In the above codes, the target caption refers to the caption that will be shown at your target location and the link location.

There are many options for customizing hyperlinks in LaTeX. You can set the hyperlink color and border using the command \hypersetup inthe document preamble. 

For example:








    pdftitle={An Example},




In the above code, \hypersetup{….} allows us to configure attributes of the link in the document. We then separated each of the parameters that followed using a comma. The syntax for these parameters is denoted as parameter=value.

\colorlinks=true informs LaTeX to make the links colored. The default color produced with this command is red.

\linkcolor=blue informs LaTeX that internal links that were created using cross-referenced elements should be in blue

\filecolor=magenta informs LaTeX that any links to local files should be in magenta.

\urlcolor=cyan informs LaTeX that any links to websites should be in cyan.

\urlstyle{same} informs LaTeX to print the links using a mono-style space font.

In certain cases, you may need to insert links into your document manually. This is possible using the command \label. LaTeX lets you do this because cross-referenced elements are turned into links after hyperref is imported.

For example:

You can directly link a word 

or \hyperlink{thesentence}{a sentence} in your document.

\hypertarget{thesentence}{this sentence}.

This should produce an output that resembles:

As mentioned above, you can create hyperlinks in LaTeX in many different styles. Some of these are shown below:

  • hyperindex: This turns the page numbers in the index entries into clickable hyperlinks. It’s default value is true
  • linktocpage: This turns your page numbers into links instead of the text in the Table of Contents. It’s default value is false.
  • breaklinks: This informs LaTeX to break links into multiple lines.It’s default value is false.
  • colorlinks: This sets the color for the text in links and anchors. These colors will show up in the document’s printed version. It’s default value is false. 
  • linkcolor: This sets the color for normal internal links in the document. It’s default value is red.
  • anchorcolor: This sets the color for your document’s anchor text. It’s default value is black
  • citecolor: This sets the color for your document’s bibliographic citations. It’s default value is green.
  • filecolor: This sets the color for the links that open local files on your system. It’s default value is cyan.
  • urlcolor: This sets the color for your document’s linked URLs. It’s default value is magenta.

Final Thoughts

As you can see, LaTeX allows you to insert hyperlinks into your document in many different ways. You can also customize hyperlinks in LaTeX using the various commands discussed above. Hyperlinks help lead readers to valuable information, so consider using them in your next LaTeX document.

Frequently Asked Questions

Some frequently asked questions related to hyperlinks in LaTeX are shown below:

Q1. How Do You Hyperlink in Latex?

You can add a hyperlink into your LaTeX article using the command \usepackage{hyperref} and then including the command \href{YOUR URL}{TEXT FOR YOUR HYPERLINK}.

Q2. What Is Hyperref Latex?

hypperef is a LaTeX package that allows you to cross-reference elements and create hyperlinks.

Q3. Can We Change the Colour of Hyperlink Using Latex?

You can change the color of hyperlinks in LaTeX using the command  colorlinks=true followed by  
 linkcolor=[color name],
filecolor=[color name],      

Q4. How Do I Make a Clickable Link?

You can make a clickable link using the command \usepackage{hyperref} and then including the command \href{YOUR URL}{TEXT FOR YOUR HYPERLINK}.

Q5. What to do if I still have issues with the LaTex types of lists? 

We find sites like WikiBooks and the StackExchange helpful.

Further Reading

LaTex Tutorial

  1. 27 Pros and Cons of Using LaTex for Scientific Writing
  2. 6 easy steps to create your first Latex document examples
  3. How to add circuit diagrams in Latex
  4. How to change Latex font and font size
  5. How to create a Latex table of contents
  6. How to create footnotes in LaTeX and how to refer to them, using the builtin commands
  7. How to create Glossaries in LaTeX
  8. How to create plots in Latex – codes and examples
  9. How to create symbols in LaTeX – commands for Latex greek alphabet 
  10. How to create tables in LaTeX – rows, columns, pages and landscape tables
  11. How to drawing graphs in Latex – vector graphics with tikz
  12. How to highlight source code in LaTeX
  13. How to insert an image in LaTeX – Managing Latex figure and picture
  14. How to Itemize and Number List – Adding Latex Bullet Points
  15. How to reference in Latex – 5 steps to bibliography with Bibtex
  16. How to use Latex Packages with examples
  17. How to use LaTeX paragraphs and sections
  18. LaTeX Installation Guide – Easy to follow steps to install LaTex
  19. Learn to typeset and align Latex equations and math

Photo of author
SJ Tsai
Shen Ju Tsai (SJ) is the Chief Editor at His role involves managing a team of writers, overseeing content creation, and conducting research for content planning and keyword selection.

Leave a Comment