Web developers are often uncertain about the coding technique and syntax to use in HTML as the HTML version changed from HTML to XHTML and finally HTML5. Although, HTML5 is far more flexible but sloppy in terms of code validation, the code itself is easier to understand. Since it supports bad coding, it is always a smart move to write HTML codes close to XHTML so that you do not need to rewrite the entire code in case new browsers or the newer versions of the existing ones stopped supporting bad coding standards.
Here are a few HTML coding conventions you might want to follow to maintain proper coding stardard.
XHTML stands for EXtensible HyperText Markup Language. It is almost identical to HTML but is stricter in coding standard. XHTML is supported by all major browsers. It is a markup language where documents must be marked up correctly. It was developed by combining the strengths of HTML and XML.
<html> <head> <title>This is bad HTML</title> <body> <h1>Bad HTML <p>This is a paragraph </body>
In HTML, some elements can be improperly nested whereas in XHTML all elements must be properly nested.
// HTML <b><i>This text is bold and italic</b></i> // XHTML <b><i>This text is bold and italic</i></b>
XHTML elements must always be closed while most browsers display them properly in HTML.
// HTML <p>This is a paragraph <p>This is another paragraph // XHTML <p>This is a paragraph</p> <p>This is another paragraph</p>
Empty elements must be closed in XHTML.
HTML <br> <hr> <img> // XHTML <br /> <hr /> <img />
XHTML elements must be in lowercase
// HTML <BODY> <P>This is a paragraph</P> </BODY> //XHTML <body> <p>This is a paragraph</p> </body>
XHTML attribute names must be in lowercase
// HTML <table WIDTH="100%"> // XHTML <table width="100%">
XHTML attribute values must be quoted
// HTML <table width=100%> // XHTML <table width="100%">
XHTML attribute minimization is forbidden
// HTML <input type="checkbox" name="vehicle" value="car" checked /> // XHTML <input type="checkbox" name="vehicle" value="car" checked="checked" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="https://www.w3.org/1999/xhtml"> <head> <title>Title of document</title> </head> <body> some content </body> </html>