Link preview
A link shown as a card: the page's title, description, image and site, as a chat, a comment or a composer shows a pasted URL.

No JavaScript needed. Only
dismissneeds Alpine and the package's script; without them the preview shows with no remove button. See getting started.
Use it
The component draws what your server already found. It fetches nothing.
<x-ds::link-preview
:url="$link->url"
:title="$link->title"
:description="$link->description"
:image="route('og-image', $link)"
:site="$link->site_name"
:favicon="$link->favicon_url"
:publishedAt="$link->published_at"
/>
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
url | string | — | The page. Only an http or https URL becomes a link; anything else (javascript:, data:) is shown as text. |
title | string | — | The page's title, held to two lines. Without one the domain stands in. |
description | string | — | Held to two lines (not shown in compact). |
image | string | — | The page's image. A failed image leaves a placeholder, not a hole. |
site | string | — | The site's name, before the domain. |
favicon | string | — | A small icon before the site. |
author | string | — | Shown with the date. |
publishedAt | string or DateTime | — | Shown as "3 Dec 2026". |
variant | row card compact | row | Image at the side, image on top, or one line. |
loading | bool | false | You are still fetching: a skeleton in its place. |
failed | bool | false | Fetching failed: a plain link showing the domain. |
target | string | _blank | Where it opens; _self (or an empty string) for the same tab. A new tab is said in the link's name. |
dismiss | bool | false | A remove button, for a preview in a composer: hides it and dispatches dismiss. |
dismissLabel | string | Remove preview | That button's name. |
Fetching the metadata, safely
Reading a stranger's page from your server is a request your server makes on someone else's say-so, which is how internal services get reached (server-side request forgery). When you fetch Open Graph data:
- Resolve the host and refuse private addresses: loopback, link-local
(including the cloud metadata address
169.254.169.254), and the private ranges, for IPv4 and IPv6. Check again after every redirect, and allow only a few. - Only
httpandhttps, on ports 80 and 443. - Bound it: a short timeout, and stop reading after a few hundred
kilobytes; the
<head>is near the top. - Treat everything you read as text. Blade escapes it here; do not mark it safe.
- Proxy the image through your own host (and cache it) rather than hot-linking it: the reader's browser then never tells the other site who is reading, and a changed image cannot change what was posted.
- Cache by URL, so a link pasted a thousand times is fetched once.
Render loading while the job runs and failed if it gives up, so the URL is
never lost.
In a composer
<x-ds::link-preview :url="$draft->link" :title="$draft->link_title" :dismiss="true"
x-on:dismiss="$wire.removePreview()" />
Accessibility
- The whole card is one link, named by its title, domain and "opens in a new tab", and described by its description, rather than read out end to end.
- Images are decorative (
alt=""): the title says what the link is. - The remove button is a separate button after the link, not inside it.
Don't
- Don't pass the URL through
{!! !!}or build the link yourself; the component's checks are the point. - Don't fetch metadata in the request that renders the page. Fetch in a
job and show
loading. - Don't hot-link the image where you can proxy it.
More in specs/link-preview.md.
From the package repo: edit this page on GitHub.