DotNetDaily.net Coding Standards for Web Development This document was downloaded from http://www.dotnetdaily.net/ You are permitted to use and distribute this document for any noncommercial purpose as long as you retain this license & copyrights information. This document is provided on As-Is basis. The author of this document will not be responsible for any kind of loss for you due to any inaccurate information provided in this document.
2 Coding Standards for Web Development Contents 1 HTML Coding Standards... 3 1.1 HTML General Rules... 3 1.2 HTML Markup Formatting... 4 2. CSS Coding Standards... 4 2.1 CSS General Rules... 4 2.2 CSS Formatting... 5
3 Coding Standards for Web Development 1 HTML Coding Standards 1.1 HTML General Rules 1.1.1 Always close your tags; 1.1.2 Keep your tag names lowercase: Good: Bad: <div> <p>lorem lipsum sit dolorem. </p> <DIV> <P>Lorem lipsum sit dolorem. </P> </DIV> 1.1.3 Use H1 H6 tags. For semantic and SEO reasons, try to use heading tags. The hierarchy of them in the page is important too. 1.1.4 Wrap navigation with an unordered list; <ul id="nav"> <li><a href="#">home</a></li> <li><a href="#">about</a></li> <li><a href="#">contact</a></li> </ul> 1.1.5 Always complete the alt attribute of an image; 1.1.6 For naming ID's of HTML tags, use Camel Case and for naming classes use lower case: <ul id="navcontainer" class="nav-container"> <li><a href="#">home</a></li> <li><a href="#">about</a></li> <li><a href="#">contact</a></li> </ul> 1.1.7
4 Coding Standards for Web Development 1.2 HTML Markup Formatting 1.2.1 Place a comment tag at the end of each important HTML container that notifies the end of that specific tag; <div id="loginwrapper"> <form action="" method="post"> <input type="text" name="username" class="loginusername" value="please type your email address"/><br/> <input type="password" name="password" class="loginpassword" value="please type your password"/><br/> <input type="submit" value="" class="login-button" /><br/> </form> <!-- End of #LoginWrapper --> 1.2.2 When you want to add comments inside ASP.NET Web Controls, use this syntax: <%-- ASP.NET syntax for comments --%> 1.2.3 Use one blank line to separate important HTML containers; <div id="page"> <div id="header"> <!-- HTML code --> <div id="content"> <!-- HTML code --> <div id="footer"> <!-- HTML code --> 1.2.4 Use TAB for indentation. Do not use spaces. Recommended TAB size is 4; 2. CSS Coding Standards 2.1 CSS General Rules
5 Coding Standards for Web Development 2.1.1 Use margin: 0px auto; as a CSS attribute for centering a div inside container; 2.1.2 Use.px as measurement unit in design. It s easier to control than.em and all the developers on a project can understand it; 2.1.3 Use CSS reset class, example: *{margin: 0px; padding: 0px}. You can add additional attributes to this class depending on your requirements. 2.1.4 Use structural naming convention instead of a presentational naming convention: Good: <p> Lorem lipsum sit <a href="#" class="article-link">dolorem</a></p> Bad: <p> Lorem lipsum sit <a href="#" class="red-link">dolorem</a></p> 2.1.5 2.2 CSS Formatting CSS: 2.2.1 Use Single-Line formatting. This is the most space and size efficient way to write div.wrapper { margin:0 auto; padding:200px 0 0 0; width:960px; z-index:2 } ul.nav { position:absolute; top:0; left:430px; padding:120px 0 0 0 } ul.nav li { display:inline; margin:0 10px 0 0 } div.column { float:left; margin:0 70px 0 0; padding:0 0 0 70px; width:340p x } div.post-wrapper { bottom center norepeat; margin:0 0 40px 0; padding:0 0 40px 0 } div.wrapper img, div.wrapper a img, div.article_illustration_mini { backgr ound:#d3d4cb; padding:10px; border:1px solid #999 } div.wrapper a:hover img { background:#fff } 2.2.2 Use one blank line to separate logical groups of styling: table thead tr th.left-corner { /* CSS style */ }
6 Coding Standards for Web Development table thead tr th.right-corner { /* CSS style */ } table#addnewuser{ /* CSS style */ } table#addnewuser thead tr th h3{ /* CSS style */ } 2.2.3 Order your CSS properties. For example, if you are styling a <h1> tag, put first the font-related declarations then color-related declarations and finally the position-related declarations: h1 { /* Font */ font-size: 2em; font-weight: bold; /* Color */ color: #c00; background: #fff; /* Box model */ padding: 10px; margin-bottom: 1em; } Comments are optional, so is the formatting. 2.2.4 Order the CSS items in groups. This way you can easily read the contents and jump straight to a particular section. Prepending each heading with a dollar sign makes it unique, so that a search will yield only headings: /* $DEFAULTS ----------------------------------------------------------*/ body { background: #b6b7bc; font-size:.80em; fontfamily: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif; margin: 0px; padding: 0px; color: #696969;} a:link, a:visited{ color: #034af3;} a:hover{ color: #1d60ff; text-decoration: none;} a:active{ color: #034af3;} p{ margin-bottom: 10px; line-height: 1.6em;} /* $HEADINGS ----------------------------------------------------------*/ h1, h2, h3, h4, h5, h6{ font-size: 1.5em; color: #666666; font-variant: smallcaps; text-transform: none; font-weight: 400; margin-bottom: 0px;} h1{ font-size: 1.6em; padding-bottom: 0px; margin-bottom: 0px;} h2{ font-size: 1.5em; font-weight: 600;} h3{ font-size: 1.2em;}
7 Coding Standards for Web Development h4{ font-size: 1.1em;} h5, h6{ font-size: 1em;}