How To Write Better HTML, JavaScript, CSS And PHP

If you run a website, then you are a coder to some extent. You might not identify yourself as such – you probably think of yourself more as a writer or a designer – but in fact if you run a site then looking at and editing code is a part of your job and is a very important way to improve your business.

Become a better coder and you will be able to run a better website. You’ll be able to make smarter changes to your site more efficiently, your visitors will get more from going there, and you’ll make more money as a result.

Here then we will look at some of the things you can do to start coding better so that your site can really thrive…

Use a Good Editor

Good old Notepad can handle most of the requirements you’ll need for writing code for a website, but that doesn’t mean that you shouldn’t look elsewhere as well. Better editors will give you more options (letting you find and replace across whole folders for instance), they’ll use colour coding and they’ll help you to find those annoying errors that prevent things from working. This is even more important when you’re working with PHP, in which case a good coding environment will prevent you from having to upload your files to your servers every time you want to test them. A bad workman blames his tools, but a workman with lousy tools is destined to be bad…

Use Comments

Comments are incredibly useful if you have a large page of code that you need to navigate and can save you a huge amount of time that will allow you to spend more time writing great content, responding to your e-mails and coming up with new features, design elements and menus.

Comments should let you know precisely what it is that a section of code does so that you’re never left staring blankly at a page of numbers without knowing what to do next. At the same time though, you can also use them as a great place to jump quickly to the section you need by using the search function in your editor. Use comments then that act as ‘headings’ for sections, and then consider creating a key at the top so you can quickly jump wherever you need to go. Even if you think that the code is going to stay small this can be a good idea – you never know how these pages are going to grow.

Delete as You Go

That said, if you’re the sort of person who likes to keep ‘commenting out’ your old code (turning it into a comment instead of deleting it to prevent it from taking effect), then you need to stop commenting and start deleting. Otherwise you will end up making the file unnecessarily large and more difficult to search through.

Use Smart Variables

In Java and PHP you might find yourself using variables and cookies which allow you to assign names to particular values. Here you need to make sure that you are using a logical system to name your variables so that you can quickly figure out what they each do and so you aren’t forced to wrack your brain trying to remember what each variable is called.

For instance, if you are using a string to store a password, don’t call it ‘userpass’, call it ‘passcode’ because you’re more likely to use that. Better yet, when using Booleans (values that can either be ‘true’ or ‘false’), try to make sure that they make sense when used as a sentence. For instance: ‘If passwordcorrect then echo’. This way anyone who looks at your code will know instantly what it means.


It can also help to remain generally consistent throughout your coding. This means making sure that you phrase things in the same way and that you use the same formatting. A simple example is your AdSense – each time you include an AdSense unit on your page, use the same style and the same exact text as that way you’ll be able to simply find and replace it with a tool like Dreamweaver when you want to swap it for a different kind of add or remove the adverts altogether.

All this will help you to code in a way that’s simple, logical and easy to navigate – meaning you waste less time searching and spend more time making great content.

The author of this post, John Miller, is an employee at WebFirm, a company that offers SEO services. He has a very dynamic personality and he enjoys interacting with people.

Mars Cureg

Web designer by profession, photography hobbyist, T-shirt lover, design blog founder, gamer. Socially and physically awkward, lack of social skills, struggles to communicate with anyone who doesn't have a keyboard. Willing to walk to get to the promised land. Photo and video freelancer, SEO. Check out more on my Google+

You may also like...