That post seems to be missing.
cypherpunks 181 points a year ago

No, SVG files are not HTML.

Please change this post title (currently "today i learned: svg files are literally just html code"), to avoid spreading this incorrect factoid!

I suggest you change it to "today i learned: svg files are just text in an html-like language" or something like that. edit: thanks OP

SVG is a dialect of XML.

XML and HTML have many similarities, because they both are descendants of SGML. But, as others have noted in this thread, HTML is also not XML. (Except for when it's XHTML...)

Like HTML, SVG also can use CSS, and, in some environments (eg, in browsers, but not in Inkscape) also JavaScript. But, the styles you can specify with CSS in SVG are quite different than those you can specify with CSS in HTML.

Lastly, you can embed SVG in HTML and it will work in (modern) browsers. You cannot embed HTML in SVG, however.

path: 0 15902684, hotness: undefined, score: 181, children: 7
adrianhooves 21 points a year ago
path: 0 15902684 15910676, hotness: undefined, score: 21, children: 0
BigMikeInAustin 8 points a year ago

You know how they say that the internet is a series of tubes? We used to think that was just a funny old man. Turns out, it is the literal truth. The internet is made up of SVG files!

path: 0 15902684 15917210, hotness: undefined, score: 8, children: 0
zarkanian 8 points a year ago

I remember when XHTML was supposed to replace HTML. Everything was going to be standardized and web designers would run their HTML code against a validator...it was going to be glorious! And of course it never happened, because demanding that all websites conform to the XHTML standard would've broken a lot of websites.

So, HTML5 ate XHTML's lunch because it was much more forgiving, and...oh yeah, you could watch videos and play games in it, too.

path: 0 15902684 15928614, hotness: undefined, score: 8, children: 4
Agent641 6 points a year ago

I fucking learned a whole-ass language for nothing back then because I thought it was the future!, fuck you, XHTML!

path: 0 15902684 15928614 15928787, hotness: undefined, score: 6, children: 2
zarkanian 3 points a year ago

100% of XHTML will work in HTML5.

path: 0 15902684 15928614 15928787 15952222, hotness: undefined, score: 3, children: 0
alphadont 1 point a year ago

As someone who can find a billion XML parser libraries and, like, three HTML parser libraries, you do have my gratitude if it's worth anything.

path: 0 15902684 15928614 15928787 16002104, hotness: undefined, score: 1, children: 0
alphadont 2 points a year ago

Killing Flash was worth it, but couldn't we have avoided its reign of tyranny if we'd just stuck with Java applets in the first place...?

path: 0 15902684 15928614 16002121, hotness: undefined, score: 2, children: 0
AbouBenAdhem 77 points a year ago

More precisely, both are flavors of XML.

path: 0 15894685, hotness: undefined, score: 77, children: 12
atzanteol 45 points a year ago

technically HTML is not XML.. XHTML is, but HTML can be invalid XML.

path: 0 15894685 15895859, hotness: undefined, score: 45, children: 3
AbouBenAdhem 13 points a year ago

Ok—to the extent that SVG is HTML, the variant of HTML that it is is a flavor of XML.

path: 0 15894685 15895859 15896208, hotness: undefined, score: 13, children: 0
Giloron 3 points a year ago

It annoys me that you aren't supposed to close input tags. At least browsers tolerate self closing them even if it is out of spec.

path: 0 15894685 15895859 15914078, hotness: undefined, score: 3, children: 1
neclimdul 1 point a year ago

Technically it's not browser tolerance but spec tolerance. It's built into the html5 spec to tolerate different tags closing and other things invalid in xml.

This was an important design that grew out of one of the largest failings of xhtml that such failures would make the entire page unrenderable.

path: 0 15894685 15895859 15914078 16029871, hotness: undefined, score: 1, children: 0
SatyrSack 18 points a year ago

HTML predates XML by several years.

path: 0 15894685 15895291, hotness: undefined, score: 18, children: 6
atzanteol 15 points a year ago

Age doesn't matter. XML is a super-set of XHTML's spec.

That is - all XHTML is valid XML but not all XML is valid XHTML.

Note I'm saying XHTML not HTML since the later need not be valid XML.

path: 0 15894685 15895291 15895948, hotness: undefined, score: 15, children: 4
chtk 9 points a year ago

XML is a super-set of XHTML's spec.

That's a weird way of saying XHTML is an application of XML.

path: 0 15894685 15895291 15895948 15898281, hotness: undefined, score: 9, children: 1
atzanteol 1 point a year ago

You can phrase it however you like?

?

path: 0 15894685 15895291 15895948 15898281 15910524, hotness: undefined, score: 1, children: 0
floo -13 points a year ago
path: 0 15894685 15895291 15895948 15896062, hotness: undefined, score: -13, children: 1
atzanteol 1 point a year ago

No what?

path: 0 15894685 15895291 15895948 15896062 15910540, hotness: undefined, score: 1, children: 0
db2 3 points a year ago

HTML5 is XML that inherited the lingo.

path: 0 15894685 15895291 15895711, hotness: undefined, score: 3, children: 0
NeoNachtwaechter 9 points a year ago

...which is derived from SGML.

path: 0 15894685 15895068, hotness: undefined, score: 9, children: 0
mina86 31 points a year ago
path: 0 15896430, hotness: undefined, score: 31, children: 6
adrianhooves 10 points a year ago
path: 0 15896430 15896770, hotness: undefined, score: 10, children: 5
phr 15 points a year ago

litghter, as in smaller, yess. but keep in mind, that vector graphics need to be rendered, wich depending on circumstance and graphic might become inefficient.

i never crunched the numbers, but basically youre outsourcing the generation of a rastergraphic to those who open up your website.

path: 0 15896430 15896770 15898128, hotness: undefined, score: 15, children: 2
FooBarrington 6 points a year ago

Though this also has advantages - not only will they be drawn at an appropriate resolution, they can also be styled & modified by the user. If I'm using Dark Reader and your icons are SVGs using currentColor, they'll render with the same color as other text. The best you can do for raster graphics is inverting them.

path: 0 15896430 15896770 15898128 15910347, hotness: undefined, score: 6, children: 1
phr 3 points a year ago

i too love the svg. rest assured. ;)

path: 0 15896430 15896770 15898128 15910347 15915128, hotness: undefined, score: 3, children: 0
mina86 10 points a year ago
path: 0 15896430 15896770 15896898, hotness: undefined, score: 10, children: 0
kotg 4 points a year ago

One should always optimize assets for the web, this includes svg as well.

For critical paths I use https://optimize.svgomg.net/ a svg file optimizer. Svgs that are coming directly from illustrator or sketch are getting better these days but this little tool is invaluable regardless.

I think you can run this local too

path: 0 15896430 15896770 15901884, hotness: undefined, score: 4, children: 0
JRaccoon 23 points a year ago

They can include runnable JavaScript too, which can cause vulnerabilities in certain contexts. One example from work some years back: We had a web app where users could upload files, and certain users could view files uploaded by others. They had the option to download the file or, if it was a file type that the browser could display (like an image or a PDF), the site would display it directly on the page.

To prevent any XSS (scripts from user-provided files), we served all files with the CSP sandbox header, which prevents any scripts from running. However, at the time, that header broke some features of the video player on certain browsers (I think in Safari, at least), so we had to serve some file types without the header. Mistakenly, we also included image files in the exclusion, as everyone through image files couldn't contain scripts. But the MIME type for SVG files is image/svg+xml... It was very embarrassing to have such a simple XSS vuln flagged in a security audit.

path: 0 15898792, hotness: undefined, score: 23, children: 0
perishthethought 23 points a year ago path: 0 15906946, hotness: undefined, score: 23, children: 0
gomp 15 points a year ago

Ommigod, these kids :)

SVG comes XML (a more coherent/simple version of the SGML that is behind HTML), and specifically from a time where people took XML and made it hyper-complicated with a flurry of extensions and specifications (look up "xml namespaces" "xslt" "xml schema").

The most apparent difference between SGML and XML is than in the former you write tags like <br> without a corresponding </br>, and in the latter you have to close them like <br/> (which is shorthand for <br></br>).

So... today you learned that what you learned earlier today was close to truth, but not true :)

PS: A lot of document formats are undercover/zipped XML (eg. the libre office documents, IIRC microsoft's .xlsx and .docx). This is not dissimilar to how json/yaml are widely used today.

path: 0 15904912, hotness: undefined, score: 15, children: 3
milicent_bystandr 1 point a year ago

So, my Lemmy app - and I think a lot of Lemmy, renders markdown, so whenever you write "<...>" It disappears for me!

path: 0 15904912 15926547, hotness: undefined, score: 1, children: 2
gomp 2 points a year ago

I tried adding backslashes to escape, it still looks fine on lemmy.ml but your app may be bugged (and possibly vulnerable to xss? can you see the script block after the closed bracket?)

path: 0 15904912 15926547 15981013, hotness: undefined, score: 2, children: 1
milicent_bystandr 1 point a year ago

It all looks good now :-)

path: 0 15904912 15926547 15981013 15996950, hotness: undefined, score: 1, children: 0
MonkderVierte 11 points a year ago

No, it's XML. It's an ancestor of HTML and, unlike HTML, it can be losslessly converted.

path: 0 15907075, hotness: undefined, score: 11, children: 2
JubilantJaguar 8 points a year ago

Not quite. XML came several years after HTML! Both are descendants of SGML.

path: 0 15907075 15921141, hotness: undefined, score: 8, children: 1
MonkderVierte 1 point a year ago

Oh, ok.

path: 0 15907075 15921141 15944077, hotness: undefined, score: 1, children: 0
utopiah 8 points a year ago

main difference between raster graphics and vector graphics was the quality

It's not. The primitives, the most basic constitutive building blocks, are different, for raster it's the pixel (a mix of colors, e.g. red/green/blue) whereas for vector it's the ... vector (a relative position elements, e.g. line, circle, rectangle or text start with).

This is a fundamental distinction on how you interact with the content. For raster you basically paint over pixels, changing the values of pixels, whereas for vector you change values of elements and add/remove elements. Both can be lossless though (vector always is) as for raster can have no compression or lossless compression. That being said raster does have a grid size (i.e. how many pixels are stored, e.g. 800x600) whereas vector does not, letting you zoom infinitely and see no aliasing on straight lines.

Anyway yes it's fascinating. In fact you can even modify SVG straight from the browser, no image editor or text editor needed, thanks to your browser inspector (easy to change the color of a rectangle for example) or even the console itself then via JavaScript and contentDocument you can change a lot more programmatically (e.g. change the color of all rectangles).

It's a lot of fun to tinker with!

path: 0 15898729, hotness: undefined, score: 8, children: 2
SomeoneSomewhere 4 points a year ago

I'm not sure that lossy compression on vectors is strictly impossible.

You can do things like store less colour information and simplify splines so that curves are less complex.

path: 0 15898729 15901027, hotness: undefined, score: 4, children: 1
utopiah 2 points a year ago

True, in fact I've done so myself (simplifying a curve resulting of hand sketching). Still I'd argue that's not the expected behavior of storing the vector file but rather explicitly modifying it.

path: 0 15898729 15901027 15907491, hotness: undefined, score: 2, children: 0
A_norny_mousse 7 points a year ago

we could modify the desktop environment and make it waaaaay lighter by getting rid of jpg or png icons and just using pure svg on it

That's already happening.

You can also change the main color of many SVGs (icons or even desktop backgrounds) with one simple edit, one command, one click.

In web sites, you can assign CSS classes to SVG graphics and thus e.g. change their color according to a theme.

That's my extent of fiddling with it.

IIRC they also use fonts the same way CSS/HTML does.

BTW, there are situations where an SVG is significantly larger than a corresponding raster image. It depends on the content.

path: 0 15899775, hotness: undefined, score: 7, children: 0
BCsven 7 points a year ago

I don't think it would be lighter, SVGs need a rendering tool to read the code and draw the artwork for the vector based images. This has always been slower than just displaying a bmp, jpg, or PNG.

path: 0 15914259, hotness: undefined, score: 7, children: 0
StorageB 6 points a year ago

for example, on a linux distro, we could modify the desktop environment and make it waaaaay lighter by getting rid of jpg or png icons and just using pure svg on it.

Isn't that how it already works? GNOME system icons are all SVG - that's what allows them to change colors when you change themes or switch between light and dark mode.

path: 0 15910449, hotness: undefined, score: 6, children: 2
BCsven 5 points a year ago

There are both, PNG as standard sizes and the SVGs. I believe the DE pulls the 32 48 256 pixel pngs so no addition rendering is needed.

path: 0 15910449 15914129, hotness: undefined, score: 5, children: 0
adrianhooves 2 points a year ago
path: 0 15910449 15910619, hotness: undefined, score: 2, children: 0
cypherpunks 6 points a year ago

for example, on a linux distro, we could modify the desktop environment and make it waaaaay lighter by getting rid of jpg or png icons and just using pure svg on it.

this has largely happened; if you're on a dpkg-based distro try running this command:

dpkg -S svg | grep svg$ | sort

...and you'll see that your distro includes thousands of SVG files :)

explanation of that pipeline:
  • dpkg -S svg - this searches for files installed by the package manager which contain "svg" in their path
  • grep svg$ - this filters the output to only show paths which end with svg; that is, the actual svg files. the argument to grep is a regular expression, where $ means "end of line". you can invert the match (to see the paths dpkg -S svg found which only contain "svg" in the middle of the path) by writing grep -v svg$ instead.
  • the sort command does what it says on the tin, and makes the output easier to read

you can run man dpkg, man grep, and man sort to read more about each of these commands.

path: 0 15904323, hotness: undefined, score: 6, children: 2
MonkderVierte 2 points a year ago

Is this the same as pacman -Ql?

Edit: the dpkg part is.

path: 0 15904323 15908239, hotness: undefined, score: 2, children: 0
kionite231 1 point a year ago

for alpine linux users:

apk info -L $(apk info) | grep -v contains | grep 'svg'
path: 0 15904323 15905257, hotness: undefined, score: 1, children: 0
weirdboy 4 points a year ago

Postscript is also literally just a text based programming language for drawing stuff. You can create loops and recursions and all kinds of crazy transformations with a few lines of code.

path: 0 15900096, hotness: undefined, score: 4, children: 0
tasankovasara 3 points a year ago

I made an interactive map: drew in Inkscape, gave the interactive elements numbers for ids, then substituted the id='xxx' in vim with the php code and js function calls, picking up the number from the id tag and inserting it appropriately in php code and function arguments. 250 interactive elements taken care of in a single vim substitute. My bestest development power move yet :D

path: 0 15902789, hotness: undefined, score: 3, children: 0
AnimalsDream 2 points a year ago

Hold on now. If an svg will render as valid html in browsers, does that mean I can use Inkscape as a wysiwyg webpage editor, and just export that to html?

path: 0 15954373, hotness: undefined, score: 2, children: 1
adrianhooves 2 points a year ago
path: 0 15954373 15954438, hotness: undefined, score: 2, children: 0
daggermoon 1 point a year ago

Damn, I actually did not know that. I thought it was just an image file.

path: 0 15897983, hotness: undefined, score: 1, children: 3
executivechimp 3 points a year ago

It's both of those things

path: 0 15897983 15898577, hotness: undefined, score: 3, children: 2
N0x0n 2 points a year ago

Schrödinger's SVG?

path: 0 15897983 15898577 15902286, hotness: undefined, score: 2, children: 1
executivechimp 2 points a year ago

Yeah, it depends on if you view source

path: 0 15897983 15898577 15902286 15902497, hotness: undefined, score: 2, children: 0

thanks for using Leebra!

go to feed...