How To Add Image In The Title Bar - W3docs
Có thể bạn quan tâm
Most websites add an icon or image logo in the title bar. This icon logo is also called a favicon and can be useful for user engagement.
A favicon, also known as a URL icon, a tab icon, a shortcut icon, a website icon, or a bookmark icon, is a file containing one or more small icons associated with a particular website or web page.
You can let the browser detect your favicon or upload it to your hosting root area.
W3C standardized favicon in the HTML 4.01 recommendation. The standard implementation uses a <link> element with the rel attribute in the <head> section of the document that specifies the file format, file name, and location. The file can have any image format (ico, png, jpeg, gif) and can be in any website directory.Let the browser finds the favicon!
One way, which is the easiest, is by uploading an icon as a .png or .ico file from your hosting’s File Manager. If you prepare your image in png or ico, you can upload it to your hosting area, and most modern browsers will automatically detect favicon.png and favicon.ico files from your host (naming matters here, it should be exactly favicon). So, you’ll need no coding.
The other way is by using the HTML link inside the head tag.
Let's use HTML link tag:
/* it should be placed inside the head tag */ <head> <link rel="icon" type="image/png" href="path-to-your-favicon"/> </head>If you use a different image format, implement the appropriate changes (read the next paragraph), and change the value of the href attribute to the path where your image is located in your project. The ICO format is not as reliable anymore, and it's better to use png (to preserve transparency).
Depending on the favicon format, the type attribute must be changed:
- For PNG, use image/png.
- For GIF, use image/gif.
- For JPEG, use image/jpg.
- For ICO, use image/x-icon.
- For SVG, use image/svg+xml.
A favicon must have the following characteristics:
- Favicon.ico is the default name.
- Size should be 16×16, 32×32, 48×48, 64×64 or 128×128 pixels.
- Color should be 8 bites, 24 bites or 32 bites.
There are a lot of online tools that will help you create a favicon, convert the image formats, etc., and you can find them by a simple search on Google, by the way.
The image must be square dimensioned in any image format (ico, jpg, BMP, gif, png) to appear in browsers properly. Images with non-square dimensions will also work. However, such icons may not look professional.
Example of adding an image in the title bar:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <link rel="icon" type="images/x-icon" href="https://www.w3docs.com/favicon.ico" /> </head> <body> <h1>Hello from W3docs!</h1> </body> </html> Try it Yourself »If you take a look at the result of the above code, it should be something like this.
If you do not see the new favicon, clear your browser's cache and restart it.Different Platforms:
For different platforms, the favicon size should also be changed:
Platform | Name | Rel value | Favicon size |
---|---|---|---|
Google TV | favicon-96x96.png | icon | 96×96 |
Ipad Retina, iOS 7 or later | apple-touch-icon-152×152-precomposed.png | apple-touch-icon-precomposed | 152×152 |
Ipad Retina, iOS 6 or later | apple-touch-icon-144×144-precomposed.png | apple-touch-icon-precomposed | 144×144 |
Ipad Min, first generation iOS 7 or later | apple-touch-icon-76×76-precomposed.png | apple-touch-icon-precomposed | 76×76 |
Ipad Mini, first generation iOS 6 or previous | apple-touch-icon-72×72-precomposed.png | apple-touch-icon-precomposed | 72×72 |
Iphone Retina, iOS 7 or later | apple-touch-icon-120×120-precomposed.png | apple-touch-icon-precomposed | 120×120 |
Iphone Retina, iOS 6 or previous | apple-touch-icon-114×114-precomposed.png | apple-touch-icon-precomposed | 114×114 |
Add it to your code in the following way:
<!-- default favicon --> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <!-- wideley used favicon --> <link rel="icon" href="/favicon.png" sizes="32x32" type="image/png"> <!-- for apple mobile devices --> <link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-152x152-precomposed.png" type="image/png" sizes="152x152"> <link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-120x120-precomposed.png" type="image/png" sizes="120x120"> <!-- google tv favicon --> <link rel="icon" href="/favicon-96x96.png" sizes="96x96" type="image/png">Please note that you must change the href attribute value based on the location of your favicon file, either in your host or in your project folder if you're working locally. And the naming matters; otherwise, the browser can not detect it.
In the end, it is worth noting that you can use this open-source link which is a cheat sheet for favicon and has valuable information that may help you along the way.
Từ khóa » Html Icon In Head Title
-
How To Add Icon Logo In Title Bar Using HTML ? - GeeksforGeeks
-
How Do I Get My Page Title To Have An Icon? - Stack Overflow
-
How To Add A Favicon In HTML - W3Schools
-
How To Add Logo In Html Title Code Example
-
Html Title Icon Code Code Example - Code Grepper
-
More About The Document Head - W3C Wiki
-
How To Set Logo In Title Bar Html - YouTube
-
How Do I Add An Icon In An HTML Title? - Quora
-
How To Add Image In Title Bar In HTML? - The Tech Platform
-
How To Add A Favicon To Your Website With HTML | DigitalOcean
-
Başlıksız
-
How Can I Get The Logo On Title Bar? - Quora
-
How To Add A Favicon In Html - Javatpoint
-
Başlıksız