Is HTML5 Dirty?

Share this article

Last week, I wrote about Google’s mod_pagespeed. Some of the module’s features brought out some negative reactions in the comments; notably, the fact that mod_pagespeed can be set to remove quotes from around attributes in your markup, and remove unnecessary attributes (such as type="text" on an input element). The commenters noted that they were uncomfortable having the server output invalid markup, or “destroying their good intentions.” Ah, but it’s not invalid! Or at least, it doesn’t need to be. One of the more interesting (and at least a little controversial) aspects of the HTML5 specification is its relaxing of several constraints on the exact syntax of your markup. The idea was to reduce as much of the complexity of an HTML document as possible, while maintaining backwards compatibility. As it turns out, browsers have always supported unquoted attributes, and they’ve always defaulted to an input type of text in the absence of a type attribute (or in the presence of a type attribute they don’t understand; this is why the new input types like "number" or "email" are backwards compatible). As a result, the simplest input attribute that’s fully backwards compatible is:

<input>
This works in every browser, and correctly displays a text input box. This is why the authors of the HTML5 spec went ahead and made that the minimum required by the specification to create that element. Quotes around attribute values are only required if there’s a space in the value; element and attribute names are case-insensitive, and many attributes have a default value that will be assumed if the attribute is absent (this is the case with the type attribute of the input element). That’s the whole idea behind the spartan HTML5 doctype: it was the minimum number of characters required to trigger standards mode in older browsers. Even once you understand that, markup like <INPUT type=text> still looks wrong, doesn’t it? But, as Jeremy Keith argues extremely well in his Fronteers 2010 keynote, that’s a question of coding style, and the specification should be style-agnostic. So, coming back to mod_pagespeed. If it can improve your performance by stripping out a bunch of needless bulk from your code in a way that every browser ever made will be able to parse without problem—then I say let’s do it. The good news is that the HTML5 spec has been built with this in mind, so those of us who care about doing things “the right way” can gain some peace of mind.
note:Want more?
If you want to read more from Louis, subscribe to our weekly tech geek newsletter, Tech Times.

Frequently Asked Questions about HTML5 and Dirty Markup

What is dirty markup in HTML5?

Dirty markup in HTML5 refers to the code that is not well-structured, unoptimized, or contains unnecessary elements. This could be due to a variety of reasons such as lack of proper indentation, use of deprecated tags, inline styles, or excessive use of div tags. Dirty markup can make the code difficult to read, maintain, and can also affect the performance of the website.

How can I clean my HTML5 code?

Cleaning HTML5 code involves removing unnecessary elements, properly indenting the code, and using semantic tags. Tools like HTML Cleaner and DirtyMarkup can help in this process. They automatically format and clean your code, making it more readable and efficient.

Why is it important to clean HTML5 code?

Clean HTML5 code is easier to read, maintain, and debug. It also improves the website’s performance as the browser can render the clean code faster. Moreover, clean code is more accessible and SEO-friendly, which can help in improving the website’s ranking on search engines.

What are some common mistakes that lead to dirty markup?

Some common mistakes that lead to dirty markup include not closing tags, using deprecated tags, excessive use of div tags, inline styles, and lack of proper indentation. These mistakes can make the code difficult to read and maintain.

What are semantic tags in HTML5?

Semantic tags in HTML5 provide information about the type of content they contain. Examples of semantic tags include

,
,
, and
. Using semantic tags can make the code more readable and accessible.

How can I avoid dirty markup in HTML5?

To avoid dirty markup, always use semantic tags, properly indent your code, avoid using deprecated tags, and limit the use of div tags. Also, avoid inline styles and use CSS for styling instead.

Can dirty markup affect my website’s SEO?

Yes, dirty markup can affect your website’s SEO. Search engines prefer clean, well-structured code as it is easier to crawl and index. Dirty markup can make it difficult for search engines to understand the content of your website, which can affect its ranking.

What is the role of a code cleaner tool?

A code cleaner tool helps in formatting and cleaning your HTML5 code. It removes unnecessary elements, properly indents the code, and can also convert your code to use semantic tags. This makes the code more readable, efficient, and SEO-friendly.

Can I clean my HTML5 code manually?

Yes, you can clean your HTML5 code manually. However, it can be a time-consuming process, especially for large codebases. Using a code cleaner tool can make the process faster and more efficient.

What are some best practices for writing clean HTML5 code?

Some best practices for writing clean HTML5 code include using semantic tags, properly indenting your code, avoiding deprecated tags, limiting the use of div tags, and using CSS for styling. Also, regularly review and clean your code to ensure it remains optimized and efficient.

Louis SimoneauLouis Simoneau
View Author

Louis joined SitePoint in 2009 as a technical editor, and has since moved over into a web developer role at Flippa. He enjoys hip-hop, spicy food, and all things geeky.

HTML5 Dev CenterHTML5 Tutorials & Articles
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week