Code-to-text ratio measures the proportion of visible text content versus HTML code on a web page. A higher ratio generally indicates that a page delivers more content relative to its markup overhead.
Code-to-text ratio is calculated by dividing the amount of rendered text content by the total size of the HTML source code. A page with 10KB of text content and 100KB of HTML has a 10% ratio. Excessive code bulk from inline styles, JavaScript, unnecessary divs, and bloated frameworks reduces this ratio.
While code-to-text ratio is not a confirmed direct ranking factor, pages with very low ratios often have underlying issues that do affect SEO — slow load times, poor crawlability, or thin content. A very low ratio can indicate pages stuffed with code and lacking meaningful content, or pages where content is loaded via JavaScript rather than being present in the HTML.
Improve code-to-text ratio by minifying HTML, CSS, and JavaScript, removing unnecessary markup and inline styles, using external stylesheets instead of inline CSS, eliminating redundant wrapper divs, and ensuring substantive text content is present in the initial HTML. Use SEO auditing tools that report this metric to identify pages that need cleanup.
Want to learn more? Explore our SEO Glossary or check out our expert guides on SEO strategies.