SVG: The Good, the Bad, and the Ugly (2021)
eisfunke.com
eisfunke.com
I generally agree with the article, SVG is bloated and confused about what it's trying to do.
You're not alone in wanting something better. We had this same problem in Flutter. Ian Hickson (of HTML5 fame) made some attempts at seeing a better future you might be interested in: https://docs.google.com/document/d/1YWffrlc6ZqRwfIiR1qwp1AOk...
What did disappoint me when reading the doc was the decision to place accessibility at the bottom of the list of priorities for the proposed format. There's a footnote that says "Accessibility being low on this list reflects that the needs can be met outside the format as well, and supporting them inside the format would be beneficial only to the extent that it provides greater flexibility to designers", but to me that seemed back-to-front: why not tell the engine/device that will display the image the (preferred) requirements for accessibly rendering (or describing) that image by including such data in the format, rather than hoping that the engine/device will make "best efforts" to support people with accessible needs in some unknowable way?
[1] Text section in doc - https://docs.google.com/document/d/1YWffrlc6ZqRwfIiR1qwp1AOk...
I see JSON these days for everything including, for instance, savefiles for documents; templates in Azure, etc etc
I wonder if I will honestly, un-ironically, use XML in my next project for something where JSON could have done the job.
JSON is missing these small things make it very annoying (mainly comments, comma at end of last element not allowed, and the crappy ambiguities standard vs implementations about numbers, autoformatting of pretty printed JSON not standardized). Also not very readable as config format.
And YAML is human editing friendly but so horrible in other ways ( [US, GB, SE, DK, NO, ...])
I am sure there are lots of small competitors. But XML is already there, so well supported everywhere.
However, there are features of XML that are very useful for a document format like SVG. One of them is namespaces. For example, you can create an SVG and add custom metadata in another namespace, and then any viewer who uses a decent XML parser will show it without issues. That’s not possible with JSON, as there is no guarantee that an unknown key will pass. (although I prefer a simple format like JSON or TOML for config files)
We just need browsers to implement SVG 2.0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
or: <?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
It's not only verbose and extremely ugly but also impossible to remember.svg header is simply:
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
Maybe read the manual once per decade ? Its like saying JS does not have support for lambdas.For what it's worth, I do agree that the syntax may be a tad strange. But I feel that, as with many of these issues, this is a tooling issue. Now, whether or not tooling will be made or not, for these kinds of problems, is unrelated.
As an aside, I rarely remember the HTML header tag; but that's fine, I have tooling that does it for me.
array:
- string one
- string two
or like this: array:
- string one
- string two
I've found that the easiest way for me to edit YAML (when I have to, which is pretty much exclusively when dealing with CI stuff) is to write it in one of those YAML -> JSON converters online.SVG often appears embedded in HTML so it makes sense to have it use similar angle-brackets syntax. Unless they also want to recast HTML in JSON (which I’m sure someone have proposed).
SVG: The Good, the Bad and the Ugly - https://news.ycombinator.com/item?id=26114863 - Feb 2021 (219 comments)
There are also filters, pattern fills, dashed strokes, etc. Also, mesh gradients (as supported by Inkscape) are immensely powerful but not yet standardized.
A lot of people are surprised to find <script> in SVGs and maybe that's a bad idea, but everything that someone thought was pure unnecessary bloat are actually features that users depend on. Maybe there is a cleaner and purer universal standard that covers everyone's use cases, but users already have SVG and would rather see incremental improvements here, as opposed to waiting for a new thing that is less capable.
I ginned up some pretty inelegant stuff to rotate text 90 degrees[0] because I got tired of trying to figure out if there was a sane, blessed approach that I could generate with whatever Python library I was using.
Ditto right justifying text. I just ended up fudging it [1]. Like, this is a pretty basic functionality if you're mixing text into your graphics. And I'm pretty willing to go down a rabbit hole if I can find one. I realize that doing this requires knowing the size of the text as rendered or doing something funny like rendering LtR text RtL reversed (which wouldn't work for centered?), but this is something that seems reasonable to expect a straightforward solution to.
[0] https://github.com/longwalkwoodworking/cutlist/blob/a7c96028...
[1] https://github.com/longwalkwoodworking/cutlist/blob/a7c96028...
[1] https://developer.mozilla.org/en-US/docs/Web/SVG/Element/for...
Not very elegant, but it saved me time to work on the thing I actually wanted to work on. Not sure if this sort of approach would be applicable for your cut lists.
That being said, SVG allows you to create quite beautiful and complex effects with relatively little code.
Well if you just do the generic version uncritically, you end up with all sorts of security vulnerabilities. Things like xml external entities, xinclude have causes quite a few security issues over the years when processing svgs.
After some quick experiments, I found that SVG is a total non starter compared to PNG and JPEG. At image counts in the tens, you can't tell the difference. If you are rendering a 20x30 grid of 600 images, SVG can take seconds, whereas the raster formats can redraw at monitor refresh rate.
My process now is to treat the SVGs as art source code and to raster them into various formats as required at design time.
I am a little bit disappointed by this outcome, as I was hoping for "infinite resolution" game art that would accommodate the varying zoom levels automagically. I will now be working with pre rastered tile sets for discrete zoom thresholds. I was expecting SVG to be slower, but not that much slower.
A few responses:
1. The spec is too long/complicated: Yeah that's cause graphics is inherently complicated. You can't simplify out the core of the thing you're trying to do. Sure "shapes" are simple, but anything that would be actually useful involves paths (interpolation modes), transforms, groups, blend modes, effects, gradients, masks, stamps, FONTS (don't get me started on fonts!) typography, and on and on. And that's just stationary 2d graphics! Add animations in there and it's a whole other deal. Strip it all out and yes, your spec is shorter. But then you need like 20 different file formats! One for each sub-domain. And good luck trying to make them all work with each other.
The fact that it interoperates with CSS/JS _is a huge plus!_. You can have SVG without these things if you really wanted to, but the fact that they interplay with each other is a testament to good language design on everyone's part here.
Also: The Postscript spec is 920 pages, and the PDF spec from 2008 is 750 pages. Graphics are hard!
2. SVG is verbose because it's XML: XML is pretty compact honestly, especially in SVGs.
Consider:
<rect width="200" height="100" x="10" y="10" />
vs. { "type": "rect", "width": 200, "height": 100, "x": 10", "y": 10 }
And that's me following best practices to have `"` around the values in the XML! It could be even more compact. It's only more verbose I guess when you have closing tags which in SVGs is mostly for the `<g>` element which is literally only one letter :PSo...
<g>
<rect width="200" height="100" x="10" y="10" />
</g>
vs {
"type": "g",
"children": [
{ "type": "rect", "width": 200, "height": 100, "x": 10", "y": 10 }
]
}
XML is really not significantly verbose for uses like this, and the auto-closing `/>` makes it even more compact. And at the end of the day even if it were more verbose, it's not sufficiently more verbose for me to super care.3. Who is SVG for?
It's for both humans and computers and strikes a compromise between the needs of the two. Computers: built in a hugely well-supported language like XML makes it super easy to parse/process computationally. If you wanted to build a renderer that supports just a subset of SVG, that would be a < 1 day task. The more you want to support, the more it would take.
And it's human readable -- or at least as human readable as any textual representation of 2D graphics can be. And that's another piece of inherent complexity here: representing 2D graphics in (effectively 1D) text is _always_ going to be hard to "read", if by "read" we mean understand what it's supposed to be displaying. No text format will be able to get around that.
TLDR: The flaws listed here with SVG are either mostly preference/minutia or complexity inherent to the problem-space itself (2D graphics in a 1D format) that aren't likely overcomeable. Don't get me wrong there are definitely flaws with SVG! But I don't think these are it.
This isn't an issue if you use S expressions, simply because S expressions get rid of the concept of properties. But at that point, you end up with a rectangle with a sub-node called "width", which feels weird as well: the width of a rectangle is clearly a property of the rectangle, not a "child" of it? I'd argue that using S-expressions where each rect node must have x/y/width/height children is just a poor attempt at adding back properties to a syntax which doesn't natively support it.
I even like XML as a user of my work’s external vendor’s configs. I edit subsections more than I write it. It is well documented, errors are easy to spot, and the file is git-able. I would honestly hate to see what that company would come up with in JSON or YAML configs so in this case XML is a great fit.
Are you implying those are optional? They aren't. You can choose between " and ' but you need one of them. You might be confusing HTML rules with XML here? HTML is not XML. (That was XHTML, which failed…)
Do you have any of your old projects public to share? I love creative UI stuff!
> This problem of SVG is actually just the problem of the web in general. It’s scope is huge, it’s bloated and hard to work with.
> SVG is nothing you could implement in a day. Or a week. Or a month. The huge amount of specifications, that are most often only partly implemented, makes it very hard to overview what supports what, confusing the user as to what features they can actually use if they want their SVG file to be universally supported
That just doesn't seem like a big problem, in fact. The webs gotten pretty good & the standard is pretty high. Yes people have some real pains but also my word, software is a world of contrived griefs, nonsense beefs. People love grandstanding against things.
the problem I have is that SVG is complicated like the old web, but unlike the new web we also haven't created new standards like Flexbox and Grid that let you ignore the problems with the old ones.
For example, in HTML-land we have had z-index for a while to describe the order in which elements should render on top of each other. This doesn't exist in SVG, so the order of elements is the order that they are declared in markup, which can lead to very kludgy things.
In SVG land, there is no way to orient around a multiline text box's corners, you can only align the baseline of the first line of text. In fact, there is no way to set a width on a box and have text wrap to the next line when it hits said width. Etc., etc.
These are all things solved in SVG1.2, but of course the classic issue is that barely anyone has bothered implementing SVG1.2.
You can use <foreignElement> and just include HTML text with all CSS text layout capabilities to achieve that. It won't work in Illustrator or Figma, but it's fine for the web. I honestly am somewhat okay with that, let HTML+CSS handle what it's already best at instead of duplicating functionality into SVG.
The z-index is somewhat annoying for accessibility though, because the DOM order also determines the accessibility tree order, so it's not always possible to reorder the DOM to re-arrange the z-order without breaking screen reader order.
but it makes writing design programs that output svg, annoying. the need for a `textarea` element is so great it's already in what was supposed to be the next generation of the spec; and pretty much all SVG output software has a way to input text boxes to treat them like that. But I suspect the complexity of dealing with svg is why alternatives to the Adobe Suite have only become more numerous recently; it's a complex beast.
to me, .ai and .svg are the equivalents to .doc and .docx, but we don't really have a great alternative a la Markdown that is significantly easier to output.
Or to have a rectangle scale to the width of the text inside it.
I have been told by a member of the standardization committee that you are supposed to use Javascript for this kind of thing.
From an early (2022) post:
https://awesomekling.github.io/Ladybird-a-new-cross-platform...
> Q: Why bother? You can’t make a new browser engine without billions of dollars and hundreds of staff.
> Sure you can. Don’t listen to armchair defeatists who never worked on a browser.
...fast-forward to this month:
https://awesomekling.substack.com/p/forking-ladybird-and-ste...
> Since then, SerenityOS has grown into a large OSS community with over one thousand contributors all over the world.
> Personally, for the past two years, I've been almost entirely focused on Ladybird
Expecting to build a world class software platform for less than, oh, I don't know, maybe $25m invested in a good capable engineering team seems silly. What does the web take to redo? More? $100m? Maybe, but I expect significantly less.
Folks use this as such a scare tactic: oh, it's be so hard to do! There's some incidental complexity sure but it's not the bulk of the design, and most of the core & a huge amount of the capabilities are purposeful and solid in nature. Folks also try to work people up about performance: oh, it's so big and bulky. But there's plenty of data heavy very fast sites doing enormous things out there, for quite reasonable footprint, and we're only just getting into the webworker & wasm age where we can start using the existing platform much better. The web's stance continues to improve drastically, and that's not just by being harder to implement, it's by ever refining & improving. It's not gloom I see as we iterate: it's strengths adding together & reinforcing.
Last it just seems so hideously developer-centrix to imagine doing anything else. Nothing else has any legs to stand on for giving users agency. SVG, HTML, and CSS are completely unique in software development in that they leave the door open, are alive computing systems that users can modify & extend with the browsers and plugins that they want. There's no proposals remotely on the table anywhere to any degree that do 1/1000th as much for the user, to respect them & maintain their agency.
So, I don't think the web's scope is a problem. I think it's very doable to build your own world's best platform, for a pretty reasonable sum, if you can put together a small or medium business to do so. That's an ok bar. We can cobble together demoscene grade cool flashy things for less, sure, and that scratches a nerd itch. And maybe some of those will be good high and low level platforms both, be really good maybe even enduring particular ways of doing software. But will they be able to be adapted by users? But will they get it right & never change & never bloat themselves? But will perhaps they too need to evolve & change over time, allow for different styles? The Extensible Web Manifesto ideas have allowed the web to be an enduring low level platform across great architectural explorations & expressions, while still maintaining greatly similar base truths; that empowers developers to find & speak their own truths, while keeping an incredibly capable deepening hyper-multi-media lingua franca that right now the whole world speaks. The web is amazing and building a new browser is a bargain, especially given how excellent the ready-made test suites are.
But no, most engineers won't be able to diy one in their garage; that doesn't mean it's too big & it's ridiculous to insist on. Programming languages/llvm, kernels, none of these are simple or things folks could do de-novo, cheaply, with the needed breadth scope. The popular versions of all of these have had enormous effort poured in. But for some reason we've invented and applied a bar, saying sorry, the web and the web alone has to be doable as a hobby project. It's ridiculous to insist the platforms for the world should necessarily be primitive works. The web keeps winning precisely because it has generous platform for all.
Where the Web is heading, very soon it's end users won't be well served with Google being the only one willing and capable of footing the bill for it.
We need a re-do. A lean, clean SVG might be the ticket.
It is a big problem when the only ones who can write browsers that will work on all the sites people care about are Big Tech.