search

Style Anchor Tags by Link Type with CSS

This code aims to improve user experience. We often encounter situations where we click links without knowing where they lead. This code can improve UX by adding small icons next to links to show visitors that it is an external link – email, PDF file, image, etc.

/* external links */
a[href^="http://"]{
    padding-right: 20px;
    background: url(external.gif) no-repeat center right;
}
 
/* emails */
a[href^="mailto:"]{
    padding-right: 20px;
    background: url(email.png) no-repeat center right;
}
 
/* pdfs */
a[href$=".pdf"]{
    padding-right: 20px;
    background: url(pdf.png) no-repeat center right;
}

For more on link styling, see Styling External Links with CSS.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo