Generating a HTML Link


You want to create a HTML link in your Blade template.

You know you can use HTML directly and use the anchor tag (<a>...</a>) but you want to use the HTML facade.


Use the HTML::link() method.

If you only pass the URL as the first argument it will create a link using the URL as the title.

{{ HTML::link('') }}

This produces the following HTML.

<a href=""></a>

You can add a second argument for the title.

{{ HTML::link('', 'testing')}}

Which will produce the following.

<a href="">testing</a>

The third argument, if used, must be an array. It allows you to assign other attributes to the tag.

{{ HTML::link('', null, array('id' => 'linkid'))}}

Now the anchor tag also has the id attribute. Notice also that the title is back to the URL because we passed null as the second argument.

<a href="" id="linkid"></a>

A fourth option can be passed to make the URL secure. Note that this only works when the URL is automatically built (see the discussion below).

{{ HTML::link('/login', 'log in', array('id' => 'linkid'), true)}}

This produces something like what's below.

<a href="https://your.url/login" id="linkid">log in</a>


The URL portion will be completed as needed.

Laravel will automatically build the URL, using your application's URL as the base if an incomplete URL is passed.


  • you pass "test" for URL, it expands to "http://your.url/test"
  • you pass "" for URL (forgetting the scheme), it expands to "http://your.url/"

The exception to this are URLs beginning with the pound symbol (#).

  • you pass "#test" for URL, it stays "#test"

This allows for in-page links.

comments powered by Disqus