By Craig Buckler

Does Your Text to Code Ratio Matter?

By Craig Buckler

A page’s text to code ratio is a measure of the quantity of content compared to the structure. For example, assume your page is 1,000 bytes. If 700 bytes are used for HTML tags and embedded CSS or JavaScript, 300 bytes would be readable content. You would have a text ratio of 3:7 or percentage of 30%. There are many tools to help you assess the figure — one of the easiest to use is DOM Monster.

But is there an ideal text to code ratio?

Search Engine Optimization

Some SEO experts claim that higher text ratios improve search engine positions. I’ve even seen 42% stated as a magical perfect percentage which will boost your Google PageRank. However, I suspect that number’s been plucked by an SEO snake oil “specialist” with a Hitchhiker’s Guide to the Galaxy obsession.

Personally, I don’t believe the text to code ratio has a significant impact on SEO. That said, Google ignores content beyond the first 100Kb so larger pages could benefit from a higher text ratio. However, if you’re exceeding 100Kb, I’d suggest splitting documents into several more focused pages would be a more constructive SEO exercise.

Code Efficiency

In general, it’s best practice to use the least amount of code possible. Unnecessary tags incur additional page weight, slower downloads and more inefficient browser rendering. It also makes your code harder to maintain.

If your pages are lightweight and use clean, semantic HTML with external CSS and JavaScript files, your text to code ratio will naturally fall. There are a few exceptions:

  • Shorter pages will have a low text ratio because you require a minimum number of code elements to create a valid HTML document.
  • Media-heavy pages, such as a gallery with images or videos, typically have low text ratio.
  • Flash or Ajax-powered web applications may not have any content whatsoever — but it’s still there.

In general though, a text to code ratio which exceeds 50% is achievable on
most content pages.

So should we, as conscientious developers, measure our text to code ratios?

If you’re already using good coding techniques, there’s little need to bother. You could use it as a factor when measuring efficiency since a good developer will generally have a higher text to code ratio. However, ratios should never be considered in isolation. After all, a page scoring 25% which works everywhere is usually better than one which scores 50% but fails in most browsers.

Do you consider your page’s text to code ratios? Do you use it to evaluate your own performance?

The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account