Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set icon of an page using CSS

Tags:

html

css

Is it possible to have this code:

<link rel="icon" href="icon.gif" />

Using css document?

(I would rather not have to go through and add that to every pages) and is it possible to set title of page using css(I am not gonna use it as all pages have different title but just for general info)


2 Answers

You cannot set the favicon using CSS.... You need to use a link tag with rel value of shortcut icon.

Inorder to set that, you need to put the below string in between the <head> tags..

<link rel="shortcut icon" href="favicon.ico" /> 
                                   -----^-----
             <!--Remember to have .ico as the extension else 
                 some browsers fail to load other extensions -->

You need to also specify the type attribute here type="image/x-icon" if IE fails to load your favicon, if it loads fine, you can just ignore the type attribute.

like image 120
Mr. Alien Avatar answered Sep 20 '25 22:09

Mr. Alien


You can't do it using CSS it can only be done by inserting

<link rel="icon" href="icon.gif" />

as you have described above.. CSS is used to format some text/images etc in the page and and there is nothing to format in icon let me guess if you are working on many pages you probably have either a blog or an script to generate pages just add this line of text in it.. And you can always change icon of each page at once by just changing the icon itself...:)