Visual External Link with CSS

Visual External Link with CSS

This is a simple snippet to show the end user a visual example of when they are clicking on an external link from your website. It uses the :after pseudo class to show an image that represents an external link.


Lets look at the following HTML code:

   <li><a href="#">CSS Portal</a></li>
   <li><a href="#" class="external">Google</a></li>
   <li><a href="#" class="external">Bing</a></li>
   <li><a href="#">CSS Portal Blog</a></li>
   <li><a href="#">CSS Portal Properties</a></li>

The above code represents 5 potential links, here we have two links that point to an external page, they are: Google and Bing. To each of these links, we have added an external class which will display an image for an external link.

The following CSS code is used to style our links:

.external:after {

A break down of the CSS is:
content – Here we place the location for our external link with the content property.
margin-left – As we don’t want the image touching our link, we add a margin of 5px to the left of the image.
vertical-align – This property will vertically align the image to the middle.

That’s it for this snippet, we hope you’ll find it useful for your websites.

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.