---
area: "Learn"
parent: "Learn"
url: "https://unpoly.com/learn/links"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [Learn](https://unpoly.com/learn.md)</nav>

# Links

Unpoly enhances links so they update a fragment of the current page, instead of loading a full new document. The rest of the page keeps its state: scroll positions, focus, unsaved form fields and running scripts all survive the click.

<nav aria-label="Contents">

#### Contents

- [Updating a fragment](#updating-a-fragment)
- [Handling all links](#handling-all-links)
- [Preloading links](#preloading-links)
- [Highlighting the current location](#highlighting-the-current-location)
- [See also](#see-also)

</nav>

## Updating a fragment {#updating-a-fragment}

To let Unpoly handle a link, set an [`[up-follow]`](https://unpoly.com/api/up-follow.md) attribute:

```html
<a href="/preferences" up-follow>Preferences</a>
```

When the user clicks, Unpoly fetches `/preferences`. The server renders a full HTML page, the same way it would for a regular page load. Unpoly then extracts the response's [main fragment](https://unpoly.com/api/main.md) and swaps it into the current page, leaving everything around it untouched.

To update a different fragment, add an [`[up-target]`](https://unpoly.com/api/up-follow.md#up-target) attribute with a CSS selector:

```html
<nav>
  <a href="/pages/a" up-target="article">A</a>
  <a href="/pages/b" up-target="article">B</a>
</nav>

<article>
  Page A
</article>
```

Clicking _B_ fetches `/pages/b` and replaces only the `<article>` element with its counterpart from the response.

The link stays a standard hyperlink. When the user opens it in a new tab, or when JavaScript is unavailable, the browser makes a regular full page load.

<nav aria-label="Read more">

- [More: Following links](https://unpoly.com/learn/following-links.md)

</nav>

## Handling all links {#handling-all-links}

Instead of annotating every link, you can configure Unpoly to follow all links on the page:

```js
up.link.config.followSelectors.push('a[href]')
```

<nav aria-label="Read more">

- [More: Handling all links](https://unpoly.com/learn/handling-all-links.md)

</nav>

## Preloading links {#preloading-links}

A link can request its destination before the user clicks, making the interaction feel instant:

```html
<a href="/stories/5" up-preload>Full story</a>
```

Hovering over the link already loads the response into the [cache](https://unpoly.com/learn/caching.md).

<nav aria-label="Read more">

- [More: Preloading links](https://unpoly.com/learn/preloading.md)

</nav>

## Highlighting the current location {#highlighting-the-current-location}

Links in a navigation bar are marked with an [`.up-current`](https://unpoly.com/api/up-current.md) class when they point to the current page:

```html
<nav>
  <a href="/users" class="up-current">Users</a>
  <a href="/posts">Posts</a>
</nav>
```

Style that class with your CSS to highlight the active menu section.

<nav aria-label="Read more">

- [More: Navigation bars](https://unpoly.com/learn/navigation-bars.md)

</nav>

## See also {#see-also}

To make a `<span>` or a table row act like a hyperlink, see [Elements that act like links or buttons](https://unpoly.com/learn/faux-interactive-elements.md).

<nav aria-label="In this chapter">

## In this chapter {#children-index-title}

- [Following links](https://unpoly.com/learn/following-links.md)
- [Handling all links](https://unpoly.com/learn/handling-all-links.md)
- [Preloading links](https://unpoly.com/learn/preloading.md)
- [Navigation bars](https://unpoly.com/learn/navigation-bars.md)
- [Custom links and buttons](https://unpoly.com/learn/faux-interactive-elements.md)

</nav>

<nav aria-label="Reading order">

- [Previous: Where to go from here](https://unpoly.com/learn/start/next.md)
- [Next: Following links](https://unpoly.com/learn/following-links.md)

</nav>

