Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the SVG xmlns attribute do?

Tags:

html

xml

svg

I've seen source code for embedded SVGs that look like:

<svg>...</svg>

and others that look like:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">...</svg>

What exactly does specifying the xmlns / xmlns:xlink attributes do?

like image 404
saricden Avatar asked Aug 22 '14 15:08

saricden


2 Answers

In XML documents attributes and elements belong to namespaces. This is to prevent the elements from different technologies from clashing e.g. the SVG <a> element and the HTML <a> element can be distinguished if one is called svg:a and the other html:a

xmlns:xlink says that elements prefixed by xlink should be interpreted using the xlink specification by UAs that understand that specification.

xmlns defines the default namespace so no prefixes are necessary for that and you can just write <a> rather than namespace:a and the UA knows it's an SVG <a> element and not a HTML <a> element or some <a> element you made up yourself for your application.

like image 157
Robert Longson Avatar answered Oct 29 '22 08:10

Robert Longson


The xmlns:XLink is used to create hyperlinks within XML documents

From wiki

XML Linking Language, or XLink, is an XML markup language and W3C specification that provides methods for creating internal and external links within XML documents, and associating metadata with those links

like image 33
Rahul Tripathi Avatar answered Oct 29 '22 08:10

Rahul Tripathi