10 best practices for Front-End web developers1. Use CSS reset
CSS Reset is a short, often minified set of CSS rules that resets the styling of all HTML elements to a consistent baseline. In case you didn't know, every browser has its own default 'user agent' stylesheet, that it uses to make unstyled websites appear more legible. Because by default, browsers don’t apply the same default styling to HTML elements, a CSS reset will ensure that all element have no particular style so you can define your own without the risk of many cross-browser rendering issue.
2. Don’t use @import
CSS files can be included using the @import directive. This can be useful when, for example, you want to include a style sheet into another. While it works, the @import directive is much slower than the other way to include style sheets into a HTML document: It will not make a difference on low traffic websites, but if you have the chance to own a popular website, don’t waste your visitor’s time using @import.
4. Use HTML semantically
HTML is a markup language, used to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, and more. If you started to create websites in the good old 90’s or in the beginning of the century, you know how dirty the markup was at the time. But happily, it has evolved. Among other things, it is important to use HTML element semantically.
5. Explain which DIV you’re closing
Most of the time when we see website source, at the very bottom of the page, an almost endless list of closing </div> tags. Div's can be cleaners than tables, but without proper code organization, it can be as messy as table based code. Using indentation is a good start. But a tip that can definitely make you save lot of time is to comment every div tag you’re closing, like using <!-- end -->
6. Don’t write inline CSS
As a markup language, the right use of HTML is to organize documents by defining a header, a footer, lists, blockquotes. Some time ago, front-end web developers often used now deprecated HTML attributes to style a particular element. Nowadays, the style attribute allows developers to insert CSS directly into a HTML document. This is very useful for testing or when you’re in a hurry. But the <style> attribute is bad practice, even Google forbids it.
8. Use conditional comments
IE sucks, and some clients suck even more by requiring you to create web pages which are compatible with this obsolete browser. To target specific versions of IE, you can use the well known IE hacks, as shown below:
height: 200px; /* normal browsers */ _height: 300px; /* IE6 */ .height: 250px; /* IE7 */ *height: 350px; /* All IEs */Those hacks are extremely useful sometimes, but they are not the best way to target a specific version of IE, and it will cause your CSS validation to fail.
9. Optimizing images
Image optimization is an art that not many people master. There are many good image editing tools that allow us to get the best visual result for a certain file size but "under the hood" a lot more optimization can be done.
10. Test your site to avoid cross-browser issues
The term cross-browser is often confused with multi-browser. Multi-browser means something works with several web browsers. For your visitor's sake test and enhance your site make it as compatible as possible.