bendc /frontend-guidelines
Some HTML, CSS and JS best practices.
★ 9,132⑂ 673👁 324⑃ 35● 46▤ 0
More from this author
+0
Daily
9,132
stars
673
forks
324
watchers
35
prs
46
issues
0
releases
README
Frontend Guidelines
HTML
Semantics
HTML5 provides us with lots of semantic elements aimed to describe precisely the content. Make sure you benefit from its rich vocabulary.
html
Blog post
Published: 21st Feb, 2015
…
Blog post
Published: 21st Feb, 2015
…
Make sure you understand the semantics of the elements you're using. It's worse to use a semantic
element in a wrong way than staying neutral.
html
Brevity
Keep your code terse. Forget about your old XHTML habits.
html
Contact
Contact me
Email address:
Contact
Contact me
Email address:
Accessibility
Accessibility shouldn't be an afterthought. You don't have to be a WCAG expert to improve your
website, you can start immediately by fixing the little things that make a huge difference, such as:
learning to use the alt attribute properly
making sure your links and buttons are marked as such (no atrocities)
not relying exclusively on colors to communicate information
explicitly labelling form controls
html
Language & character encoding
While defining the language is optional, it's recommended to always declare
it on the root element.
The HTML standard requires that pages use the UTF-8 character encoding.
It has to be declared, and although it can be declared in the Content-Type HTTP header,
it is recommended to always declare it at the document level.
html
Hello, world.
Hello, world.
Performance
Unless there's a valid reason for loading your scripts before your content, don't block the
rendering of your page. If your style sheet is heavy, isolate the styles that are absolutely
required initially and defer the loading of the secondary declarations in a separate style sheet.
Two HTTP requests is significantly slower than one, but the perception of speed is the most
important factor.
html
Hello, world.
...
Hello, world.
...
CSS
Semicolons
While the semicolon is technically a separator in CSS, always treat it as a terminator.
css
/ bad /
div {
color: red
}
/ good /
div {
color: red;
}
Box model
The box model should ideally be the same for the entire document. A global
{ box-sizing: border-box; } is fine, but don't change the default box model
on specific elements if you can avoid it.
css
/ bad /
div {
width: 100%;
padding: 10px;
box-sizing: border-box;
}
/ good /
div {
padding: 10px;
}
Flow
Don't change the default behavior of an element if you can avoid it. Keep elements in the
natural document flow as much as you can. For example, removing the white-space below an
image shouldn't make you change its default display:
css
/ bad /
img {
display: block;
}
/ good /
img {
vertical-align: middle;
}
Similarly, don't take an element off the flow if you can avoid it.
css
/ bad /
div {
width: 100px;
position: absolute;
right