Sometimes there is an easy way to divide blocks by their appearances because it requires fewer styles. But it is the wrong way that will confuse your teammates and make the app less scalable
Avoid such a code: <span><div></div></span>
Use long names and long descriptions for all available text elements
Only one <h1>
is supposed to be on one page
If a table has a heading row - use <thead>
and nested <th>
for the first raw
<br>
is supposed to be appropriate only where all of the following conditions are applied:
- Newlines are semantically meaningful
- Indentation is not semantically meaningful (otherwise, you should use a
<pre>
) - There exists no other semantically appropriate tag, like a paragraph or header tag
Don't do this if this file is for extending by template engine
Don't even put spaces and line breaks there
It can save <title>
from incorrect encoding
Define tags title, keywords, and description in the <head>
Usually <meta name="viewport" content="initial-scale=1.0, width=device-width">
default is enough
Good: <img />
or <input />
.
Bad: <div />
and <span />
Don't do like this:
<img width=200 />
<div class=block></div>
<a href='/some/url'></a>
Always try to guarantee that id is unique (for example get it only from database unique field). Use it only when you need:
- In-page navigation (example is Wikipedia web-site)
- Bind
<label>
and<input>
if they placed in different DOM branches. However, always prefer to put<input>
inside<label>
, hereid
is not required
Avoid simple unnamed <div></div>
and <span></span>
There should not be something like this: <div onclick="func()">
. Of course except of projects with frameworks that make you to do such things (like Angular or React)
Avoid simple <img />
tags because sometimes links to the images can be broken. Nevertheless web-site should be still functional
This will allow submiting by hitting Enter key and will semantically bind all elements
You can have several forms on a page but they should not be nested.
Use email, number, color, etc, old browsers will just use them as simple text
Use simple <span>
. And all links should be able to open new tabs with third mouse click
Examples
<a href="tel: +74951234567">+7 (495) 123-45-67</a>
<a href="mailto: [email protected]">[email protected]</a>
<a href="skype: someskype?call">someskype</a>
Sometimes for educational or another purposes we can display code samples (we often do it in this document). It is good practice to wrap all code snippets in <code>
tag and use only monospaced fonts.
If there are no special conventions, all names should be also "lower-case-hyphenated"
If you can't find it - spend some time to ask manager or designer for it
Use http://www.jpegmini.com or https://tinypng.com for example, but prefer CLI-clients
Images without transparency should have .jpeg