{"id":17083,"date":"2012-05-26T10:28:26","date_gmt":"2012-05-26T17:28:26","guid":{"rendered":"http:\/\/css-tricks.com\/?p=17083"},"modified":"2020-08-31T10:56:28","modified_gmt":"2020-08-31T17:56:28","slug":"favicons-next-to-external-links","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/favicons-next-to-external-links\/","title":{"rendered":"Favicons Next To External Links"},"content":{"rendered":"\n

Unless we make a custom CSS selector for every single site we want to do this for, CSS isn’t capable of yanking the href<\/code> off links and using it to plant a favicon next to the link. But if we involved a smidge of JavaScript, we can get it done.<\/p>\n\n\n\n\n\n\n

The “I Wish” CSS Only Technique<\/h3>\n\n\n

What would be nice is if you had simple semantic HTML like this:<\/p>\n\n\n\n

<a href=\"https:\/\/github.com\">GitHub<\/a><\/code><\/pre>\n\n\n\n

And then you could access everything you needed to insert a background image of the favicon using a service like getFavicon<\/a>.<\/p>\n\n\n\n

\/* Fair warning, this doesn't work *\/\n\na[href^=\"http:\/\/\"]::before {\n  content: url(https:\/\/g.etfv.co\/ + attr(href));\n}<\/code><\/pre>\n\n\n\n

Maybe the syntax wouldn’t be exactly like that, but something like it. The point is, you can’t mix up the url() syntax into parts like that in CSS.<\/p>\n\n\n

Google’s Favicon Service<\/h3>\n\n\n

Google has it’s own favicon service you can use.<\/del> For example:<\/p>\n\n\n\n

https:\/\/www.google.com\/s2\/u\/0\/favicons?domain=css-tricks.com<\/code><\/pre>\n\n\n\n
Update: thats broken now. You can use Grabicon<\/a> instead now though.<\/div>\n\n\n\n
Update: Grabicon requires a referrer apparently now which makes it fail in a variety of circumstances. Heidi Pungartnik pointed out Google’s service still exists, it’s just moved URL’s slightly. Example: https:\/\/www.google.com\/s2\/favicons?domain=css-tricks.com<\/a><\/div>\n\n\n\n