3

I am trying to create a responsive design layout using XML that relies on setting the initial-scale of the user agent. In HTML I would use some variation of the <meta viewport> tag such as this:

<meta name="viewport" content="width=320, initial-scale=1">

however the lack of a closing tag is a problem for XML.

Is there a way for me to do this in valid XML that would also work in browsers?

Startec
  • 12,496
  • 23
  • 93
  • 160

2 Answers2

1

Given this answer (which is specifically about closing the <meta> tag) I think the simplest thing to do here would be to just close the meta element with /> as browsers will not complain.

Community
  • 1
  • 1
Startec
  • 12,496
  • 23
  • 93
  • 160
0

Use the XHTML namespace:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta name="viewport" content="width=320, initial-scale=1"/>
</head>
<body>
    <!-- Insert your content here -->
</body>
</html>

OR:

<html:meta xmlns:html="http://www.w3.org/1999/xhtml" name="viewport" content="width=320, initial-scale=1"/>

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • 2
    For polyglot markup I still add an extra space before the `/>` self closing tags. makes no difference to xml parsers, and really ancient html parsers might get a tad bit happier. –  Oct 29 '15 at 00:20