Archive for the ‘xhtml’ tag
Writing HTML
Programmers are often required to write HTML code. Recently, on reviewing such code, I found some glaring mistakes. Based on this experience, I have assembled some points which programmers should note when developing HTML.
Version of HTML
Before writing HTML, decide upon version compliance. HTML 4.01 and XHTML 1.0 are popular choices.
Specify Version of HTML as DOCTYPE
For HTML 4.01 it is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
For XHTML 1.0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
For a detailed list, visit: http://webdesign.about.com/od/xhtml/a/aa011507.htm
Don’t use deprecated elements like <font>
<font> has been deprecated since version 4.01 of HTML.
Use CSS for styling
For styling purposes (specifying font, color, background-color, border, etc.) use only CSS. For example, for setting the background of a page, the earlier method is:
<body bgcolor="blue">
This is better written as:
<body style="background: blue;">
Open/Close Elements
Please ensure you open and close the HTML elements in proper order. Always have the discipline of closing open elements.
Indentation
HTML is also source code which is maintained by humans. Please respect yourself and the people who will be maintaining it later: write readable HTML with proper indentation.
Validate HTML
Use a proper validation service before publishing your HTML. You may also use tools like xmllint also to validate your HTML.
Test in target browser
All our development systems are Linux. We developers test our HTMLs in Firefox. But our clients use IE. Situations like these demand additional testing effort in IE.
Feature Request: Script Exclusion in HTML
I am working currently in a portal project. From various datasources we collect information and publish as portlets. The current UI scenario requires us to use JavaScript libraries like prototype.js and jQuery. In both these libraries, $() has different meaning. So when we tie a particular portlet’s UI to prototype.js, and another to jQuery, we cannot effectively place both of them in the same page.
If HTML/XHTML provides some kind of script exclusion so that scripts placed inside a particular scope do not reveal their functions and variables globally across the page, it is going to be helpful. For example:
<script-package name="abc">
<script src="prototype.js" type="text/javascript"/>
<script type="text/javascript">
// use prototype specific code
</script>
</script-package>
<script-package name="xyz">
<script src="jquery.js" type="text/javascript"/>
<script type="text/javascript">
// use jQuery specific code
</script>
</script-package>
In the rare case when a script needs to access some variable defined in different package, it can use some namespace mechanism. Any ideas?