Insert title here

Case Studies

Bringing your idea to life and in front of billions of eyes

HTML Best Practices You Should Follow
Html And Css (Santosh Shinde)

HTML Best Practices You Should Follow 

Most of the web pages you encounter is presented to you via HTML, the world wide web’s markup language. In this article, I will share with you 20 best practices that will lead to clean and correct markup.

  1. Always Declare a Doctype

The doctype declaration should be the first thing in your HTML documents. The doctype declaration tells the browser about the XHTML standards you will be using and helps it read and render your markup correctly.

I would recommend using the XHTML 1.0 strict doctype. Some developers consider it a tough choice because this particular standard is less forgiving than loose or transitional doctype declarations, but it also ensures that your code abides strictly by the latest standards.

DTD XHTML 1.0 Strict//EN" "">

  1. Use Meaningful Title Tags

The  tag helps make a web page more meaningful and search-engine friendly. For example, the text inside the  tag appears in Google’s search engine results page, as well as in the user’s web browser bar and tabs.

Take for instance, the following example:

Six Revisions - Web Development and Design Information

The example above appears like the following image in Google’s search engine results page:

  1. Use Descriptive Meta Tags

Meta tags make your web page more meaningful for user agents like search engine spiders.

Description Meta Attribute

The description meta attribute describes the basic purpose of your web page (a summary of what the web page contains). For each web page, you should place a consise and relevant summary inside the meta description tag.

For example, this description:


Shows up in Google’s search engine results page as follows:

Don’t try to spam your description with repeated words and phrases because search engines are intelligent enough to detect that. Instead, just try to be simple and straightforward in explaining the purpose of your web page.

Keywords Meta Attribute


The keywords meta attribute contains a comma-separated list of key words and phrases that relate to your web page. These keywords make your web page even more meaningful.

Again, just like with the description meta attribute, avoid repetition of words and phrases; just mention a few words that aptly describes and categorizes your web page.

  1. Use Divs to Divide Your Layout into Major Sections

Consider dividing your web page into major sections as the first step in constructing a website design.

Doing so from the start promotes clean and well-indented code. It will also help you avoid confusion and excess use of divs, especially if you are writing complex and lengthy markup.

  1. Separate Content from Presentation

Your HTML is your content. CSS provides your content’s visual presentation. Never mix both.

Don’t use inline styles in your HTML. Always create a separate CSS file for your styles. This will help you and future developers that might work on your code make changes to the design quicker and make your content more easily digestible for user agents.

Bad Practice: Inline Styles

Below, you can see a paragraph element that is styled using the style attribute. It will work, but it’s bad practice.


  1. Minify and Unify CSS

A simple website usually has one main CSS file and possibly a few more for things like CSS reset and browser-specific fixes.

But each CSS file has to make an HTTP request, which slows down website load times.

A solution to this problem is to minify (take out unneeded characters such as spaces, newlines, and tabs) all your code and try to unify files that can be combined into one file. This will improve your website load times.

A problem with this approach is that you have to “unminify” (because it’s hard to read unformatted code) and then redo the minification process every time you need to update your code. So it’s better to do this at the end of your production cycle.

Online tools to minify and optimize CSS can be found on this list of CSS optimizers.

Also, always put your stylesheet reference link inside the  tags because it will help your web page feel more responsive while loading.

  1. Minify, Unify and Move Down JavaScript

Like CSS, never use inline JavaScript and try to minify and unify your JavaScript libraries to reduce the number of HTTP requests that need to be made in order to generate one of your web pages.

But unlike CSS, there is one really bad thing about external JavaScript files: browsers do not allow parallel downloads, which means the browser cannot download anything while it’s downloading JavaScript, resulting in making the page feel like it’s loading slowly.

So, the best strategy here is to load JavaScript last (i.e. after your CSS is loaded). To do this, place JavaScript at the bottom of your HTML document where possible. Best practice recommends doing this right before the closing  tag.


  1. Use Heading Elements Wisely

Learn to use 


 elements to denote your HTML’s content hierarchy. This helps make your content more meaningful for screen-reading software and search engines, as well as other user agents.


This is the topmost heading

This is a sub-heading underneath the topmost heading.

This is a sub-heading underneath the h2 heading.

For blogs, I really recommend using the 

 element for the blog post’s title instead of the site’s name because this is the most important thing for search engines.

WordPress Code Example


9.Use the Right HTML Element at the Right Place

Learn about all the available HTML elements and use them correctly for a semantic and meaningful content structure.

Use  for emphasis and  for heavy emphasis, instead of  or  (which are deprecated).


emphasized text

strongly emphasized text


 for paragraphs. Don’t use 
 to add a new line between paragraphs; use CSS margin and/or padding properties instead.

For a set of related elements, use:

    • (unordered lists) when the order of the list items are not important
    1. (ordered lists) when the order of the list items are important
  • (definition lists) for item/definition pairs

Don’t use 

 for indentation purposes; use it when actually quoting text.
  1. Don’t Use Divs for Everything

Sometimes developers end up wrapping 

 tags around multiple 
 tags that contain more 
 tags, creating a mountain of divs.

Under the latest draft of the W3C HTML specification, a 

 is a meaningless element that should be used “as an element of last resort, for when no other element is suitable.”

But many use it even for menial things like displaying inline elements as block elements (instead of the display:block; CSS property).

Avoid creating mountains of divs by using them sparingly and responsibly.

  1. Use an Unordered List (
      ) for Navigation

Navigation is a very important aspect of a website design and the 

     element combined with CSS makes your navigation menus semantic (because, after all, a navigation menu is a list of links) as well as beautiful.

Also, by convention, an unordered list for your navigation menu has been the accepted markup.

An Example of an Unordered List



  • Home



  • About



  • Portfolio



  • Services



  • Blog



  • Contact Us



CSS to Style the Unordered List into a Horizontal Navigation Bar

 #main_nav { position:absolute; right:30px; top:40px;}

                                #main_nav li { float:left; margin-left:2px; }

                                #main_nav li a{ font-size:16px; color:#fff; text-decoration:none; padding:8px 15px; -moz-border-radius:7px; -webkit-border-radius:7px; border-radius:7px;}

                                #main_nav li,

                       #main_nav li a:hover{  background-color:#0b86cb;  }


  1. Close Your Tags

Closing all your tags is a W3C specification. Some browsers may still render your pages correctly (under Quirks mode), but not closing your tags is invalid under standards.





some sample text


  1. Use Lower Case Markup

It is an industry-standard practice to keep your markup lower-cased. Capitalizing your markup will work and will probably not affect how your web pages are rendered, but it does affect code readability.

Bad Practice




some sample text


Good Practice




some sample text


  1. Use Alt Attributes with Images

Using a meaningful alt attribute with  elements is a must for writing valid and semantic code.

Bad Practice

alt="brg_logo.png" />

Good Practice

alt="Six Revisions Logo" />

15.Use Title Attributes with Links (When Needed)

Using a title attribute in your anchor elements will improve accessibility when used the right way.

It is important to understand that the title attribute should be used to increase the meaning of the anchor tag.

Bad Practice

When a screen reader reads the anchor tag, the listener has to listen to the same text twice. What’s worse is that it doesn’t explain what the page being linked to is.

If you are just repeating the anchor’s text or aren’t intending to describe the page being linked, it’s better not to use a title at all.

Good Practice

  1. Use Fieldset and Labels in Web Forms

Use the 

. Name a 
 using . All of this will make your forms more understandable for users and improve the quality of your code.



    Personal Details






17.Use Modular IE Fixes

You can use conditional comments to target Internet Explorer if you are having issues with your web pages.

IE 7 Example

IE 6 Example

However, try to make your fixes modular to future-proof your work such that when older versions of IE don’t need to be supported anymore, you just have to update your site in one place (i.e. take out the reference to the ie-6.css stylesheet).

By the way, for pixing PNG transparencies in IE6, I recommend the DD_belated PNG script (the JavaScript method referenced above).

18.Validate Your Code

Validation should not be the end-all evaluation of good work versus bad work. Just because your work validates doesn’t automatically mean it’s good code; and conversely, a work that doesn’t fully validate doesn’t mean it’s bad (if you don’t believe me, try auto-validating Google or Yahoo!).

But auto-validation services such as the free W3C markup validation service can be a useful debugger that helps you identify rendering errors.

While writing HTML, make a habit to validate frequently; this will save you from issues that are harder to pinpoint (or redo) once your work is completed and lengthier.

  1. Write Consistently Formatted Code

A cleanly written and well-indented code base shows your professionalism, as well as your consideration for the other people that might need to work on your code.

Write properly indented clean markup from the start; it will increase your work’s readability.

  1. Avoid Excessive Comments

While documenting your code, the purpose is to make it easier to understand, so commenting your code logic is a good thing for programming languages like PHP, Java and C#.

But markup is very much self-explanatory and commenting every line of code does not make sense in HTML/XHTML. If you find yourself commenting your HTML a lot to explain what is going on, you should review your work for semantics and appropriate naming conventions.


Add Comment     See All Comments
nfl nike authentic jerseys the bar silk twist dress los angeles dodgers fitted hat lyrics leopard shirt outfit boston red sox hat flex fit black kit name nike air vortex retro hairulafiz
nike air jordan caps 2016miami dolphins crochet hat pattern zombiemonster energy hats blue cross blue shieldwashington nationals flat cap rooms fausto slip ons wholesale nike jordan hat loki midi dress in powder bluemini dress slipwedding attire for plus size ladiesnike blazer white outfit nike free run 4 blanc nike air vapormax flyknit gray yellowadidas originals tubular radial grigionike downshifter 8 mens gold pink shoesnike air max 2014 blanco naranja verde negro lacarspotting
football trikot steelersgoat wearing tom brady jerseyceltic kit 2014patrick marleau penguins jersey coach signature jacquard walletcoach brass chain strapmichael kors iphone 6 casecoach swagger shoulder bag 20 air jordan true flight blanco and rojo knit newsboy hat pattern baby youtube mohamed salah egypt national team jerseyneymar football kit juniorchelsea team shirttrae young shirt jersey blue flowy dress shorttraditional chinese kimono dressenza costa ribbed dressred and black ball gown wedding dress stevedekay
2022 nfl alternate helmetsmichael jordan washington jerseycole caufield jersey adidassalute to service hoodie dolphins atelier versace 2015 boots sketchers womens sneakers rosalie leather slingback sandalslouboutin high top trainerschristian louboutin slingbackbottom of heels red new christian louboutin shoes miami heat fitted hats new era lyricslos angeles angels halo hat gamestexas rangers oakley hat repairtexas rangers smu hat 50 mirkurortov
michael kors mercer pebbled leather accordion crossbody not rated wedge sneakers packers nike apparel nfl cleveland browns hover helmet dallas cowboys cancer cap michael kors voyager tote blue emrefirin

Tech Divinity cloud enable faster performance