How to Control URL Line Breaks and Add “Accessed” in LaTeX
At a glance
- 1. Choose a bibliography system
Use biblatex for field-level customization; classic BibTeX styles may require editing the style or adding text manually.
- 2. Enable URL breaks
Load xurl so long URLs can break at more positions in the bibliography.
- 3. Customize the URL label
Redefine biblatex’s url field format to print Accessed before the linked URL.
- 4. Compile and inspect
Run LaTeX, Biber, then LaTeX twice; check that breaks and access-date wording suit your style.
Long URLs can stick out into the margin because TeX does not treat every character in a URL as a possible line-break point. You can improve the breaks with xurl. To add text such as “Accessed:” before a bibliography URL, customize the URL field format if you use biblatex.
The example below assumes “Accessed:” is a label before the URL. The access date itself is stored separately in the urldate field; the bibliography style determines how that date is displayed.
A complete biblatex example
Save this as main.tex and the following database as references.bib.
\documentclass{article}
\usepackage[backend=biber,style=authoryear]{biblatex}
\usepackage{xurl}
\usepackage[hidelinks]{hyperref}
\addbibresource{references.bib}
% Put “Accessed:” before each URL in the bibliography.
\DeclareFieldFormat{url}{Accessed\addcolon\space\url{#1}}
\begin{document}
A cited online source \parencite{example}.
\printbibliography
\end{document}
@online{example,
author = {Example Author},
title = {An Example Web Page},
date = {2024-03-12},
url = {https://example.com/a/very/long/path/with/a/number-of-parts},
urldate = {2025-01-20}
}
Compile with LaTeX, then Biber, then LaTeX twice. For example, with a command-line TeX installation, run pdflatex main, biber main, and pdflatex main twice. The URL is clickable because hyperref is loaded, and xurl makes additional URL breakpoints available. The exact position and appearance of the access date depend on the selected biblatex style.
How URL breaking works
The url package, which biblatex uses to typeset URL fields, defines special handling for URL characters. xurl extends the available breakpoints, including points within long sequences that otherwise might remain unbroken. It is usually the simplest first fix for a URL that overruns the text block.
A line break does not change the URL: it only changes how it is laid out on the page. Avoid inserting spaces or manual line breaks into the URL field to force a wrap. Those characters can become part of the printed or clickable address.
If the URL still creates awkward spacing, you can allow a little extra stretch in URL spaces by adding this to the preamble:
\Urlmuskip=0mu plus 1mu
Use this sparingly. It changes how flexible the spacing is; it does not add valid breakpoints in the same way xurl does.
“Accessed” before the URL or before the date?
The field format in the example puts the literal label before the URL. It does not mean that the URL itself was accessed on a particular date. Put the date in urldate, as in the database entry, and let the bibliography style print it.
If your required style means “Accessed 20 January 2025: URL,” rather than “Accessed: URL” followed by a separately formatted date, you need to customize the style’s combined URL-and-date output. That output varies by biblatex style, so check the style documentation before redefining its bibliography macros. For a one-off entry, a note field can be used as a simpler workaround, but it is less consistent than using urldate.
If you use classic BibTeX
Classic BibTeX styles control the layout of bibliography entries through a .bst file. The xurl package can still help with line breaks, but a biblatex field-format declaration will not change a classic BibTeX bibliography. To add “Accessed:” automatically, use a style that supports the desired label, edit or customize the .bst file, or add the text manually in an entry field that your style prints. The exact option depends on the bibliography style.
Common mistakes
- Expecting a package to change every bibliography style:
xurlimproves URL breaking, but it does not decide what words appear around the URL. - Putting an access date in the URL field: Keep the address in
urland the date you consulted it inurldate. - Using
biblatexcommands with classic BibTeX:\DeclareFieldFormatis abiblatexcommand. It has no effect on entries formatted by a.bstfile. - Forgetting the bibliography backend: With the example’s
backend=bibersetting, run Biber between LaTeX passes so the citation and bibliography data are updated.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.