How to Make an HTML Link in a Web Page

As I have mentioned several times, I have a group of friends that are great artists. They, however, aren’t necessarily web programmers. So, in order to help them out for an up-coming blog hop on January 9, 2012, I decided to explain how to make a link using HTML. Hopefully this helps!!

An HTML link is created using the Anchor tag. It goes something like this:

<a href=”URL-to-the-web-pagetitle=”Some explanantion of the link, if you like>The Text you want display as the link in the web page</a>

In HTML each tag (generally) has an opening and a closing sequence. In the case of Anchor, it is <a> and </a> The <> indicates it is a tag. . The a is the tag name. The / in the second sequence, </a>, indicates it is a closing tag for the opening sequemce, <a> .

An anchor tag has an inner link text, which is the text that will actually show up in your web page document when it is read by the browser. This goes in between the opening anchor tag sequence and the closing tag sequence. In the example above, it is the text- The Text you want display as the link in the web page. This text can say anything you like. Most often, I actually use the URL to the web page I am trying to link to, so that in the case where the link might not work for some reason, the URL is displayed, and a user can copy the text and paste it into their browser, and they can get to the web page that way.

The actual linking part is handled by the href attribute. An HTML tag attribute sits inside an opening tag sequence. So the href attribute goes inside the <a> tag sequence, like so <a href=””> . What goes between the quotes is the URL to the web page that you are trying to link to. So, if I was trying to link to this blog, I would use the URL, http://Ursula-Smith.com/blog .

The final piece, which is optional, is the title attribute, but it is a nice thing to have. The title attribute, again goes inside the opening anchor tag sequence, like so- <a title=””> . The title allows a user to hover over the link, and the text within the title will be displayed by the browser (most times). So, in our example, the text Some explanantion of the link, if you like would be displayed. In the case where I use the URL as the link text, I usually add an explanation of the link in the title attribute.

So here is the code for an example link to this page:

<a href=”http://ursula-smith.com/how-to-make-an-html-link-in-a-web-page/” title=”This is a test”>Link to this page</a>

and here is the actual link: Link to this Page.

So, now things get a little bit tricky! Because this post is for a bunch of artists, you KNOW they will want to have their link text be an image rather than just text &amp;#59;&amp;#41;. No worries! Instead of just putting text in between the opening and closing anchor tag seuqences, you can put an image tag instead.

An image tag looks something like this-

<img src=”URL-to-the-image-on-a-web-server alt=”Alternate text in case image isn’t displayed” title=”Some explanantion of the link, if you like/>

Again, we have an opening tag sequence <img> , but instead of using a closing tag suequence </img> , we are using a self closing tag seuqence- <img /> . This is because there is really nothing that goes inside the opening and closing tag sequences. In the anchor example, we had the link text. In an image tag, there is nothing. The only thing that you need is the src attribute, which goes inside the opening tag sequence. So, we can self close the tag by putting a / before the > in the opening tag sequence.

The image that you want to display must exists somewhere on a web server, that is, it can not be sourced from your local computer!! The source attribute, src=””, will contain the URL that will point to the image on that web server.

The alternate attribute is not mandatory, but it is really nice thing to have and you really should use it. It is the text that will shown in case there is a problem displaying the image. And the title is the same as in the anchor case.

So if we put the two tags together, it would look like so:

 <a href=”http://ursula-smith.com/how-to-make-an-html-link-in-a-web-page/” ><img src=”http://ursula-smith.com/mixed-media/wp-content/uploads/2014/05/Gelli-Arts-Printed-Hand-Stickers-300×440.jpg“alt=”Alternate text in case image isn’t displayed title=”This is a test for the image link“/> </a>

And here is the example link:

Alternate text in case image isn't displayed
Gelli Arts Printed Hand Sticker

 

Hopefully, this is helpful to those of you just starting out with HTML!!

 

Adding a quick note on showing the HTML code so the user sees the actual HTML rather than the link. For instance, if you are trying to show a “grab a button” and the button keeps showing up rather than the code. You need to trick the browser into not interpreting the HTML So you would need to write your  button code that looks something like

<a href=”http://ursula-smith.com/how-to-make-an-html-link-in-a-web-page/” ><img src=”http://ursula-smith.com/mixed-media/wp-content/uploads/2014/05/Gelli-Arts-Printed-Hand-Stickers-300×440.jpgalt=”Alternate text in case image isn’t displayed title=”This is a test for the image link“/> </a>

in a slightly different manner.  Rather than using all the angle bracket symbols, you need to change them to &lt; for the left angle bracket signs and &gt; for the right angle bracket signs. By doing this, the actual HTML code is shown to the user rather than the HTML being interpreted in which case the link would be shown to the user- they would not see the HTML button code. So your “Grab My Button” code would look something like:

&lt;a href=”http://ursula-smith.com/how-to-make-an-html-link-in-a-web-page &gt; &lt;img src=”http://ursula-smith.com/mixed-media/wp-content/uploads/2012/01/6635788089_e4ba47e872_m.jpgalt=”Alternate text in case image isn’t displayed title=”This is a test for the image link&gt; &lt;/a&gt;

You are basically tricking the browser into not interpreting the link and image HTML code, but instead the browser will show the HTML as text. The viewer will see the HTML as they would need to type it into their web page code (or blog widget) so that the link will show correctly on their page.

Hope this helps!!

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping