SlideShare a Scribd company logo
HTML/CSS Best
Practices
-Bijay Yadav
HTML Coding Standards
 Indentation
 Validation
 Doctype
 Use of Semantic Elements
 Use Practical ID & Class Values
 Use Lower Case Markup
 Comments
Indentation
 Should always reflect logical structure.
 Use tabs not spaces.
 Increases readability.
Validation
 Debugging Tool.
 Best Practices.
 Shows Professionalism.
Doctype
HTML 5
<!DOCTYPE html>
HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
XHTML 1.0 Strict
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Use of Semantic Elements
 Search Engine Friendly
 Shorter and download fasts
 Accessibility
Use Practical ID & Class Values
 relating to the content itself, not the style of the content
Bad Code
<p class="red">Error! Please try again.</p>
Good Code
<p class="alert">Error! Please try again.</p>
Use Lower Case Markup
 Better Readability.
 Standard
 Common Practise
Comments
 For Programmers
 Helps reduce errors
 For future
<div class=“alert”>
…
</div> <!-- .alert ends -->
<!– Header Section Starts -->
<header id=“header”>
</header>
<!– Header Section Ends -->
CSS Coding Standards
 Structure
 Selectors
 Properties
 Vendor Prefixes
 Values
 Media Queries
 Commenting
Structure
 Use tabs, not spaces for indentation
 two blank lines between sections.
 one blank line between blocks in a section.
 Each selector should be on its own line.
 Property-value pairs should be on their own line.
 The closing brace should be flush left.
Eg.
#selector-1,
#selector-2,
#selector-3 {
background: #fff;
color: #000;
}
Selectors
 Use lowercase and separate words with hyphens when naming selectors.
 Refrain from using over-qualified selectors.
 Attribute selectors should use double quotes around values.
Eg.
#comment-form {
margin: 1em 0;
}
input[type="text"] {
line-height: 1.1;
}
Properties
 Should be followed by a colon and a space.
 Use lowercase, except for font names and vendor-specific properties.
 Use shorthand.
Property Ordering
 Display
 Positioning
 Box model
 Colors and Typography
 Other
Vendor Prefixes
 longest (-webkit-) to shortest (unprefixed)
Eg.
.sample-output {
-webkit-box-shadow: inset 0 0 1px 1px #eee;
-moz-box-shadow: inset 0 0 1px 1px #eee;
box-shadow: inset 0 0 1px 1px #eee;
}
Values
 Space before the value, after the colon.
 Always end in a semicolon.
 Use double quotes rather than single quotes.
 0 values should not have units unless necessary.
 Line height should also be unit-less, unless necessary.
Media Queries
 Keep media queries grouped by media at the bottom of the stylesheet.
 Rule sets for media queries should be indented one level in.
Eg:
@media all and (max-width: 699px) and (min-width: 520px) {
/* Your selectors */
}
Commenting
For sections and subsections:
/**
* #.# Section title
*
* Description of section, whether or not it has media queries, etc.
*/
.selector {
float: left;
}
Commenting
For inline:
/* This is a comment about this selector */
.another-selector {
position: absolute;
top: 0 !important; /* I should explain why this is so !important */
}
Thank You!!!
References:
 http://www.codeproject.com/Tips/666578/HTML-and-Some-CSS-Best-Practice
 http://learn.shayhowe.com/html-css/writing-your-best-code/
 http://sixrevisions.com/web-standards/20-html-best-practices-you-should-follow/
 https://make.wordpress.org/core/handbook/coding-standards/html/
 https://make.wordpress.org/core/handbook/coding-standards/css/

More Related Content

PPTX
WordPress Coding Standards & WP Hooks
PPTX
Ultimate Guide to Advanced Custom Fields
PPTX
Coding conventions
PDF
Strategies For Conditional Content
PDF
Why coding convention ?
PDF
XML and Localization
PDF
CSS Selectors
PPTX
Xml attribute blowup
WordPress Coding Standards & WP Hooks
Ultimate Guide to Advanced Custom Fields
Coding conventions
Strategies For Conditional Content
Why coding convention ?
XML and Localization
CSS Selectors
Xml attribute blowup

Similar to Html css best_practices (20)

ODP
HTML5, CSS, JavaScript Style guide and coding conventions
PDF
Part 2 in depth guide on word-press coding standards for css &amp; js big
PDF
HTML and CSS Coding Standards
PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
PPTX
GDG On Campus NBNSCOE Web Workshop Day 1 : HTML & CSS
PPT
xhtml_css.ppt
PDF
Css coding-style-conventions--standards-guidelines-rules-v1.3
PPTX
Css for Development
PDF
Creative Web 02 - HTML & CSS Basics
PPTX
css-note.pptx
PPTX
How To Write Beautiful Code
PPTX
Cascading Style Sheets for web browser.pptx
PPS
PDF
A complete html and css guidelines for beginners
PDF
Introduction to HTML-CSS-Javascript.pdf
PPT
Make Css easy(part:2) : easy tips for css(part:2)
PPT
IP - Lecture 6, 7 Chapter-3 (3).ppt
PDF
Intro to HTML 5 / CSS 3
PPTX
Html,Css,Js INTERNSHIP REPORT By SELF pptx
PPT
Html & CSS - Best practices 2-hour-workshop
HTML5, CSS, JavaScript Style guide and coding conventions
Part 2 in depth guide on word-press coding standards for css &amp; js big
HTML and CSS Coding Standards
Structuring your CSS for maintainability: rules and guile lines to write CSS
GDG On Campus NBNSCOE Web Workshop Day 1 : HTML & CSS
xhtml_css.ppt
Css coding-style-conventions--standards-guidelines-rules-v1.3
Css for Development
Creative Web 02 - HTML & CSS Basics
css-note.pptx
How To Write Beautiful Code
Cascading Style Sheets for web browser.pptx
A complete html and css guidelines for beginners
Introduction to HTML-CSS-Javascript.pdf
Make Css easy(part:2) : easy tips for css(part:2)
IP - Lecture 6, 7 Chapter-3 (3).ppt
Intro to HTML 5 / CSS 3
Html,Css,Js INTERNSHIP REPORT By SELF pptx
Html & CSS - Best practices 2-hour-workshop
Ad

Recently uploaded (20)

PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PPTX
HPE Aruba-master-icon-library_052722.pptx
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
Urban Design Final Project-Context
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPT
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PPT
UNIT I- Yarn, types, explanation, process
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
DOCX
actividad 20% informatica microsoft project
PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PDF
Urban Design Final Project-Site Analysis
PPTX
Entrepreneur intro, origin, process, method
DOCX
The story of the first moon landing.docx
PPTX
Media And Information Literacy for Grade 12
PPTX
building Planning Overview for step wise design.pptx
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
Fundamental Principles of Visual Graphic Design.pptx
HPE Aruba-master-icon-library_052722.pptx
DOC-20250430-WA0014._20250714_235747_0000.pptx
Quality Control Management for RMG, Level- 4, Certificate
Urban Design Final Project-Context
BRANDBOOK-Presidential Award Scheme-Kenya-2023
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
EGWHermeneuticsffgggggggggggggggggggggggggggggggg.ppt
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
UNIT I- Yarn, types, explanation, process
YOW2022-BNE-MinimalViableArchitecture.pdf
actividad 20% informatica microsoft project
YV PROFILE PROJECTS PROFILE PRES. DESIGN
Urban Design Final Project-Site Analysis
Entrepreneur intro, origin, process, method
The story of the first moon landing.docx
Media And Information Literacy for Grade 12
building Planning Overview for step wise design.pptx
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
Ad

Html css best_practices

  • 2. HTML Coding Standards  Indentation  Validation  Doctype  Use of Semantic Elements  Use Practical ID & Class Values  Use Lower Case Markup  Comments
  • 3. Indentation  Should always reflect logical structure.  Use tabs not spaces.  Increases readability.
  • 4. Validation  Debugging Tool.  Best Practices.  Shows Professionalism.
  • 5. Doctype HTML 5 <!DOCTYPE html> HTML 4.01 Strict <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> XHTML 1.0 Strict <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  • 6. Use of Semantic Elements  Search Engine Friendly  Shorter and download fasts  Accessibility
  • 7. Use Practical ID & Class Values  relating to the content itself, not the style of the content Bad Code <p class="red">Error! Please try again.</p> Good Code <p class="alert">Error! Please try again.</p>
  • 8. Use Lower Case Markup  Better Readability.  Standard  Common Practise
  • 9. Comments  For Programmers  Helps reduce errors  For future <div class=“alert”> … </div> <!-- .alert ends --> <!– Header Section Starts --> <header id=“header”> </header> <!– Header Section Ends -->
  • 10. CSS Coding Standards  Structure  Selectors  Properties  Vendor Prefixes  Values  Media Queries  Commenting
  • 11. Structure  Use tabs, not spaces for indentation  two blank lines between sections.  one blank line between blocks in a section.  Each selector should be on its own line.  Property-value pairs should be on their own line.  The closing brace should be flush left. Eg. #selector-1, #selector-2, #selector-3 { background: #fff; color: #000; }
  • 12. Selectors  Use lowercase and separate words with hyphens when naming selectors.  Refrain from using over-qualified selectors.  Attribute selectors should use double quotes around values. Eg. #comment-form { margin: 1em 0; } input[type="text"] { line-height: 1.1; }
  • 13. Properties  Should be followed by a colon and a space.  Use lowercase, except for font names and vendor-specific properties.  Use shorthand.
  • 14. Property Ordering  Display  Positioning  Box model  Colors and Typography  Other
  • 15. Vendor Prefixes  longest (-webkit-) to shortest (unprefixed) Eg. .sample-output { -webkit-box-shadow: inset 0 0 1px 1px #eee; -moz-box-shadow: inset 0 0 1px 1px #eee; box-shadow: inset 0 0 1px 1px #eee; }
  • 16. Values  Space before the value, after the colon.  Always end in a semicolon.  Use double quotes rather than single quotes.  0 values should not have units unless necessary.  Line height should also be unit-less, unless necessary.
  • 17. Media Queries  Keep media queries grouped by media at the bottom of the stylesheet.  Rule sets for media queries should be indented one level in. Eg: @media all and (max-width: 699px) and (min-width: 520px) { /* Your selectors */ }
  • 18. Commenting For sections and subsections: /** * #.# Section title * * Description of section, whether or not it has media queries, etc. */ .selector { float: left; }
  • 19. Commenting For inline: /* This is a comment about this selector */ .another-selector { position: absolute; top: 0 !important; /* I should explain why this is so !important */ }
  • 20. Thank You!!! References:  http://www.codeproject.com/Tips/666578/HTML-and-Some-CSS-Best-Practice  http://learn.shayhowe.com/html-css/writing-your-best-code/  http://sixrevisions.com/web-standards/20-html-best-practices-you-should-follow/  https://make.wordpress.org/core/handbook/coding-standards/html/  https://make.wordpress.org/core/handbook/coding-standards/css/