Meta Tags Inside MasterPage Output On One Line

I like clean code and I'm sure most developers do. I am coming across an issue where my Meta tags are all appearing on ONE line all together and not on separate lines.

I have a file called "client.master" and here is code for the header:

<head runat="server">
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
   <meta name="apple-mobile-web-app-capable" content="yes" />
   <meta name="apple-mobile-web-app-status-bar-style" content="default" />
   <meta name="format-detection" content="telephone=no" />

   <script src="/scripts/script1.min.js" type="text/javascript"></script>
   <script src="/scripts/script2.min.js" type="text/javascript"></script>

   <link rel="apple-touch-icon" href="/images/home-screen.png" />
   <link rel="apple-touch-startup-image" href="/images/home-startup.png" />
   <link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" />
   <link href="/css/design.css" type="text/css" rel="stylesheet" />

   <asp:ContentPlaceHolder ID="headContent" runat="server">
   </asp:ContentPlaceHolder>
</head>

That looks very clean and nice. However, when I view the source of the page, the output shows the <meta> tags and the <link> tags all on one line. The script tags are not.

Here is the output of my code:

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="default" /><meta name="format-detection" content="telephone=no" />

   <script src="/scripts/script1.min.js" type="text/javascript"></script>
   <script src="/scripts/script2.min.js" type="text/javascript"></script>

   <link rel="apple-touch-icon" href="/images/home-screen.png" /><link rel="apple-touch-startup-image" href="/images/home-startup.png" /><link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" /><link href="/css/design.css" type="text/css" rel="stylesheet" />

   <title>
      Login
</title></head>

Notice the <meta> and <link> tags are both on a single line AND the <title> tag has line breaks.

Here is the HTML for the default.aspx page for the Title:

<asp:Content ID="title" runat="server" ContentPlaceHolderID="title">
   Login
</asp:Content>

My assumption is because the <meta> tags and <link> tags are self enclosed and the <script> tags end with </script>.

Is the only way to resolve this issue to close my <meta> tags with </meta>. Which way is to be considered the standard when closing meta and link tags? or script tags?

Thanks in advance for your help!

Answers


If you really want to follow the spec, link and meta are void elements, they can't have a closing tag, if your DOCTYPE is HTML5, you can use the selfclosing tag <meta ..../> but the default way would be to use it only as a start tag, that is a correct conforming use as empty elements don't need an end tag (void ones, as I said, can't have it).

Script is not a void element, but is an empty one, so you can use only the start tag, the self-closing tag or both start and end tags.

Note that for an element to have a content model of type empty really means it may be empty, not that it should; that would probably be what it is called void.

As to why the asp parser does that to your metas, I can't think of a reason. I understand your preference for clean code, but if it is of any help, try to think that at least that bug contributes to a filesize decrease :o)

Bear in mind that all of this applies to HTML5, XHTML treats void and empty models differently.


Need Your Help

GestureRecogniser and disabling drag gesture of a UIView in a UIScrollView

iphone ios xcode xcode4 ios4

Recently I had a problem. How to disable scrolling in a particular area of a UIScrollView, particularly the area occupied by a UIView or subview.

JAVA DOM API Processing inscrution and doctype before XML prolog

java api xslt dom doctype

I am working on DOM API in JAVA, i have a problem, how may i add Precessing Instruction (XSLT Style Sheet) and DOCTYPE (Document type) after XML Prolog

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.