The simplest way to make an image a link in CakePHP is the url option on image(): $this->Html->image('logo.png', ['alt' => 'Home', 'url' => '/']). When you need extra attributes on the link itself, wrap image() inside link() and pass 'escape' => false so the image HTML isn’t printed as text. Both work in CakePHP 2 through 5.
Originally published in June 2010 for CakePHP 1.3. Rewritten in December 2026 for current versions.
Option 1: The url option
<?= $this->Html->image('logo.svg', [
'alt' => 'My Store home',
'url' => ['controller' => 'Pages', 'action' => 'display', 'home'],
]) ?>This outputs an <a> around the <img>. The image path is relative to webroot/img/.
Option 2: image() inside link()
Use this when the link needs its own class, title or target:
<?= $this->Html->link(
$this->Html->image('icons/delete.svg', ['alt' => 'Delete this user']),
['action' => 'delete', $user->id],
['escape' => false, 'class' => 'icon-link', 'confirm' => 'Delete this user?']
) ?>Without 'escape' => false, CakePHP escapes the image tag and you see <img src=...> as text on the page.
For actions that change data, such as delete, use postLink() instead of link(), so the action runs on a POST request and isn’t triggered by crawlers or prefetching.
Write useful alt text
When an image is the only thing inside a link, its alt text becomes the link’s name. Describe where the link goes or what it does, such as “Delete this user” or “My Store home”, not what the picture looks like. Leaving alt empty on a linked image makes the link unreadable to screen readers.
CakePHP 1.3
The 1.3 helpers were accessed as $html rather than $this->Html:
echo $html->link($html->image('user_red_delete.png'), '/users/delete/5', array('escape' => false));If you’re upgrading, a search for $html-> and $form-> finds most of the helper calls that need to change.
Common questions
Why does my image link show raw HTML?
The link text was escaped. Add 'escape' => false to the options of link(), or use the url option on image() instead.
Can I open the link in a new tab?
Yes. Use option 2 and add 'target' => '_blank' to the link options. CakePHP doesn’t add rel="noopener" for you in every version, so add it yourself.
How do I link a full-size image from a thumbnail?
Pass the full image URL as the link target: $this->Html->link($this->Html->image('thumbs/a.jpg', ['alt' => 'Kitchen, before']), '/img/full/a.jpg', ['escape' => false]).