HTML5, CSS, JavaScript Style guide and coding conventions

Knoldus Inc.
Knoldus Inc.CTO & Co-Founder at Knoldus Software em Knoldus Inc.
HTML5, CSS, JavaScript
Style guide and coding conventions
HTML5, CSS, JavaScript
Style guide and coding conventions
Priyanka Wadhwa
Software Consultant
Knoldus Software LLP
Priyanka Wadhwa
Software Consultant
Knoldus Software LLP
Agenda
● Why we need coding Standards?
● HTML5 coding conventions
● CSS style guide
● JavaScript Coding standards
● Why we need coding Standards?
● HTML5 coding conventions
● CSS style guide
● JavaScript Coding standards
What is a need for coding standards ?
Problem
When we learn a new language, we begin to code in a specific style. A style we want and
not the one that has been suggested to us.
Now what?
➢ Can the other person actually read your code? Is it spaced out clearly?
➢ Will he be able to work out what’s happening without needing to look at every line?
➢ Will he be able to know how and why are you commenting the work?
➢ And many more questions may arise…
HTML5, CSS, JavaScript Style guide and coding conventions
Need for coding standards
Solution
Coding conventions are style guidelines for programming.
A coding standards document tells developers how they should write their code. Instead of
each developer coding in their own preferred style, they should write all code to the
standards outlined in the document.
Large projects need to be coded in a consistent style – Not just to make the code easier to
understand, but also to ensure that any developer who looks at the code will know what
naming conventions say and what should he expect from the entire application.
HTML5 coding conventions
HTML5 coding conventions
● HTML5 doctype
Enforce standards mode and more consistent rendering in every browser possible with this simple doctype at
the beginning of every HTML page.
<!DOCTYPE html>
<html>
<head>
</head>
</html>
● Language Attribute
A lang attribute is required to be specified on the root html element, giving the document's language.
<html lang=”en-us”>
<!→-→-->
</html>
● Character encoding
Ensure proper rendering of your content by declaring an explicit character encoding.
<head>
<meta charset=”UTF-8”>
</head>
● Internet Explorer compatibility mode
Internet Explorer supports the use of a document compatibility <meta> tag to specify what version of
IE the page should be rendered as.
<meta http-equiv=”X-UA-Compatibile” content=”IE=Edge”>
● CSS and JavaScript includes
<link rel='stylesheet' href='guide.css'>
<style>/* …… */</style>
HTML5 Coding conventions
● Attribute order
As per the standards, we are required to follow the following order of HTML attributes -
➢ class
➢ id, name
➢ data-*
➢ src, for, type, href, value
➢ title, alt
➢ role, aria-*
<a class=”….” id=”…..” data-toggle=”model” href=”#”>
Example link
</a>
<img src=”...” alt=”...”/>
HTML5 Coding conventions
● Boolean attributes
Requires no declaration.
<input type=”text” disabled>
<input type=”checkbox” value=”1” checked>
<select>
<option value=”1” selected>1</option>
</select>
● Reducing markup
Produce less HTML, avoid superfluous parent elements when writing HTML.
<span class=”avatar”>
<img src=”...”>
</span>
can be re-written as -
<img class=”avatar” src=”...”>
HTML5 Coding conventions
Some more basic standards -
● Always use the alt attribute with images. It is important when the image cannot be viewed.
● Try to avoid code lines longer than 80 characters.
● Spaces and equal signs - HTML5 allows spaces around equal signs. But space-less is easier
to read, and groups entities better together.
● Use the attributes name in lower case letters.
● Close each and every HTML elements even empty HTML elements also.
.
HTML5 Coding conventions
CSS style guide
CSS style guide
Am I following the correct
coding conventions here?
CSS style guide
Am I following the correct
coding conventions here?
And what about me?
CSS style guide
Am I following the correct
coding conventions here?
And what about me?
CSS style guide
Am I following the correct
coding conventions here?
And what about me?
Let's find out the correct way of coding CSS , following the correct coding conventions.
CSS style guide
Syntax
● Use soft tabs with two spaces—they're the only way to guarantee code renders the same in
any environment.
● When grouping selectors, keep individual selectors to a single line.
● Include one space before the opening brace of declaration blocks for legibility.
● Place closing braces of declaration blocks on a new line.
● Include one space after : for each declaration.
● Each declaration should appear on its own line for more accurate error reporting.
● End all declarations with a semi-colon. The last declaration's is optional, but your code is
more error prone without it.
● Comma-separated property values should include a space after each comma (e.g., box-
shadow).
CSS style guide
● Don't include spaces after commas within rgb(), rgba() values. This helps differentiate
multiple color values from multiple property values.
● Don't prefix property values or color parameters with a leading zero (e.g., .5 instead of 0.5
and -.5px instead of -0.5px).
● Lowercase all hex values, e.g., #fff. Lowercase letters are much easier to read.
● Use shorthand hex values when available, e.g., #fff instead of #ffffff.
● Quote attribute values in selectors, e.g., input[type="text"]. They’re only optional in some
cases, and it’s a good practice for consistency.
● Avoid specifying units for zero values, e.g., margin: 0; instead of margin: 0px;.
CSS style guide
● Declaration order
Following properties should be grouped together :
➢ Positioning (position, top, right)
➢ Box model (display, float, width, height)
➢ Typographic (font, line-height, color)
➢ Visual (background-color, border)
➢ Misc (opacity)
Positioning comes first because it can remove an element from the normal flow of the
document and override box model related styles. The box model comes next as it dictates a
component's dimensions and placement.
CSS style guide
● Don't use of @import
From a page speed standpoint, @import from a CSS file should almost never be used, as it
can prevent stylesheets from being downloaded concurrently.
There are occasionally situations where @import is appropriate, but they are generally the
exception, not the rule.
CSS style guide
● Media query placement
➢ Bundling the media query in a separate file is not preferable.
➢ Decision to add it at the end of the CSS file or placing close to their relevant rule sets
depends upon your CSS file.
CSS style guide
● Single declarations
Consider removing line breaks for readability and faster editing. Any rule set with multiple
declarations should be split to separate lines.
Single-line declaration
Multi-line declaration
CSS style guide
● Shorthand notation
Strive to limit use of shorthand declarations to instances where you must explicitly set all the
available values. Common overused shorthand properties include:
➢ padding
➢ margin
➢ font
➢ background
➢ border
➢ Border-radius
Often times we don't need to set all the values a shorthand property represents.
For example, HTML headings only set top and bottom margin, so when necessary, only
override those two values. Excessive use of shorthand properties often leads to sloppier code
with unnecessary overrides and unintended side effects.
CSS style guide
● Comments
Code is written and maintained by people. Ensure your code is descriptive, well
commented, and approachable by others. Great code comments convey context or
purpose. Do not simply reiterate a component or class name.
CSS style guide
● Class names
Do keep the following points in mind before giving class names to the HTML elements -
➢ Keep classes lowercase and use dashes (not underscores or camelCase). Dashes serve as natural
breaks in related class (e.g., .btn and .btn-danger).
➢ Avoid excessive and arbitrary shorthand notation. .btn is useful for button, but .s doesn't mean
anything.
➢ Keep classes as short and succinct as possible.
➢ Use meaningful names; use structural or purposeful names over presentational.
➢ Prefix classes based on the closest parent or base class.
➢ Use .js-* classes to denote behavior (as opposed to style), but keep these classes out of your CSS.
Class to denote behavior : .js-calculate-price
Some good class names : .sequence { … }, .sequence-header { … }, .important { … }
Not so good class names : .s { … }, .header { … }, .red { … }
CSS style guide
● Selectors
Keep the following in mind before using nested CSS selectors -
➢ Use classes over generic element tag for optimum rendering performance.
➢ Avoid using several attribute selectors (eg., [class^="..."]) on commonly occurring
components. Browser performance is known to be impacted by these.
➢ Keep selectors short and strive to limit the number of elements in each selector to three.
➢ Scope classes to the closest parent only when necessary (e.g., when not using prefixed
classes).
CSS style guide
● CSS quotations
Use single ('') rather than double ("") quotation marks for attribute selectors or property
values.
Do not use quotation marks in URI values (url()).
@import url(“//www.google.com/css”);
html {
font-family: “open sans”, arial, sans-serif;
}
@import url(//www.google.com/css);
html {
font-family: 'open sans', arial, sans-serif;
}
JavaScript coding standards
JS coding standards
● Variable Names
Use of letters with camelCase in naming the variables.
✔ firstName = “Knoldus”;
✔ price = 9.90;
✗ middlename = “Softwares”;
● Spaces around operators
Spaces should be used to differentiate operators and also after commas.
✔ var x = y + z;
✔ var values = [“knoldus” , “software”];
✗ var values=[“knoldus”,“software”];
JS coding standards
● Code Indentation
4 spaces for indentation of code block -
function toCelsius(fahrenheit) {
return (5 / 9) * (fahrenheit – 32);
}
* Do not use tabs for indentation Different editors may treat it differently.
● Statement Rules
Simple statements end with a semicolon. Like – declaring a variable
var person = {
firstName: “Knoldus”,
lastName: “Softwares”,
};
JS coding standards
Complex/ compound statements must follow the following -
➢ Opening bracket at the end of first line,
➢ Space before opening bracket.
➢ Closing bracket on a new line, without leading spaces.
➢ And, complex statements doesn't end with a semicolon.
function tocelsius(fahrenheit) {
return (5 / 9) * (fahrenheit - 32);
}
* same applies for the loop and conditional statements.
JS coding standards
● Object Rules -
➢ Placing opening brackets on the same as the object name.
➢ Using colon plus one space between each property and its value.
➢ No adding of comma at the last property-value pair.
➢ Placing of closing brackets on a new line, without leading spaces.
➢ Never forget to end an object with a semicolon.
var person = {
firstName: "Knoldus",
lastName: "Softwares"
};
Short objects can be compressed and written in one line using the spaces only between their properties -
var person = {firstName:"Knoldus", lastName:"Softwares"};
JS coding standards
● Line length < 80 characters
If a javascript statement does not fit on one line, then the best place to break it, is after an
operator or comma.
document.getElementById("knolx").innerHTML =
"Hello Knolders.";
● Naming Conventions
Remember to maintain consistency in the naming convention for all your code.
➢ All variables and functions must be in camelCase.
➢ Global variables and Constants to be written in UPPERCASE.
JS coding standards
● Line length < 80 characters
If a javascript statement does not fit on one line, then the best place to break it, is after an
operator or comma.
document.getElementById("knolx").innerHTML =
"Hello Knolders.";
● Naming Conventions
Remember to maintain consistency in the naming convention for all your code.
➢ All variables and functions must be in camelCase.
➢ Global variables and Constants to be written in UPPERCASE.
Should we use hyp-hens, camelCase or under_scores in variable names?
JS coding standards
Hyphens (-)
● HTML5 attributes can have hyphens (data-element, data-count).
● CSS uses hyphens in property names (background-color, padding-left, font-size)
● JavaScript names does not allow use of hyphens. As they can conflict with subtraction
operator.
Underscores ( _ )
● Underscores (date_of_birth) are mostly used in databases or in documentation. So, we
prefer not to go with using underscores.
PascalCase
● It is often used by C Programmers.
CamelCase
● This is used by javascript, jquery and in various JS libraries.
References
● https://google.github.io/styleguide/htmlcssguide.xml
● http://codeguide.co
● http://www.w3schools.com/js/js_conventions.asp
● http://www.w3schools.com/html/html5_syntax.asp
Thank you :)Thank you :)
1 de 37

Recomendados

HTML and CSS Coding Standards por
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding StandardsSaajan Maharjan
1.1K visualizações12 slides
Complete Lecture on Css presentation por
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
9.9K visualizações61 slides
Responsive Web Design with HTML5 and CSS3 por
Responsive Web Design with HTML5 and CSS3Responsive Web Design with HTML5 and CSS3
Responsive Web Design with HTML5 and CSS3Kannika Kong
17.5K visualizações22 slides
Css por
CssCss
CssAbhishek Kesharwani
1.2K visualizações27 slides
Javascript por
JavascriptJavascript
JavascriptNagarajan
5.4K visualizações54 slides
1 03 - CSS Introduction por
1 03 - CSS Introduction1 03 - CSS Introduction
1 03 - CSS Introductionapnwebdev
1K visualizações46 slides

Mais conteúdo relacionado

Mais procurados

cascading style sheet ppt por
cascading style sheet pptcascading style sheet ppt
cascading style sheet pptabhilashagupta
38.3K visualizações29 slides
Beginners css tutorial for web designers por
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designersSingsys Pte Ltd
3.2K visualizações46 slides
CSS Day: CSS Grid Layout por
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
9.6K visualizações122 slides
Introduction to CSS3 por
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
4.4K visualizações45 slides
CSS Best practice por
CSS Best practiceCSS Best practice
CSS Best practiceRuss Weakley
7.2K visualizações30 slides
Introduction to Javascript por
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
13.5K visualizações46 slides

Mais procurados(20)

cascading style sheet ppt por abhilashagupta
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
abhilashagupta38.3K visualizações
Beginners css tutorial for web designers por Singsys Pte Ltd
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
Singsys Pte Ltd3.2K visualizações
CSS Day: CSS Grid Layout por Rachel Andrew
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
Rachel Andrew9.6K visualizações
Introduction to CSS3 por Doris Chen
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Doris Chen4.4K visualizações
CSS Best practice por Russ Weakley
CSS Best practiceCSS Best practice
CSS Best practice
Russ Weakley7.2K visualizações
Introduction to Javascript por Amit Tyagi
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
Amit Tyagi13.5K visualizações
Typescript in 30mins por Udaya Kumar
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
Udaya Kumar876 visualizações
Flexbox and Grid Layout por Rachel Andrew
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
Rachel Andrew7K visualizações
Presentation about html5 css3 por Gopi A
Presentation about html5 css3Presentation about html5 css3
Presentation about html5 css3
Gopi A10.7K visualizações
CSS Selectors por Rachel Andrew
CSS SelectorsCSS Selectors
CSS Selectors
Rachel Andrew4K visualizações
How Cascading Style Sheets (CSS) Works por Amit Tyagi
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi79.4K visualizações
Css ppt por Nidhi mishra
Css pptCss ppt
Css ppt
Nidhi mishra2.3K visualizações
JavaScript Programming por Sehwan Noh
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
Sehwan Noh14.9K visualizações
Basic JavaScript Tutorial por DHTMLExtreme
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme3.8K visualizações
(Fast) Introduction to HTML & CSS por Dave Kelly
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
Dave Kelly3.4K visualizações
Javascript basics por shreesenthil
Javascript basicsJavascript basics
Javascript basics
shreesenthil1.8K visualizações
CSS Introduction por Swati Sharma
CSS IntroductionCSS Introduction
CSS Introduction
Swati Sharma1.7K visualizações
Java script por Sadeek Mohammed
Java scriptJava script
Java script
Sadeek Mohammed3.7K visualizações
Tech talk on Tailwind CSS por Squareboat
Tech talk on Tailwind CSSTech talk on Tailwind CSS
Tech talk on Tailwind CSS
Squareboat2.7K visualizações
CSS por Vladimir Zhidal
CSSCSS
CSS
Vladimir Zhidal1.7K visualizações

Destaque

Functional programming in Javascript por
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in JavascriptKnoldus Inc.
1.8K visualizações15 slides
Mailchimp and Mandrill - The ‘Hominidae’ kingdom por
Mailchimp and Mandrill - The ‘Hominidae’ kingdomMailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdomKnoldus Inc.
7.9K visualizações16 slides
Introduction to BDD por
Introduction to BDDIntroduction to BDD
Introduction to BDDKnoldus Inc.
2.7K visualizações14 slides
Deep dive into sass por
Deep dive into sassDeep dive into sass
Deep dive into sassKnoldus Inc.
1.6K visualizações25 slides
Akka Finite State Machine por
Akka Finite State MachineAkka Finite State Machine
Akka Finite State MachineKnoldus Inc.
2.3K visualizações15 slides
Mandrill Templates por
Mandrill TemplatesMandrill Templates
Mandrill TemplatesKnoldus Inc.
2.7K visualizações24 slides

Destaque(20)

Functional programming in Javascript por Knoldus Inc.
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in Javascript
Knoldus Inc.1.8K visualizações
Mailchimp and Mandrill - The ‘Hominidae’ kingdom por Knoldus Inc.
Mailchimp and Mandrill - The ‘Hominidae’ kingdomMailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
Knoldus Inc.7.9K visualizações
Introduction to BDD por Knoldus Inc.
Introduction to BDDIntroduction to BDD
Introduction to BDD
Knoldus Inc.2.7K visualizações
Deep dive into sass por Knoldus Inc.
Deep dive into sassDeep dive into sass
Deep dive into sass
Knoldus Inc.1.6K visualizações
Akka Finite State Machine por Knoldus Inc.
Akka Finite State MachineAkka Finite State Machine
Akka Finite State Machine
Knoldus Inc.2.3K visualizações
Mandrill Templates por Knoldus Inc.
Mandrill TemplatesMandrill Templates
Mandrill Templates
Knoldus Inc.2.7K visualizações
Fast dataarchitecture por Knoldus Inc.
Fast dataarchitectureFast dataarchitecture
Fast dataarchitecture
Knoldus Inc.4.7K visualizações
Introduction to Quasiquotes por Knoldus Inc.
Introduction to QuasiquotesIntroduction to Quasiquotes
Introduction to Quasiquotes
Knoldus Inc.2.5K visualizações
Introduction to Knockout Js por Knoldus Inc.
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
Knoldus Inc.1.8K visualizações
Lambda Architecture with Spark por Knoldus Inc.
Lambda Architecture with SparkLambda Architecture with Spark
Lambda Architecture with Spark
Knoldus Inc.7.5K visualizações
Cassandra - Tips And Techniques por Knoldus Inc.
Cassandra - Tips And TechniquesCassandra - Tips And Techniques
Cassandra - Tips And Techniques
Knoldus Inc.2.2K visualizações
Introduction to Apache Cassandra por Knoldus Inc.
Introduction to Apache Cassandra Introduction to Apache Cassandra
Introduction to Apache Cassandra
Knoldus Inc.4.5K visualizações
Event sourcing with Eventuate por Knoldus Inc.
Event sourcing with EventuateEvent sourcing with Eventuate
Event sourcing with Eventuate
Knoldus Inc.2.8K visualizações
Walk-through: Amazon ECS por Knoldus Inc.
Walk-through: Amazon ECSWalk-through: Amazon ECS
Walk-through: Amazon ECS
Knoldus Inc.3.2K visualizações
Getting started with typescript and angular 2 por Knoldus Inc.
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
Knoldus Inc.4.4K visualizações
Introduction to Structured Streaming por Knoldus Inc.
Introduction to Structured StreamingIntroduction to Structured Streaming
Introduction to Structured Streaming
Knoldus Inc.6.8K visualizações
Introduction to AWS IAM por Knoldus Inc.
Introduction to AWS IAMIntroduction to AWS IAM
Introduction to AWS IAM
Knoldus Inc.4.7K visualizações
Petex 2016 Future Working Zone por Andrew Zolnai
Petex 2016 Future Working ZonePetex 2016 Future Working Zone
Petex 2016 Future Working Zone
Andrew Zolnai635 visualizações
How the web was won por Andrew Zolnai
How the web was wonHow the web was won
How the web was won
Andrew Zolnai1.3K visualizações
Drilling the Async Library por Knoldus Inc.
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
Knoldus Inc.1.1K visualizações

Similar a HTML5, CSS, JavaScript Style guide and coding conventions

Web Design for Literary Theorists II: Overview of CSS (v 1.0) por
Web Design for Literary Theorists II: Overview of CSS (v 1.0)Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Web Design for Literary Theorists II: Overview of CSS (v 1.0)Patrick Mooney
640 visualizações34 slides
Part 2 in depth guide on word-press coding standards for css &amp; js big por
Part 2  in depth guide on word-press coding standards for css &amp; js bigPart 2  in depth guide on word-press coding standards for css &amp; js big
Part 2 in depth guide on word-press coding standards for css &amp; js bigeSparkBiz
32 visualizações19 slides
4. Web Technology CSS Basics-1 por
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1Jyoti Yadav
46 visualizações64 slides
Advanced Web Programming Chapter 8 por
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8RohanMistry15
20 visualizações23 slides
Introduction to HTML+CSS+Javascript.pptx por
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxKADAMBARIPUROHIT
49 visualizações59 slides
CSS Overview por
CSS OverviewCSS Overview
CSS OverviewDoncho Minkov
1.1K visualizações52 slides

Similar a HTML5, CSS, JavaScript Style guide and coding conventions(20)

Web Design for Literary Theorists II: Overview of CSS (v 1.0) por Patrick Mooney
Web Design for Literary Theorists II: Overview of CSS (v 1.0)Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Patrick Mooney640 visualizações
Part 2 in depth guide on word-press coding standards for css &amp; js big por eSparkBiz
Part 2  in depth guide on word-press coding standards for css &amp; js bigPart 2  in depth guide on word-press coding standards for css &amp; js big
Part 2 in depth guide on word-press coding standards for css &amp; js big
eSparkBiz32 visualizações
4. Web Technology CSS Basics-1 por Jyoti Yadav
4. Web Technology CSS Basics-14. Web Technology CSS Basics-1
4. Web Technology CSS Basics-1
Jyoti Yadav46 visualizações
Advanced Web Programming Chapter 8 por RohanMistry15
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
RohanMistry1520 visualizações
Introduction to HTML+CSS+Javascript.pptx por KADAMBARIPUROHIT
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
KADAMBARIPUROHIT49 visualizações
CSS Overview por Doncho Minkov
CSS OverviewCSS Overview
CSS Overview
Doncho Minkov1.1K visualizações
CSS Methodology por Zohar Arad
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad964 visualizações
css-tutorial por tutorialsruby
css-tutorialcss-tutorial
css-tutorial
tutorialsruby848 visualizações
css-tutorial por tutorialsruby
css-tutorialcss-tutorial
css-tutorial
tutorialsruby956 visualizações
Cascading Style Sheets - Part 02 por Hatem Mahmoud
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud4.5K visualizações
wd project.pptx por dsffsdf1
wd project.pptxwd project.pptx
wd project.pptx
dsffsdf125 visualizações
Basics Of Css And Some Common Mistakes por sanjay2211
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
sanjay22118.2K visualizações
DHTML por Ravinder Kamboj
DHTMLDHTML
DHTML
Ravinder Kamboj8.1K visualizações
WEB TECHNOLOGY Unit-2.pptx por karthiksmart21
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
karthiksmart213 visualizações
Html & CSS - Best practices 2-hour-workshop por Vero Rebagliatte
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte4.2K visualizações
Introduction to Web Development.pptx por Alisha Kamat
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
Alisha Kamat21 visualizações
Introduction to Web Development.pptx por Alisha Kamat
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
Alisha Kamat7 visualizações
Introduction to Web Development.pptx por GDSCVJTI
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
GDSCVJTI138 visualizações
Structuring your CSS for maintainability: rules and guile lines to write CSS por Sanjoy Kr. Paul
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul77 visualizações

Mais de Knoldus Inc.

Graylog por
GraylogGraylog
GraylogKnoldus Inc.
103 visualizações13 slides
Getting Started with Delta Lake on Databricks por
Getting Started with Delta Lake on DatabricksGetting Started with Delta Lake on Databricks
Getting Started with Delta Lake on DatabricksKnoldus Inc.
283 visualizações15 slides
Design Thinking in Project Management por
Design Thinking in Project ManagementDesign Thinking in Project Management
Design Thinking in Project ManagementKnoldus Inc.
48 visualizações12 slides
SpringBoot 3 Observability por
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 ObservabilityKnoldus Inc.
218 visualizações10 slides
Cypress Best Pratices for Test Automation por
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test AutomationKnoldus Inc.
46 visualizações22 slides
Business Process Automation A Productivity Lever por
Business Process Automation A Productivity LeverBusiness Process Automation A Productivity Lever
Business Process Automation A Productivity LeverKnoldus Inc.
115 visualizações17 slides

Mais de Knoldus Inc.(20)

Graylog por Knoldus Inc.
GraylogGraylog
Graylog
Knoldus Inc.103 visualizações
Getting Started with Delta Lake on Databricks por Knoldus Inc.
Getting Started with Delta Lake on DatabricksGetting Started with Delta Lake on Databricks
Getting Started with Delta Lake on Databricks
Knoldus Inc.283 visualizações
Design Thinking in Project Management por Knoldus Inc.
Design Thinking in Project ManagementDesign Thinking in Project Management
Design Thinking in Project Management
Knoldus Inc.48 visualizações
SpringBoot 3 Observability por Knoldus Inc.
SpringBoot 3 ObservabilitySpringBoot 3 Observability
SpringBoot 3 Observability
Knoldus Inc.218 visualizações
Cypress Best Pratices for Test Automation por Knoldus Inc.
Cypress Best Pratices for Test AutomationCypress Best Pratices for Test Automation
Cypress Best Pratices for Test Automation
Knoldus Inc.46 visualizações
Business Process Automation A Productivity Lever por Knoldus Inc.
Business Process Automation A Productivity LeverBusiness Process Automation A Productivity Lever
Business Process Automation A Productivity Lever
Knoldus Inc.115 visualizações
Resilience4j with Spring Boot por Knoldus Inc.
Resilience4j with Spring BootResilience4j with Spring Boot
Resilience4j with Spring Boot
Knoldus Inc.159 visualizações
KnolX-K9S por Knoldus Inc.
KnolX-K9SKnolX-K9S
KnolX-K9S
Knoldus Inc.13 visualizações
Dig Deeper With http4s por Knoldus Inc.
Dig Deeper With http4sDig Deeper With http4s
Dig Deeper With http4s
Knoldus Inc.21 visualizações
Ansible Tower por Knoldus Inc.
Ansible TowerAnsible Tower
Ansible Tower
Knoldus Inc.192 visualizações
Scaled Agile Framework por Knoldus Inc.
Scaled Agile FrameworkScaled Agile Framework
Scaled Agile Framework
Knoldus Inc.226 visualizações
Twitter Finagle por Knoldus Inc.
Twitter FinagleTwitter Finagle
Twitter Finagle
Knoldus Inc.41 visualizações
Why Should we use Microsoft's Playwright por Knoldus Inc.
Why Should we use Microsoft's PlaywrightWhy Should we use Microsoft's Playwright
Why Should we use Microsoft's Playwright
Knoldus Inc.807 visualizações
Navigation and Routing in Ionic Apps por Knoldus Inc.
Navigation and Routing in Ionic AppsNavigation and Routing in Ionic Apps
Navigation and Routing in Ionic Apps
Knoldus Inc.95 visualizações
Methods of Optimization in Machine Learning por Knoldus Inc.
Methods of Optimization in Machine LearningMethods of Optimization in Machine Learning
Methods of Optimization in Machine Learning
Knoldus Inc.372 visualizações
Vertex AI Presentation por Knoldus Inc.
Vertex AI PresentationVertex AI Presentation
Vertex AI Presentation
Knoldus Inc.124 visualizações
Reactive Programming por Knoldus Inc.
Reactive ProgrammingReactive Programming
Reactive Programming
Knoldus Inc.31 visualizações
KnolX AWS Tech. Stack por Knoldus Inc.
KnolX AWS Tech. StackKnolX AWS Tech. Stack
KnolX AWS Tech. Stack
Knoldus Inc.90 visualizações
Introduction to Amazon Kinesis Data Streams por Knoldus Inc.
Introduction to Amazon Kinesis Data StreamsIntroduction to Amazon Kinesis Data Streams
Introduction to Amazon Kinesis Data Streams
Knoldus Inc.24 visualizações
Getting started with FP IO por Knoldus Inc.
Getting started with FP IOGetting started with FP IO
Getting started with FP IO
Knoldus Inc.12 visualizações

Último

MS PowerPoint.pptx por
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptxLitty Sylus
5 visualizações14 slides
Fleet Management Software in India por
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
11 visualizações1 slide
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... por
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Donato Onofri
860 visualizações34 slides
Myths and Facts About Hospice Care: Busting Common Misconceptions por
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common MisconceptionsCare Coordinations
6 visualizações1 slide
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...Marc Müller
40 visualizações62 slides
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... por
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
14 visualizações23 slides

Último(20)

MS PowerPoint.pptx por Litty Sylus
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptx
Litty Sylus5 visualizações
Fleet Management Software in India por Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 visualizações
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... por Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri860 visualizações
Myths and Facts About Hospice Care: Busting Common Misconceptions por Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
Care Coordinations6 visualizações
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... por Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller40 visualizações
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... por Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 visualizações
360 graden fabriek por info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492122 visualizações
SAP FOR CONTRACT MANUFACTURING.pdf por Virendra Rai, PMP
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdf
Virendra Rai, PMP13 visualizações
nintendo_64.pptx por paiga02016
nintendo_64.pptxnintendo_64.pptx
nintendo_64.pptx
paiga020165 visualizações
AI and Ml presentation .pptx por FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8712 visualizações
Airline Booking Software por SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta6 visualizações
Dapr Unleashed: Accelerating Microservice Development por Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski10 visualizações
tecnologia18.docx por nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 visualizações
Navigating container technology for enhanced security by Niklas Saari por Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 visualizações
HarshithAkkapelli_Presentation.pdf por harshithakkapelli
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdf
harshithakkapelli11 visualizações
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... por sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik7 visualizações
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... por Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 visualizações
WebAssembly por Jens Siebert
WebAssemblyWebAssembly
WebAssembly
Jens Siebert51 visualizações
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... por NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi212 visualizações
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... por Deltares
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
Deltares9 visualizações

HTML5, CSS, JavaScript Style guide and coding conventions

  • 1. HTML5, CSS, JavaScript Style guide and coding conventions HTML5, CSS, JavaScript Style guide and coding conventions Priyanka Wadhwa Software Consultant Knoldus Software LLP Priyanka Wadhwa Software Consultant Knoldus Software LLP
  • 2. Agenda ● Why we need coding Standards? ● HTML5 coding conventions ● CSS style guide ● JavaScript Coding standards ● Why we need coding Standards? ● HTML5 coding conventions ● CSS style guide ● JavaScript Coding standards
  • 3. What is a need for coding standards ? Problem When we learn a new language, we begin to code in a specific style. A style we want and not the one that has been suggested to us. Now what? ➢ Can the other person actually read your code? Is it spaced out clearly? ➢ Will he be able to work out what’s happening without needing to look at every line? ➢ Will he be able to know how and why are you commenting the work? ➢ And many more questions may arise…
  • 5. Need for coding standards Solution Coding conventions are style guidelines for programming. A coding standards document tells developers how they should write their code. Instead of each developer coding in their own preferred style, they should write all code to the standards outlined in the document. Large projects need to be coded in a consistent style – Not just to make the code easier to understand, but also to ensure that any developer who looks at the code will know what naming conventions say and what should he expect from the entire application.
  • 7. HTML5 coding conventions ● HTML5 doctype Enforce standards mode and more consistent rendering in every browser possible with this simple doctype at the beginning of every HTML page. <!DOCTYPE html> <html> <head> </head> </html> ● Language Attribute A lang attribute is required to be specified on the root html element, giving the document's language. <html lang=”en-us”> <!→-→--> </html>
  • 8. ● Character encoding Ensure proper rendering of your content by declaring an explicit character encoding. <head> <meta charset=”UTF-8”> </head> ● Internet Explorer compatibility mode Internet Explorer supports the use of a document compatibility <meta> tag to specify what version of IE the page should be rendered as. <meta http-equiv=”X-UA-Compatibile” content=”IE=Edge”> ● CSS and JavaScript includes <link rel='stylesheet' href='guide.css'> <style>/* …… */</style> HTML5 Coding conventions
  • 9. ● Attribute order As per the standards, we are required to follow the following order of HTML attributes - ➢ class ➢ id, name ➢ data-* ➢ src, for, type, href, value ➢ title, alt ➢ role, aria-* <a class=”….” id=”…..” data-toggle=”model” href=”#”> Example link </a> <img src=”...” alt=”...”/> HTML5 Coding conventions
  • 10. ● Boolean attributes Requires no declaration. <input type=”text” disabled> <input type=”checkbox” value=”1” checked> <select> <option value=”1” selected>1</option> </select> ● Reducing markup Produce less HTML, avoid superfluous parent elements when writing HTML. <span class=”avatar”> <img src=”...”> </span> can be re-written as - <img class=”avatar” src=”...”> HTML5 Coding conventions
  • 11. Some more basic standards - ● Always use the alt attribute with images. It is important when the image cannot be viewed. ● Try to avoid code lines longer than 80 characters. ● Spaces and equal signs - HTML5 allows spaces around equal signs. But space-less is easier to read, and groups entities better together. ● Use the attributes name in lower case letters. ● Close each and every HTML elements even empty HTML elements also. . HTML5 Coding conventions
  • 13. CSS style guide Am I following the correct coding conventions here?
  • 14. CSS style guide Am I following the correct coding conventions here? And what about me?
  • 15. CSS style guide Am I following the correct coding conventions here? And what about me?
  • 16. CSS style guide Am I following the correct coding conventions here? And what about me? Let's find out the correct way of coding CSS , following the correct coding conventions.
  • 17. CSS style guide Syntax ● Use soft tabs with two spaces—they're the only way to guarantee code renders the same in any environment. ● When grouping selectors, keep individual selectors to a single line. ● Include one space before the opening brace of declaration blocks for legibility. ● Place closing braces of declaration blocks on a new line. ● Include one space after : for each declaration. ● Each declaration should appear on its own line for more accurate error reporting. ● End all declarations with a semi-colon. The last declaration's is optional, but your code is more error prone without it. ● Comma-separated property values should include a space after each comma (e.g., box- shadow).
  • 18. CSS style guide ● Don't include spaces after commas within rgb(), rgba() values. This helps differentiate multiple color values from multiple property values. ● Don't prefix property values or color parameters with a leading zero (e.g., .5 instead of 0.5 and -.5px instead of -0.5px). ● Lowercase all hex values, e.g., #fff. Lowercase letters are much easier to read. ● Use shorthand hex values when available, e.g., #fff instead of #ffffff. ● Quote attribute values in selectors, e.g., input[type="text"]. They’re only optional in some cases, and it’s a good practice for consistency. ● Avoid specifying units for zero values, e.g., margin: 0; instead of margin: 0px;.
  • 19. CSS style guide ● Declaration order Following properties should be grouped together : ➢ Positioning (position, top, right) ➢ Box model (display, float, width, height) ➢ Typographic (font, line-height, color) ➢ Visual (background-color, border) ➢ Misc (opacity) Positioning comes first because it can remove an element from the normal flow of the document and override box model related styles. The box model comes next as it dictates a component's dimensions and placement.
  • 20. CSS style guide ● Don't use of @import From a page speed standpoint, @import from a CSS file should almost never be used, as it can prevent stylesheets from being downloaded concurrently. There are occasionally situations where @import is appropriate, but they are generally the exception, not the rule.
  • 21. CSS style guide ● Media query placement ➢ Bundling the media query in a separate file is not preferable. ➢ Decision to add it at the end of the CSS file or placing close to their relevant rule sets depends upon your CSS file.
  • 22. CSS style guide ● Single declarations Consider removing line breaks for readability and faster editing. Any rule set with multiple declarations should be split to separate lines. Single-line declaration Multi-line declaration
  • 23. CSS style guide ● Shorthand notation Strive to limit use of shorthand declarations to instances where you must explicitly set all the available values. Common overused shorthand properties include: ➢ padding ➢ margin ➢ font ➢ background ➢ border ➢ Border-radius Often times we don't need to set all the values a shorthand property represents. For example, HTML headings only set top and bottom margin, so when necessary, only override those two values. Excessive use of shorthand properties often leads to sloppier code with unnecessary overrides and unintended side effects.
  • 24. CSS style guide ● Comments Code is written and maintained by people. Ensure your code is descriptive, well commented, and approachable by others. Great code comments convey context or purpose. Do not simply reiterate a component or class name.
  • 25. CSS style guide ● Class names Do keep the following points in mind before giving class names to the HTML elements - ➢ Keep classes lowercase and use dashes (not underscores or camelCase). Dashes serve as natural breaks in related class (e.g., .btn and .btn-danger). ➢ Avoid excessive and arbitrary shorthand notation. .btn is useful for button, but .s doesn't mean anything. ➢ Keep classes as short and succinct as possible. ➢ Use meaningful names; use structural or purposeful names over presentational. ➢ Prefix classes based on the closest parent or base class. ➢ Use .js-* classes to denote behavior (as opposed to style), but keep these classes out of your CSS. Class to denote behavior : .js-calculate-price Some good class names : .sequence { … }, .sequence-header { … }, .important { … } Not so good class names : .s { … }, .header { … }, .red { … }
  • 26. CSS style guide ● Selectors Keep the following in mind before using nested CSS selectors - ➢ Use classes over generic element tag for optimum rendering performance. ➢ Avoid using several attribute selectors (eg., [class^="..."]) on commonly occurring components. Browser performance is known to be impacted by these. ➢ Keep selectors short and strive to limit the number of elements in each selector to three. ➢ Scope classes to the closest parent only when necessary (e.g., when not using prefixed classes).
  • 27. CSS style guide ● CSS quotations Use single ('') rather than double ("") quotation marks for attribute selectors or property values. Do not use quotation marks in URI values (url()). @import url(“//www.google.com/css”); html { font-family: “open sans”, arial, sans-serif; } @import url(//www.google.com/css); html { font-family: 'open sans', arial, sans-serif; }
  • 29. JS coding standards ● Variable Names Use of letters with camelCase in naming the variables. ✔ firstName = “Knoldus”; ✔ price = 9.90; ✗ middlename = “Softwares”; ● Spaces around operators Spaces should be used to differentiate operators and also after commas. ✔ var x = y + z; ✔ var values = [“knoldus” , “software”]; ✗ var values=[“knoldus”,“software”];
  • 30. JS coding standards ● Code Indentation 4 spaces for indentation of code block - function toCelsius(fahrenheit) { return (5 / 9) * (fahrenheit – 32); } * Do not use tabs for indentation Different editors may treat it differently. ● Statement Rules Simple statements end with a semicolon. Like – declaring a variable var person = { firstName: “Knoldus”, lastName: “Softwares”, };
  • 31. JS coding standards Complex/ compound statements must follow the following - ➢ Opening bracket at the end of first line, ➢ Space before opening bracket. ➢ Closing bracket on a new line, without leading spaces. ➢ And, complex statements doesn't end with a semicolon. function tocelsius(fahrenheit) { return (5 / 9) * (fahrenheit - 32); } * same applies for the loop and conditional statements.
  • 32. JS coding standards ● Object Rules - ➢ Placing opening brackets on the same as the object name. ➢ Using colon plus one space between each property and its value. ➢ No adding of comma at the last property-value pair. ➢ Placing of closing brackets on a new line, without leading spaces. ➢ Never forget to end an object with a semicolon. var person = { firstName: "Knoldus", lastName: "Softwares" }; Short objects can be compressed and written in one line using the spaces only between their properties - var person = {firstName:"Knoldus", lastName:"Softwares"};
  • 33. JS coding standards ● Line length < 80 characters If a javascript statement does not fit on one line, then the best place to break it, is after an operator or comma. document.getElementById("knolx").innerHTML = "Hello Knolders."; ● Naming Conventions Remember to maintain consistency in the naming convention for all your code. ➢ All variables and functions must be in camelCase. ➢ Global variables and Constants to be written in UPPERCASE.
  • 34. JS coding standards ● Line length < 80 characters If a javascript statement does not fit on one line, then the best place to break it, is after an operator or comma. document.getElementById("knolx").innerHTML = "Hello Knolders."; ● Naming Conventions Remember to maintain consistency in the naming convention for all your code. ➢ All variables and functions must be in camelCase. ➢ Global variables and Constants to be written in UPPERCASE. Should we use hyp-hens, camelCase or under_scores in variable names?
  • 35. JS coding standards Hyphens (-) ● HTML5 attributes can have hyphens (data-element, data-count). ● CSS uses hyphens in property names (background-color, padding-left, font-size) ● JavaScript names does not allow use of hyphens. As they can conflict with subtraction operator. Underscores ( _ ) ● Underscores (date_of_birth) are mostly used in databases or in documentation. So, we prefer not to go with using underscores. PascalCase ● It is often used by C Programmers. CamelCase ● This is used by javascript, jquery and in various JS libraries.
  • 36. References ● https://google.github.io/styleguide/htmlcssguide.xml ● http://codeguide.co ● http://www.w3schools.com/js/js_conventions.asp ● http://www.w3schools.com/html/html5_syntax.asp

Notas do Editor

  1. specify a lang attribute on the root html element
  2. UTF-8 is for chracter encoding. It is capable of encoding all possivle characters, defined by unicode. UTF-8: UTF-8 is backwards compatible with ASCII. UTF-8 is the preferred encoding for e-mail and web pages 1 byte: Standard ASCII 2 bytes: Arabic, Hebrew, most European scripts (most notably excluding Georgian) 3 bytes: BMP 4 bytes: All Unicode characters UTF-16: capable of encoding the entire Unicode repertoire. UTF-16 is used in major operating systems and environments, like Microsoft Windows, Java and .NET. 2 bytes: BMP 4 bytes: All Unicode characters
  3. For instance, if stylesheet A contains the text: @import url(&amp;quot;stylesheetB.css&amp;quot;); then the download of the second stylesheet may not start until the first stylesheet has been downloaded. If, on the other hand, both stylesheets are referenced in &amp;lt;link&amp;gt; elements in the main HTML page, both can be downloaded at the same time. If both stylesheets are always loaded together, it can also be helpful to simply combine them into a single file.