Stop Using Icon Fonts
irigoyen.dev
irigoyen.dev
<!-- Should be in all your pages -->
<svg style="display: none" aria-hidden="true">
<defs>
<symbol id="icon-circle" viewBox="0 0 20 20"><circle fill="currentColor" cx="10" cy="10" r="10" /></symbol>
<!-- other icons here -->
</defs>
</svg>
<!-- In some other template -->
<button>
<svg class="icon"><use xlink:href="#icon-circle"></use></svg>
<span>foobar</span>
</button>
<!-- in your CSS -->
.icon { width: 1em; height: 1em; }
This approach I feel has most of the advantages of inlined SVG (mostly context-dependent colors) while avoiding most of the clutter, and is not heavily reliant on a specific JS-based workflow (thought we do need to includes our <def> somewhere in all pages)some advanced features of SVG, such as filters, are very much YMMV to this day. But for simple logos and icons there isn't much to worry about.
https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use...
Nice overview here too http://tutorials.jenkov.com/svg/use-element.html
<use xlink:href='icons.svg#foo'/>
Theoretically the browser should only download that file once, just as with multiple img elements referencing the same image. I haven't seen that approach much in the wild, though.You can give my library, svg-loader, [1] a try. It's a single line of javascript that makes it really easy to load external SVGs as inline elements. The syntax is even shorter and you avoid all the problems of external SVGs.
I use Affinity Designer for this. It exports artboards using a trivially detectable pattern, which can be easily turned into symbol elements in a compilation step.
I made a feature request for an option to do this natively, but it never got any traction.
1. At that level, do you really believe anyone will notice?
2. How does the faster rendering even make a dent in the increased load times from which your users will suffer as their browser downloads the whole font with all its glyphs they don’t need?
I prefer to use SVGs (I find animation and styling with them easier) but I agree with the OP of this thread that properly bundled icon fonts aren't that big a deal.
[1] Accessibility for Ontarians with Disabilities Act,
How does that work with people who have "use my fonts" ticked for whatever reason? Is there some kind of override that applies?
Firefox calls it "Allow pages to choose their own fonts, instead of your selections above." Safari lets you use a custom stylesheet to enforce your font choices - Chrome did too but it sounds like they've removed that option. In all 3 cases, I think there's extensions which will also do this for you.
> With the release of Chromium-powered version Microsoft's Edge browser in early 2020, Scalable Vector Graphics (SVG) became fully supported across all major browsers.
These are not good claims. I've tested Internet Explorer 11 (released in 2013) and it supports lots of SVG features already. I agree with the article that we should use SVG icons, but think it should have been done 5+ years earlier.
Speech: use aria-hidden="true"
Stylesheet overrides: External to design & UI intention. Outside of control.
Cannot provide metadata: I can't think of a valid reason why this matters on a character..
> By themselves, these icons don't provide any semantical information about their contents; You cannot label them or describe them directly
Why would you ? Do you add context to individual strings in your content too ? No, you add to the container.
I'm all for other opinions, but demanding is just off-putting from the start.
To add to this point. On normal DPI screens, aliasing often just looks blurry, and the automatic font hinting that's used on most custom fonts is A T R O C I O U S, if you disable anti-aliasing. System default fonts are usually OK and look crisp without aliasing, since they've been expensively manually-hinted, but requiring icon fonts makes it difficult for the user to use them on your site.
I hate aliasing, so I hate all web fonts, not just icon fonts.
On the web, icon fonts seem like the natural parallel since they also "just work" when matching styles with text. To my knowledge, SVGs can't automatically match text size or weight which is a significant weakness, particularly when the user has specified overrides for accessibility reasons. But as the article states, icon fonts are bad because they're nonsense to screen readers.
Is the only way to get an SF Symbols equivalent on the web, then, with SVGs and some JS wizardry?
Edit: examples here [1]
https://css-tricks.com/scale-svg/
Microsoft has a great "Fluent UI" icon pack in SVG: https://github.com/microsoft/fluentui-system-icons/blob/mast...
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/v... https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/p...
How about security?
That's not changing any time soon; even with old IE ripped out of Windows 10 to a large extent, there are still multitudes of kiosks and other custom setups using XP/Vista out there that won't be getting any upgrade.
Security should absolutely be more of a concern but it's not. You're talking about business choices not engineering choices.
I think the plan is for Edge to one day have a way to display pages in IE compatibility mode.
https://caniuse.com/svg https://caniuse.com/svg-img
It seems to me the only browsers not supporting any SVG are ones you'd expect in a computer museum, but not in active use.
The flipside is that one just accept that the users who are not able to upgrade are not your target audience and will use other systems to get their work done.
Don't carry others burdens when they self impose their problems.
Or in healthcare.
Or in industrial systems.
Or in kiosks.
Or in much of the real world beyond social media and "disruptive" industries.A healthcare provider using a browser that's too old to have SVG support is a patient data leak waiting to happen.
Developers almost never get to decide if they want to give up on IE, unless they're doing their own project. It's always the legal, security, and other departments and middle managers that make that decision.
I can imagine the response of a developer at an enterprise saying to the boss, "I'm going to stop supporting 2% of our customers, is that OK with you?"
Depends on whether it's followed by "This will save 20-50% of development and maintenance costs."
[1] https://css-tricks.com/a-complete-guide-to-svg-fallbacks/
https://github.blog/2016-02-22-delivering-octicons-with-svg/
However, that doesn't work with Lynx, because "archive.fo" is so concerned about preserving our intellectual heritage, the way archives do, that it serves a visual CAPTCHA to Lynx users and, presumably, anybody trying to save a copy of their page with wget.†
Here's what the original page looks like in Lynx:
←←←→→→ Twitter Profile
Irigoyen.dev irigoyen.dev
(BUTTON) (BUTTON) Irigoyen.dev irigoyen.dev (BUTTON) about (BUTTON) resume
(BUTTON) projects (BUTTON) talks (BUTTON) philanthropy (BUTTON) contact (BUTTON)
blog
One Moment Please...
© 2021 Michael Irigoyen
[Document has only hidden links. Use the 'l'ist command.]
In this context I think it's terribly amusing that the author has taken it upon himself to lecture us about what's "notoriously bad for accessibility". What's worse: that your screen reader inserts a few "unpronounceables" at the beginning of your essay, or that it says "(BUTTON) (BUTTON) Irigoyen.dev irigoyen.dev (BUTTON) about (BUTTON) resume" and then fails to load your actual article? Except for the all-important copyright notice, of course.At least the endless spinner is rendered in SVG instead of one of those godawful icon fonts.
Way to show us your "passion for user experience", Michael. I'd hate to see what it looks like when you don't care about user experience!
Why do I get a spinner? "RangeError: invalid time zone in DateTimeFormat(): AMERICA/CHICAGO", apparently, on line 1 of the JavaScript. In column 103224. How that results in the whole web page completely failing to load is anybody's guess. God forbid a timestamp on the page should be localized incorrectly. I guess that's just what passion looks like!
I gotta say, when I pioneered AJAX in the year 2000 (along with a number of other people, of course), this was not the fucking Web I was fucking hoping for.
_______
† Actually wget from a different IP address works fine on archive.fo, and it yields an HTML file that Lynx can render successfully, although you have to page down past five pages of base64-encoded SVG data: URLs. Why Lynx elects to show the data: URLs of archive.fo's SVG icons I have no idea. Somebody ask Foteos why it does that, if he isn't drinking himself into a stupor to forget the horror the web has become. I'd ask him myself but http://www.macridesweb.com/fote/ gives me a 403, apparently because I live in the wrong country.
He hasn't worked on Lynx since, uh, the late 90s (I forget the exact year but not long after 96-97.) You'll be wanting the lynx-dev mailing list (lynx-dev@nongnu.org) for questions and feature requests.
This seems like the appropriate solution, especially since those icon codepoints are quite extensive (they include all emoji, for example). Do you have examples of icon fonts that are implemented with this restriction?
Sometimes that's exactly the opposite of what I want. What's next, "Stop using emoji, use SVG instead"?
While generally the platforms have gotten better at aligning on the meanings over time, the same emoji will sometimes have different meanings on different platforms.
This is why Twitter and Discord render custom emojis (using... pngs actually afact) so at least they have the same meaning everywhere.
> Cannot provide metadata
That was never the responsibility of the icon font, it was the responsibility of the thing placing the icon. You can still put ARIA attributes on the element that says “put the icon here”. (And if it’s just an extra class on an existing independently-meaningful element that says “put an icon before it”, then that icon is decorative and shouldn’t be exposed in the accessibility tree anyway.) Also ::before and ::after are not the only way of doing an icon font; you can style normal text nodes if you want to—it’s just not the most common way of doing it.
> Size and Maintainability
This is somewhere between unfair and incorrect. Most or all alternatives will experience the same or similar issues. (This is a common theme—each technology has its own advantages and disadvantages, and the author is pointing out the disadvantages of one that don’t affect another, without considering the tradeoffs made and the similar disadvantages in that other.)
> Degraded Visual Quality
This is nonsense. Size your glyphs correctly and you’ll have no trouble. (Though I will admit user stylesheets can mess with this, but you should expect that they’d be messing with all alternatives in much the same way as well, so I deem the quibble invalid.)
> Difficult to Style/Position
The monochromacy can’t be overcome, but icon fonts aren’t difficult to position, you just need to exercise a modicum of caution. Other techniques require just as much caution, just in different places; e.g. I’m fed up with inline <svg> elements lacking width and height attributes so that they end up filling the viewport when the stylesheets fail to load, rather than being 16×16 or whatever.
> SVGs are straight up vector images. Anti-aliasing methods employed by your browser or operating system have no effect and your icons will be noticeably sharper.
I… what!? I’m going to say it straight, this guy doesn’t understand what he’s talking about.
> Additionally, SVGs are simply the size they are.
This is drivel. They may have an inherent size, but they’re the size the document tells them to be—just like text is the size the document tells it to be. I’d actually say my experience with SVG icon sizing is substantially worse than my experience with icon font sizing, to do with the missing width and height attributes mentioned above, when rendered sans CSS.
> I… what!? I’m going to say it straight, this guy doesn’t understand what he’s talking about.
Perhaps I am misunderstanding too, but I think what GP is saying is that icon fonts render through the font engine and are subject to sub pixel rendering (such as Microsoft ClearType) where an SVG is not. Sub pixel realignment is meant to make text more readable and not to make images more accurate, so I can imagine an SVG would render with less artifacting. What do you think?
Subpixel rendering may have been part of the topic of the “degraded visual quality”, but that’s easily disabled if desired. (Whether you should disable it or not is another question.) And it still sounds like he’s talking about antialiasing rather than subpixel rendering.
Actually, this is now making me think of macOS’s glyph dilation. I suppose icon fonts will be degraded on most macOS devices (unless the user has turned off the misnamed “font smoothing” setting).
Then in this section you’re citing, well, SVG is certainly subject to antialiasing; no sharpness arguments will be won here. Subpixel rendering probably won’t apply (and I say only probably—the browser is at liberty to do subpixel rendering on everything if it wants to, and people have toyed with doing subpixel rendering of more vector graphics than just fonts—in fact, in theory you have less control of this rendering than you do of text, as there’s no CSS property for it, unlike with text), but subpixel rendering is all about making things sharper anyway, so again SVG “loses”, if anything. Remember also that icon fonts are more or less constrained to monochromacy, and that’s where subpixel rendering excels, at increasing the effective resolution in one axis.
Are there any open source SVG icon libraries I can use in any web app I want?
IIRC, there was an aggregator/search engine for SVG icons posted on here a couple of weeks ago also.
Of course, if you only use a few icons from a huge font, thats bad. SVG is probably better for a few icons and fonts better for when you use many. Subsetting for fonts and lazy loading for images help too.
Both are valid solutions. Optimize and test for your use case.
https://stackoverflow.com/questions/12436274/svg-image-in-ja...
I'd like to add one: don't use full icon fonts, use only the icons you need with a tool like icomoon.io => it generates font files with only the icons you choose!
Of course it's a bad idea to use SF Symbols in web pages since the font won't be available on non-Apple devices.
Replaces it with a ton of Javascript, NPM packages, obscure languages, frameworks that will be out of popularity with 6months.
Granted, SVG IS the way to go, but the recommendation above is ridiculous.
I have a web page with the same icons repeated 20+ times, and I my intuition is that it it could be optimized by using a shared reference instead of repeated inlined svg sources in the html documention — which is font-awesome default behavior.
The syntax is like this:
<!-- Define the SVGs. I usually put them in an element with `display:none` --> <svg id='svgID12345'><path d="..."/></svg>
<!-- Use the SVG via `<use xlink>` anywhere you want to see it. --> <svg><use xlink:href='#svgID12345'></svg>
You can reference external SVGs in external files as well. Just use `<use xlink:href="defs.svg#icon-1"></use>`. https://css-tricks.com/svg-use-with-external-reference-take-...
The article still brings up good advice, for whatever it's worth.
Just use an <a> tag! And if you really need to carefully prevent only left clicks to do internal navigation. (I do wish that <a> tags had a better semantic event that could be used to override only "regular navigation")
For example opening external links in a new tab is one such common practice. It is done so that people don't lose the page they were on (which is what the Back button is for) because clients are afraid once the user navigates away from their website they won't know how to return to it. But the back button is one of the most used browser features in the browser [1]. If users wanted to open the link in a new tab the browser has the functionality to let them control that behavior but "some people may not know to M3 click, shift+click, or right click->open in a new tab". So instead it is forced for everyone with no way to opt-out without running a userscript that strips out target="_blank" from all <a> elements.
And <a> elements are just one of the many cases where "We know how the user wants to interact with our site/the internet as a whole" is often and annoyingly wrong.
[1] https://ux.stackexchange.com/questions/36017/is-the-browser-...
See also Linux users distrust of Microsoft.
I've seen a lot of weird antipatterns on the web, but this is my first time seeing this. What's the point of doing this???
Let's go to icon font. All I do is include a font and use it, I can set color and style it.
It's has 99% features that *I* need, I don't need advanced features that SVG offers and I don't like to embed SVG directly into our HTML code or has separate SVG files. Icon font is a great hack to me.