Are you using SVG favicons yet? A guide for modern browsers

栏目: IT技术 · 发布时间: 6年前

内容简介:You should be using SVG favicons. They’re supported in all modern browsers right now.Also, you probably don’t need all these icon links and sizes you’re copying from projects to projects. Let’s find out what’s the absolute minimum required, word by word.Th

Are you using SVG favicons yet? A guide for modern browsers.

Are you using SVG favicons yet? A guide for modern browsers

You should be using SVG favicons. They’re supported in all modern browsers right now.

Also, you probably don’t need all these icon links and sizes you’re copying from projects to projects. Let’s find out what’s the absolute minimum required, word by word.

Are you using SVG favicons yet? A guide for modern browsers

Icon

The main favicon can be an SVG of any size. The type type=”image/svg+xml” is unnecessary.

<link rel="icon" href="favicon.svg">

Mask icon

For Safari, it’s a bit different. You need to add a mask-icon . It’s also an SVG, but it has to be made of a single colour and placed on a transparent background. The browser adds the colour of the attribute.

<link rel=”mask-icon” href=”mask-icon.svg” color=”#000000">

Touch icon

The icon for iOS devices as well as favourites from browsers new tab page and more. You only need the 180 x 180 size, and the sizes attribute is superfluous.

<link rel="apple-touch-icon" href="apple-touch-icon.png">

Manifest

The manifest.json provides information about your web app or website. These lines are mandatory to pass Lighthouse ’s test. The icon linked is used by Android and Chrome. The largest size 512 x 512 is the only one needed.

{
    "name": "Starter",
    "short_name": "Starter",
    "icons": [{
        "src": "google-touch-icon.png",
        "sizes": "512x512"
    }],
    "background_color": "#ffffff",
    "theme_color": "#ffffff",
    "display": "fullscreen"
}

The theme-color meta is still required for Android’s Chrome browser colour.

<meta name="theme-color" content="#ffffff">

Done

That’s it, that’s all the icons you need for the current modern browsers, everything else is unnecessary. The msapplication-TileImage can be added if you want a different icon in Windows tiles otherwise the apple-touch-icon is used. The TileColor isn’t used anymore.

Everything else

Sadly, not everyone is on modern browsers yet BUT it can be easily resolved by dropping a 32 x 32 favicon.ico at the root of your website. This works everywhere else, even at your grandma’s.

Are you using SVG favicons yet? A guide for modern browsers

Dark mode

To finish, here’s a tip for dark mode. One of the benefits of an SVG favicon is that you can change the colour with CSS. Using the prefers-color-scheme media query, the colour of your favicon changes with the users dark or light mode. This method won’t work with the mask-icon since the colour is in the attribute but Safari adds a white background if there isn’t enough contrast.

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<style>
path {
fill: #000;
}
@media (prefers-color-scheme: dark) {
path {
fill: #fff;
}
}
</style>
<path fill-rule="evenodd" d="M0 0h16v16H0z"/>
</svg>

Are you using SVG favicons yet? A guide for modern browsers

Result

Here’s the final result. Copy this in the <head> of your website and don’t forget to place a favicon.ico at the root. :v:

<meta name="theme-color" content="#ffffff">
<link rel="icon" href="favicon.svg">
<link rel="mask-icon" href="mask-icon.svg" color="#000000">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="manifest" href="manifest.json">

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

计算机程序设计艺术(第3卷 英文版·第2版)

计算机程序设计艺术(第3卷 英文版·第2版)

Donald E.Knuth / 人民邮电出版社 / 2010-10 / 119.00元

《计算机程序设计艺术》系列被公认为计算机科学领域的权威之作,深入阐述了程序设计理论,对计算机领域的发展有着极为深远的影响。本书是该系列的第3卷,扩展了第1卷中信息结构的内容,主要讲排序和查找。书中对排序和查找算法进行了详细的介绍,并对各种算法的效率做了大量的分析。 本书适合从事计算机科学、计算数学等各方面工作的人员阅读,也适合高等院校相关专业的师生作为教学参考书,对于想深入理解计算机算法的读......一起来看看 《计算机程序设计艺术(第3卷 英文版·第2版)》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具