I’m using html provided by a designer to create a master page.
The html doctype is set to be HTML 4.0 Strict. The meta tags in the html do not have closing end tags (they end with > rather than />) and this html is compliant using the W3 validator tool.
For example:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
However, ASP.NET changes the head attributes before rendering the page and modifies the end tags, as below
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Now the addition of the /> at the end of the tag causes errors in the W3 validator.
How do I prevent this from happening, and ensure the html rendered is as the designers intended?
You can change how ASP.NET renders HTML by forcing it to use a particular XHTML conformance rendering mode. I’m not sure what other side effects changing the renderer may have on the HTML output produced by ASP.NET. This can be set in the web.config with the following.
There are other caveats to using the “Legacy” rendering mode, see the following MSDN resources for other rendering modes and details.
XHTML Standards in Visual Studio and ASP.NET
How to: Configure XHTML Rendering in ASP.NET Web Sites