The purpose of this style guide is to improve code quality by documenting a set of expected rules that can consistently apply across all projects. The main benefits are the following.
- Easier for new developers to on board on a project
- Easier to troubleshoot code across different projects
- Easier to contribute additional code
- Easier to adjust for SEO across all projects
- Easier to identify strategy and logic that can be applied to different projects
The following helps navigate through these guidelines.
- 1.1. Typography
- 1.2. Spacing and Overflows
- 1.3. Tags
- 1.4. Attributes
- 1.5. Comments
- 1.6. Inline Styles
- 1.7. Handlebars
- 1.8. Bootstrap
- 1.9. Template One
Do not use all uppercase text.
This is correct
Cum sociis natoque
This is correct
cum sociis natoque
This is correct
Cum Sociis Natoque
This is incorrect
CUM SOCIIS NATOQUE
Generally, do not exceed 80 characters per line. Most IDEs already
made visible the overflow line. Inline text such as <p>Inline Text</p>
is
acceptable so long as it does not exceed the overflow line.
Text that cannot fit inline should be brought to the next line such as the following.
This is correct
<p>
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis <strong>parturient montes</strong>, nascetur
ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
</p>
This implies that text that needs to be overflowed should not start with their parent tag. In other words the following is NOT allowed.
This is incorrect
<p>Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis <strong>parturient montes</strong>, nascetur ridiculus
mus. Nullam id dolor id nibh ultricies vehicula.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.</p>
The <strong>
tag in the above example since it is an inline tag, should also
be treated as inline.
This is incorrect
<p>
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis
<strong>parturient montes</strong>,
nascetur ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
</p>
The correct example above does imply that when opening a new tag, its content should be tabbed with 4 spaces like the following example.
This is correct
<div>
<span>Cum sociis natoque penatibus et magnis dis</span>
</div>
However if it can still fit within 80 characters the following the acceptable.
This is correct
<div><span>Cum sociis natoque penatibus et magnis dis</span></div>
This is incorrect
<div><span>Cum sociis natoque penatibus et magnis dis parturient montes
nascetur ridiculus mus.</span></div>
When dealing with tags having a lot of attributes, you should drop and tab each attribute. The closing tag should be separated in a new line.
This is correct
<a
class="post-like"
data-do="post-like"
data-id="123"
data-on="click"
href="javascript:void(0)"
title="This will send your information to the Job Seeker"
>
Click Me
</a>
This is correct
<img
alt="Logo"
src="logo.png"
width="200"
/>
This is incorrect
<a class="post-like" data-do="post-like" data-id="123" data-on="click" href="javascript:void(0)" title="This will send your information to the Job Seeker">
Click Me
</a>
This is incorrect
<a class="post-like"
data-do="post-like"
data-id="123"
data-on="click"
href="javascript:void(0)"
title="This will send your information to the Job Seeker">
Click Me</a>
This is incorrect
<img src="logo.png"
alt="Logo"
width="200" />
When laying out a page, or laying out a block take advantage of
<header><aside><section><footer>
where applies.
Page
------------------------------------------------
| |
| Header |
| |
------------------------------------------------
| Body |
| ------------------------------------------ |
| | ASIDE | SECTION | |
| | | | |
| | ----------- | -------------------- | |
| | | | | | | | |
| | | BLOCK 1 | | | ARTICLE 1 | | |
| | | | | | | | |
| | ----------- | -------------------- | |
| | | | |
| | ----------- | -------------------- | |
| | | | | | | | |
| | | BLOCK 2 | | | ARTICLE 2 | | |
| | | | | | | | |
| | ----------- | -------------------- | |
| ------------------------------------------ |
| |
------------------------------------------------
| |
| Footer |
| |
------------------------------------------------
Article tags <article>
should be used to explain content sections. This means,
you should use article
even when describing a post, product, event etc.
Under no circumstance should a block tag be found in an inline tag.
This is correct
<h3><a href="#">A good example</a></h3>
<p><span>A good example</span></p>
This is incorrect
<a href="#"><h3>A bad example</h3></a>
<span><p>A bad example</p></span>
Additionally, paragraph tags should not have block tags.
This is incorrect
<p><h3>A bad example</h3></p>
<p><div>A bad example</div></p>
Self closing tags should have a space followed by a forward slash.
This is correct
<hr />
<br />
<img alt="" src="" />
<input />
This is incorrect
<hr>
<br>
<img alt="" src="">
<input>
Headers are used to help outline a page; to help figure out the important parts of a page there by help making it possible to summarize its content.
There should be no more than one <h1>
tag per page. Otherwise, there can be
multiple instances of header tags, but do not skip header numbers. For example
if there is an <h3>
, you should also have an <h2>
. Header text should be
less than 140 characters.
This is correct
<h2>Nullam Quis Risus Eget Urna</h2>
This is incorrect
<h2>
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis <strong>parturient montes</strong>, nascetur
ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
</h2>
Headers should be treated as subject titles. This implies that the text found inside headers should follow a titling convention.
This is correct
<h2>A Major Title in Example</h2>
This is incorrect
<h2>a major title in example</h2>
This is incorrect
<h2>A MAJOR TITLE IN EXAMPLE</h2>
The above implies that no all caps is incorrect. If there are styles that require the text to be in all caps, you can do so in CSS instead.
All link tags should have the title=""
attribute. Titles should not exceed
140 characters.
All image tags should have the alt=""
attribute. Alts should not exceed
140 characters.
Break Tags <br />
are only allowed if it is between text.
This is correct
<p>Nullam quis risus eget urna <br /> mollis ornare vel eu leo.</p>
This is correct
<span>
Nullam quis risus eget urna
<br />
mollis ornare vel eu leo.
</span>
This is correct
<div>
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis <strong>parturient montes</strong>, nascetur
ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
<br />
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
</div>
Do not use <br />
to space blocks. Use CSS instead.
This is incorrect
<div>
Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque
penatibus et magnis dis <strong>parturient montes</strong>, nascetur
ridiculus mus. Nullam id dolor id nibh ultricies vehicula.
</div>
<br />
<div>
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus.
</div>
The horizontal ruling tag <hr />
is used to define a thematic change in the
content. Like break tags, do not use it to space blocks.
This is correct
<h1>HTML</h1>
<p>HTML is a language for describing web pages.....</p>
<hr />
<h1>CSS</h1>
<p>CSS defines how to display HTML elements.....</p>
All stylesheet tags <link>
should have an href
, rel
and type
attribute.
Script tags <script>
should have at least a type
attribute.
This is correct
<link href="/custom.css" rel="stylesheet" type="text/css" />
This is correct
<script type="text/javascript"></script>
<script type="text/javascript" src="custom.js"></script>
This is incorrect
<script src="custom.js"></script>
<script></script>
Usage of <b>
to bold, <i>
for italics, <s>
to strike out are prohibited.
Please find their HTML5 and/or CSS3 equivalents. Do not use <font>
under
no circumstances.
Attribute values should be within double quotes at all times.
This is correct
<input value="4" />
This is incorrect
<input value='4' />
This is incorrect
<input value=4 />
Attributes should placed in alphabetical order.
This is correct
<input class="form-control" name="post_count" type="text" value="4" />
This is incorrect
<input name="post_count" class="form-control" value="4" type="text" />
IDs should have unique values per page. IDs should only be used when dealing directly with javascript. You should not add styles to IDs; use classes instead. ID values should use all lowercase and dashes to separate words.
This is correct
<div id="unique-id-1"></div>
<div id="unique-id-2"></div>
This is incorrect
<div id="unique_id_1"></div>
<div id="unique_id_1"></div>
You should not use classes to indicate a particular style change. The following describes what classes not to use.
This is incorrect
<div class="pad-top margin-bottom center"></div>
Exceptions are usage of classes already defined in Twitter Bootstrap. The following for example is acceptable, however you want to try as much as possible to try other ways.
This is acceptable
<div class="pull-right pull-left text-success"></div>
Classes should have meaningful names and minimized as much as possible. If a class has more than 5 names, you should reconsider and organize your styles. Class names should be unique enough to group HTML while considering its use across the entire site.
This is correct
<h3 class="post-title">Some Title</h3>
This is incorrect
<h3 class="title">Some Title</h3>
As implied above it is best practice to describe each class name with at least two words. Class names should use all lowercase and dashes to separate words.
This is correct
<div class="post-summary"></div>
This is incorrect
<div class="post_summary"></div>
This is correct
<div class="post-item">
<h3 class="post-title">Some Title</h3>
</div>
This is incorrect
<div class="post">
<h3 class="title">Some Title</h3>
</div>
Overall classes should be strategically placed and minimized as much as possible.
Lastly, classes should be alphabetical.
This is correct
<div class="active post-summary pull-right"></div>
This is incorrect
<div class="pull-right post_summary active"></div>
The clearfix
class is used to properly adjust the height and width of a tag
where all of its children are using float
. The proper way of using clearfix
is the following.
This is correct
<div class="clearfix">
<div class="pull-left">
Item 1
</div>
<div class="pull-right">
Item 2
</div>
</div>
This is incorrect
<div>
<div class="pull-left">
Item 1
</div>
<div class="pull-right">
Item 2
</div>
<div class="clearfix"></div>
</div>
This is incorrect
<div>
<div class="pull-left">
Item 1
</div>
<div class="pull-right">
Item 2
</div>
</div>
<div class="clearfix"></div>
Use Comments to describe sections, blocks and states. This is helpful when troubleshooting code and automated acceptance testing. Comments should wrap at least each major section in the following format example.
This is correct
<!-- START: Post Image -->
<div class="post-image">
<img alt="This is a post image" height="60" src="avatar.png" />
</div>
<!-- END: Post Image -->
This is correct
<!-- START: I am logged in -->
<li>
<a href="/logout">Log Out</a>
</li>
<!-- END: I am logged in -->
This is incorrect
<!-- Post Image -->
<div class="post-image">
<img alt="This is a post image" height="60" src="avatar.png" />
</div>
This is incorrect
<!-- I am logged in -->
<li>
<a href="/logout">Log Out</a>
</li>
Just like our backend code, we encourage more comments on the front end code.
Inline styles are only permitted when dealing directly with javascript or with email HTML. Otherwise inline styles should be placed into a separate file
This is correct
<link href="/custom.css" rel="stylesheet" type="text/css" />
<h1>Some Title</h1>
This is incorrect
<style>
h1 {
font-weight: bold;
}
</style>
<h1>Some Title</h1>
This is incorrect
<h1 style="font-weight: bold;">Some Title</h1>
Inline scripts are only permitted when instructed by a third party vendor or inline a tag used to activate a script in a separate file. If it is custom code, it should be placed into a separate file.
This is correct
<h1 id="post-title-1">Some Title</h1>
<script src="custom.js" type="text/css"></script>
This is correct
<img onerror="this.parentNode.parentNode.removeChild(this.parentNode)" />
This is incorrect
<h1 id="post-title-1">Some Title</h1>
<script type="text/javascript">
//do some script
var title = document.getElementById('post-title-1');
</script>
Templates wrapped around script tags however are acceptable.
This is correct
<script tyle="text/x-template">
<h1>Some Title</h1>
</script>
At all times Handlebars should be treated as backend code, thus all regular backend style guidelines should apply.
Code in blocks should separated by lines where there is an opportunity to do so. Code inside of Handlebar blocks should be indented with 4 spaces.
This is correct
<!-- START: Profile Name -->
<h3 class="profile-name">
{{#if profile_name}}
<span>{{profile_name}}</span>
{{else}}
<span>{{_ 'Guest'}}</span>
{{/if}}
</h3>
<!-- END: Profile Name -->
This is incorrect
<!-- START: Profile Name -->
<h3 class="profile-name">
{{#if profile_name}}
<span>{{profile_name}}</span>
{{else}}
<span>{{_ 'Guest'}}</span>
{{/if}}
</h3>
<!-- END: Profile Name -->
This is incorrect
<!-- START: Profile Name -->
<h3 class="profile-name">
<span>{{#if profile_name}}{{profile_name}}{{else}}{{_ 'Guest'}}{{/if}}</span>
</h3>
<!-- END: Profile Name -->
This is correct
<!-- START: Profile Name -->
<h3
class="profile-name
{{~#if logged_in}}
profile-logged-in
{{~else}}
profile-logged-out
{{/if~}}
"
>
{{profile_name}}
</h3>
<!-- END: Profile Name -->
This is incorrect
<!-- START: Profile Name -->
<h3 class="profile-name{{#if logged_in}} profile-logged-in{{else}} profile-logged-out{{/if}}">
{{profile_name}}
</h3>
<!-- END: Profile Name -->
To keep HTML in the 80 character limit per line, consider using partials in order to reset the tab count.
This is incorrect
<div class="post-search-body post-{{type}}" >
{{#unless profile_banner}}
<form action="/post/search" class="post-search-form">
<div class="search-group">
<div
class="tag-field"
data-do="tag-field"
data-name="q"
data-suggest=true
>
{{#each q}}
<div class="tag bordered">
<input
autocomplete="off"
class="tag-input text-field"
data-do="suggestion-field"
name="q[]"
placeholder="{{_ 'Enter Search'}}"
type="text"
value="{{this}}"
/>
<a class="remove" href="javascript:void(0)">x</a>
</div>
{{/each}}
{{#if type}}
<input name="type" type="hidden" value="{{type}}">
{{/if}}
<div class="pull-right search-icon">
<button type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="text-blue">Suggested Filters:</div>
<div class="suggested-terms">
{{#each terms}}
<a
class="btn btn-white"
data-do="add-keyword"
data-on="click"
data-value="{{term_name}}"
>
{{term_name}}
</a>
{{/each}}
</div>
</div>
</form>
{{/unless}}
</div>
This is correct
<div class="post-search-body post-{{type}}" >
{{#unless profile_banner}}
<form action="/post/search" class="post-search-form" >
{{> search_fields}}
</form>
{{/unless}}
</div>
Use partials to keep the HTML code as small as possible while providing reusability on HTML code blocks.
Always consider that every product will be launched in different countries.
This is correct
<h2>{{_ 'A Major Title in Example'}}</h2>
This is correct
<h2>{{_ 'A Major %s in %s' post_title post_location}}</h2>
This is correct
<h2>
{{#_ 'A Major %s in %s'}}
{{post_title}} __ {{post_location}}
{{/_}}
</h2>
This is incorrect
<h2>Will complete in {{post_complete}} year{{#when post_complete '>' 1}}s{{/when}}</h2>
The reason why the example above is invalid is because
year{{#when post_complete '>' 1}}s{{/when}}
cannot scale to different
languages.
Before deciding to style HTML from the ground up, it is good practice to first find the bootstrap example that closely resembles the desired output. After this, if you still need to style a UI from the ground up, talk to your team lead first.
The original purpose of Bootstrap Grids should only be used to layout a page, not to be used within specific blocks. It is recommended to use custom styling instead.
Page
------------------------------------------------
| |
| Header |
| |
------------------------------------------------
| Body |
| ------------------------------------------ |
| | ASIDE | SECTION | |
| | | | |
| | ----------- | -------------------- | |
| | | | | | | | |
| | | BLOCK 1 | | | ARTICLE 1 | | |
| | | | | | | | |
| | ----------- | -------------------- | |
| | | | |
| | ----------- | -------------------- | |
| | | | | | | | |
| | | BLOCK 2 | | | ARTICLE 2 | | |
| | | | | | | | |
| | ----------- | -------------------- | |
| ------------------------------------------ |
| |
------------------------------------------------
| |
| Footer |
| |
------------------------------------------------
Before using rows
and col-*
be sure you fully understand the subject.
Consult with the team lead if you are unsure about using this.
All custom website themes should have a template one page made before development. The rationale is to increase the flexibility of UI components and to reduce the need to review custom code everytime we introduce a new UI component.
The following is how a template one page would look like. The minimum requirement for a template one page is HTML and CSS, though having the page JS and handlebars enabled would make it easier to layout different pages with the template one page.