30 Web Development Best Practices for Beginners

30 Web Development Best Practices for Beginners


There’s a lot to study as an online developer. For starters, the syntax of HTML, CSS and JavaScript, and the way these basic net languages work collectively.

Nonetheless, on high of that it’s good to learn to code effectively: how one can use the net applied sciences like knowledgeable, to create environment friendly, maintainable, and scalable apps and internet sites.

On this publish, I will share 30 ideas for greatest practices while you’re coding you webpages or net apps.

High 10 HTML Finest Practices

1. At all times Declare DOCTYPE

The DOCTYPE is without doubt one of the first few parameters a browser seems for. By definition, it tells the browser, the model of the HTML doc.If some other markup language is used, the DOCTYPE would inform about it. Therefore, the browser makes use of the DOCTYPE to know how all the doc must interpreted. 

So, what would occur if you do not have DOCTYPE in your HTML code? The browser will operate in Quirk state. It would take into account the HTML code as a chunk written within the late 90s. Consequently, bugs in older browsers will begin to imitate. In fact, the browser will do its greatest to parse the HTML doc. Nonetheless, not all parts in your code can be displayed precisely. 

The Quirk Mode is a technique utilized by sure browsers for sustaining backward compatibility. It helps in opening webpages which might be written in older requirements. In Customary Modes, the code must adjust to W3C and IETF requirements.

With the launch of HTML5 all the pieces turned a lot less complicated. It’s essential to add the next line, earlier than the <html> tag.

2. Solely One H1 Tag for a Web page

Have you ever been to Twitter recently? in the event you pay shut consideration, you’d realise that the H1 Tag is used as a emblem, as an alternative of a title. This isn’t unusual. Nonetheless, if you’re constructing a single web page software, or a weblog, it’s best to save the H1 tag for the title. H1 ought to be used to explain your web page. Whenever you embrace a number of H1 tags in a single web page, the general search engine scores can be affected. The W3C Specification advises builders to make use of solely a single H1 tag per web page.

3. Pictures Want the alt Attribute

It’s simple to overlook to make use of the alt attribute inside picture tags. Nonetheless, the alt attribute performs a vital position in validation and accessibility. By definition. the alt tag provides an alternate textual content for the picture in your web page. If the picture doesn’t get loaded, the alt textual content can be proven. Search engine scores can be affected, in the event you do not use the alt tag in your pictures. Consequently, your web page will safe a decrease rank. Not solely that, however your web page can be much less accessible to these with display screen readers.

4. Validate your HTML

Validating HTML will assist in choosing wrongly written code, and defects. There are a few validators out there on the net to assist. W3C provides considered one of most generally used HTML validators. 

5. Use Semantic Parts

HTML semantic parts are used to create webpages with construction. Whenever you assemble a webpage, it might be best to make use of semantic parts, as an alternative of organizing all the pieces into <div>s. For instance, keep away from the usage of <div> to construct headers and footers. As an alternative, make use of the semantic parts <header> and <footer> as an alternative. The <header> semantic aspect helps in exhibiting the beginning of a webpage. Alternatively, the <footer> is a spot for exhibiting navigation hyperlinks and copyright content material. 

Different semantic tags embrace <article> and <nav>.

6. At all times use Descriptive Meta Tags

Meta tags encompass two attributes: the descriptive meta attribute and key phrase meta attribute. This tag is utilized by search engines like google to know web page content material and join searchers with content material they’re on the lookout for. Search engine spiders get lot of significant details about the webpage from meta tags. 

The descriptive meta attribute is used to summarise the contents and objective of the webpage. It must be concise and related. By no means spam the descriptive meta attribute with repeated phrases. Trendy search engines like google are good sufficient to establish this trick.

The key phrase meta attribute is a set of key phrases that greatest describe the web page. It may be used to classify the webpage.

7. Shut All Your Tags

HTML is a really forgiving language. Browsers are able to rendering pages even when there are syntax errors. Nonetheless these errors—for instance not closing your tags—could make your browser run in Quirks mode. Meaning your content material won’t render the way in which you anticipate.

Unclosed tags are dangerous coding apply. In response to the W3C specification, all tags should be closed. 

8. Separate IE Fixes

You will need to construct a webpage that works on all browsers. However, one of many trickiest browsers to develop for is Web Explorer. If you’re having points with IE, then it’s good to construct modular code with satisfactory feedback.

For instance, within the beneath piece of code, solely the .css file must be modified to adapt to the IE model. 

Mixing IE compatibility fixes with the remainder of your code is asking for bother. Your code can be more durable to keep up and perceive.

9. Keep away from Too Many Feedback

This is not recommendation you may hear too usually in growth!

Not like different languages, HTML is self-explanatory. Should you use the proper semantic parts, and naming conventions, you needn’t add too many feedback. In case you might be compelled to enter many feedback, it’s best to revisit your code. 

10. Lowercase Markup and Indentation

Lastly, in HTML it’s best to keep on with lowercase characters. Right here, we aren’t coping with code standardisation. As an alternative, our major focus is code readability, which interprets to raised maintainability and readibility. Along with lowercase markup, the code must be well-indented. 

High 10 CSS Finest Practices

1. Keep away from Importing Many Stylesheets

Heard of vital rendering path? The second a response is shipped from the server to the browser, the browser begins to color the web page. It at all times has the DOM to construct. However, in case your code is loaded with many imported CSS information, the general time required to construct the web page will increase. It is because the browser builds a CSSOM (CSS Object Mannequin) for the CSS in your HTML web page. Till the CSSOM of the web page is constructed, the browser is not going to render the web page. For this reason CSS is taken into account as a render blocking useful resource. 

Right here is an easy instance to reveal the impact of imported CSS in a easy piece of HTML code, which shows some textual content and a picture. As you possibly can see, all the web page took solely round 40ms to be displayed. Even with a picture, the time taken for the web page to be displayed was much less. It is because pictures should not handled as vital sources, on the subject of making the primary paint. Bear in mind, the vital rendering path is all about HTML, CSS and JavaScript. Though we should try to get the photographs displayed as shortly as potential, they aren’t going to dam the preliminary rendering. 

loading a page with no CSSloading a page with no CSSloading a page with no CSS

Now, let’s add CSS to the piece of code.

loading a page with external CSSloading a page with external CSSloading a page with external CSS

As you possibly can see, an additional request is being fired. Though the time taken for the HTML file to load is much less, the general time for processing and displaying the web page has elevated almost tenfold. Plain HTML doesn’t contain a lot fetching and parsing. However, with a CSS file, first the HTML must be fetched, then the CSS file must be fetched, then the CSSOM (as given above) must be constructed. Each the HTML DOM and the CSS CSSOM need to be constructed. That is undoubtedly a time consuming course of.

2. Keep away from Inline Kinds

It is a golden rule for all builders. Attempt to keep away from the usage of inline types, as a lot as potential. It may be extraordinarily tempting to introduce inline types from time to time. However although it seems innocent, it’s a poor separation of issues and can be seen as an error in your coding apply. 

3. Use Inline CSS for Important Parts

We simply learn that inline types need to be prevented. Now, allow us to perceive when Inline CSS is definitely important. At all times place CSS required by the browser to finish the primary paint on the highest. This tells the browser what it wants for rendering the web page shortly. So, inlining vital CSS helps the browser full DOM and CSSOM rendering as shortly as potential. 

Important CSS is outlined because the minimal assortment of styling required by the web page, when a consumer first lands on it.

4. CSS Preprocessors

CSS Preprocessors are constructed with many utilities and instruments for modularising, avoiding repetition and organising CSS. Three generally used CSS preprocessors could be LESS, SASS and Stylus. The perfect factor about these CSS preprocessors is {that a} new means of styling shouldn’t be launched. As an alternative, you get fundamental CSS with extra options, and extra expressive syntax.

5. Stick with a CSS Methodology

Selecting the best CSS methodology on your mission will assist with upkeep and scaling. There are three CSS methodologies I can advocate: BEM, ITCSS and OOCSS.

BEM is often known as Block, Factor, Modifier methodology.

  • block represents a standalone entity or part with it is personal that means
  • aspect shouldn’t be a standalone part, however a sub-entity of the block
  • modifier is used to symbolize flags, states and look of the weather

ITCSS is inverted triangle CSS the place information are organised primarily based on specificities. As you go deeper within the triangle, you’ll grow to be extra particular. 

OOCSS is Object-Oriented CSS the place you separate the view and the construction. 

6. Use media

In case your web page has to load on each net, and cellular it’s best to make use of media queries. Additionally, it might be sensible to start with mobile-first CSS. That is broadly referred to as progressive enhancement. 

7. Compress CSS

Compressing CSS removes whitespaces, and even feedback. This reduces the general dimension of bundles. And, reduces the time taken for the browser to finish its first paint. There are a few fascinating instruments for compressing CSS. Listed here are three to start with:

8. Keep away from !essential

Have you ever heard about CSS specificity? If you’re compelled to make use of !essential, there’s a severe situation together with your CSS order or hierarchy. You can be enjoying round with inline types. Or, you might have grow to be extraordinarily particular with the selectors. Or, you is perhaps overriding types from a third social gathering library. If that’s the case, it’s best to study extra about CSS specificity, and even attempt to do away with third social gathering libraries to start with.

Specificity is a method utilized by browsers to establish the proper CSS property for a component. The ultimate consequence is dependent upon the foundations created within the code for the selectors. 

9. Watch out for Heavy CSS Properties

Trendy browsers are undoubtedly quick. Nonetheless, in case your web site is sophisticated, even the city’s quickest browser will take a while. Extensively used costly CSS properties are: filter, border-radius, and box-shadow. In truth, width and peak are comparatively costly in the event you carry out animations, and consistently change these values. Why? Each time you modify these values, the browser must recalculate the format and repaint. Each nested baby within the view can be affected by these recalculations. For this reason try to be cautious while you use these costly properties.

10. Use Shorthands

Final however definitely not least, make use of shorthands. Generally used properties like border, padding, margin and background have shorthand properties. Utilizing shorthand will allow you to type HTML markup in a extra concise method. 

By definition, a CSS shorthand is a set of CSS properties. It is possible for you to to set a replace the worth of a number of associated properties in a single line, concurrently. 

High 10 JavaScript Finest Practices

1. Place of the script Tag

More often than not, builders place their scripts on the finish of all the doc. Technically, the script tag must be current within the head. A major motive why it’s positioned on the backside, is to delay obtain and execution. The browser at all times reads and interprets a doc line by line. When it sees a script within the head, the DOM is not going to be rendered till the script is fetched and parsed. This could possibly be a protracted delay for big JavaScript information. Therefore, shifting to the underside is smart. However, there are higher methods of loading the script:


That is used when the file is essential and rendering ought to wait till the file is loaded. The browser will obtain the useful resource and execution will occur the second the useful resource is obtainable.

Deferred Loading

Whenever you use defer, the JavaScript useful resource can be downloaded whereas the HTML rendering occurs. Nonetheless, the is not going to occur as quickly because the script is downloaded. As an alternative, it waits for the HTML file to be utterly rendered.

Async Loading

Whenever you use async, you may be permitting the browser to do one thing else, whereas a JavaScript useful resource will get sdownloaded

2. No Inline Scripts

Inline scripts will make your code look dangerous. However, this isn’t the true drawback. The issue is that inline scripting will enhance the general dimension of your HTML code. Strive it out, inline your JavaScript. You will notice the scale of the code will increase. Additionally inline scripts can by no means be cached. This manner, your webpage will lose the entire idea of caching. When exterior scripts are cached, loading it for the second time turns into quicker. By including inline scripts, you possibly can by no means leverage this function present in most trendy browsers. 

So, maintain your CSS in a devoted CSS file and your JavaScript in a devoted script file.

3. Minify the Script

Whenever you publish your web site, it’s good to minify your script to cut back the general file dimension. Should you have a look at any npm bundle, you’ll come throughout two variations. One is the whole sourcecode. The opposite model ends with .min.js—the minified model. This model is not going to have any feedback, semicolons and even whitespace. All features and variable names can be changed with shorter ones. Right here is an easy instance, that will help you perceive minified JavaScript.

4. Keep away from Browser Whims

Do you’ve gotten the behavior of writing for a selected browser? If sure, this apply wants to alter. Writing code for a selected browser will certainly backfire at some point. The code will quickly grow to be out of date, and troublesome to keep up. Going across the net, you’ll come throughout many scripts that cease working with newer browser releases. The time and effort invested in constructing a web page for sure browsers will grow to be void. So develop pages to net requirements and check them throughout browsers. By no means depend on a single platform.

5. A Plan B for JavaScript

Loads of customers have turned JavaScript off of their browsers. For instance, have you learnt that the NoScript Firefox Extension has 31 million downloads at time of writing? Along with intentional disabling, many customers are unable to load JavaScript attributable to exterior circumstances. These customers haven’t any management over components like company-enforceed proxy servers, poor web entry and even overly-harsh firewalls. In such circumstances, it’s good to have a plan b. 

Remember to incorporate a <noscript> part. On this part, give a message that the consumer will see, when JavaScript shouldn’t be enabled.

6. Suppose About Accessibility

Accessibility is rarely restricted to CSS. There are a few circumstances the place JavaScript can break accessibility. If you end up designing a web page, be certain that you utilize the proper parts for the job. Additionally, content material should be out there to the consumer within the type of textual content. In a state of affairs the place you can’t management the markup, make use of WAI-ARIA to help the non-semantic JavaScript enabled widgets. And, allow the usage of keyboard controls in your script. This can assist non-mouse customers. 

WAI-ARIA is a technical specification which helps builders creates net pages which might be extremely accessible. 

7. Unobtrusive Scripting

That is an fascinating matter. Builders ought to at all times maintain obtrusive scripting in thoughts. Meaning, the present script ought to be enhanced with newer and higher functionalities. Nonetheless, all the script shouldn’t be constructed from scratch. As complicated because it sounds, it’s a sensible coding apply to not reinvent the wheel. Primary functionalities of the web page should operate, with and with out script. Nice examples of obtrusive scripting could be:

  • Construct web sites with client-side validation. Do you bear in mind the purpose, the place we harassed on fixed validation of HTML? If a consumer is getting into fallacious information within the kind, you could not look forward to server responses. As an alternative, client-side validation could be satisfactory.
  • Leverage the options of HTML5. This consists of the usage of customized controls like <video>

8. Make Use of Browser Developer instruments

This is perhaps a no brainer. However, typically we miss on the superb options provided by the fashionable developer instruments in our browsers. Whether or not it debugging a script, or a format drawback, browser developer instruments can provide a lot of data. Additionally, debugging supply code has grow to be very simple and fascinating with the newer Chromium primarily based browsers.

9. Browser Helps

Browsers have advanced drastically prior to now few years. However, that does not imply you construct options just for newer ones. New options in HTML, CSS and JavaScript won’t be out there throughout all browsers. Therefore, it’s good to check compatibility, earlier than utilizing the framework’s latest launch. For instance, if you’re planning to host a web page that could possibly be utilized by somebody with an previous browser, take into account polyfills. Older browsers do not help many new strategies like Array.consists of, Promise.allSettled and extra. In any case, realizing which options are generally out there throughout trendy browsers might be useful. The Can I Use web site is a superb useful resource to assist determine whether or not a function is widely-enough out there to be used in your software.

10. Frameworks Come Final!

Final however definitely not the least, it’s good to grasp JavaScript ideas. There are a lot of inspiring frameworks within the business. However, all these frameworks could be meaningless with out realizing JavaScript. Studying JavaScript will enhance the probabilities of you utilizing each framework to it is best. So, do not waste time on frameworks earlier than studying to code in vanilla JavaScript and CSS!


We will be happy to hear your thoughts

Leave a reply

Enable registration in settings - general