Skip to the content
Start free

Code-to-text ratio

Code-to-text ratio is the share of a web page’s file size that is visible, readable text, compared with the HTML, CSS, JavaScript and markup around it. A page that weighs 200 KB with 10 KB of words has a ratio of about 5%. Google does not publish this number as a ranking signal, but a very low ratio often points to slow, bloated pages and thin words.

What is code-to-text ratio? #

Open any page and view its source. You see the words a reader reads, wrapped in tags, scripts, style rules, tracking code and data. The ratio sets those two parts side by side. Some tools call it text-to-HTML ratio. There is no standard formula: most audit tools strip the tags from the HTML, count the bytes of text that remain and divide by the bytes of the whole document. Some count only the HTML file. Others add the CSS and scripts it loads. That is why two tools give two different figures for the same page.

Is it a Google ranking factor? #

No official Google document lists it as one. Google’s SEO starter guide states that how long a page is makes no difference to ranking on its own, and that no ideal word count exists. A ratio is just word count divided by file size, so treat it as a symptom to look into, not a ranking factor to chase. A short product page with a clear price can be perfect at 3%.

The ratio is useful because of what usually sits behind a bad score:

  • Crawl limits. Google’s Googlebot documentation sets a 2MB cap on each supported file it fetches, and that cap applies to the file before compression. Anything after that cut-off is not sent for indexing. A page stuffed with inline code can push its real words past the limit.
  • Each file counts alone. The same page says every CSS and JavaScript file is fetched separately and has the same limit.
  • Speed. More code means more to download, parse and run, which hurts Core Web Vitals and page speed.
  • Thin pages. A template with a heavy menu, footer and pop-ups but two lines of copy is often thin content.

Why does it matter for AI answers? #

An AI crawler wants the words. Text that only appears after scripts run can be missed by any crawler that does not run JavaScript; see client-side vs server-side rendering. Clean, text-first HTML is easier to split into passages, which helps content chunking and retrieval-augmented generation. Some sites also offer a plain copy of each page for machines, the idea behind llms.txt. Our Markdown Version Checker tests whether a page has one.

How does it work? #

A simple version takes three steps:

  1. Download the HTML of the page and note its size in bytes.
  2. Remove every tag, script block, style block and comment, then collapse the white space.
  3. Divide the bytes of text left by the bytes of the full file and multiply by 100.

The result swings with things that have nothing to do with quality: inline SVG icons, JSON-LD blocks for schema markup, cookie banners and page builder wrappers all add code. That is fine when the code does a job.

How do I raise it the right way? #

  • Minify. MDN’s minification entry describes it as removing unnecessary or redundant data without changing how the browser processes the file, such as comments and white space. See minification.
  • Move inline CSS and scripts to files. The browser can cache them, and they stop crowding the HTML. Load scripts with async or defer.
  • Cut the DOM. Chrome’s Lighthouse DOM size audit warns when the body has more than about 800 nodes and flags an error above about 1,400.
  • Remove dead plugins and tags. Every old tracking script adds weight.
  • Add useful words, not filler. Answer the questions buyers ask. Padding to move a ratio is keyword stuffing by another name.

Does compression change the ratio? #

Not the ratio itself, but it changes what travels over the wire. The web.dev article on text compression says gzip and Brotli work best on text files such as HTML, CSS and JavaScript, and that minification and compression add up. Google’s 2MB limit is on the uncompressed file, so compression helps speed but does not lift that limit. See text compression.

Common mistakes #

  • Chasing a target. There is no official “good” figure. Compare pages of the same type on your own site.
  • Deleting useful code. Structured data, hreflang tags and a canonical tag lower the ratio but earn their place.
  • Hiding text. Adding text people cannot see breaks Google’s spam policies; see cloaking.
  • Words only in scripts. If the text is built by JavaScript, the raw HTML ratio looks tiny and some crawlers see nothing. Read JavaScript SEO.

A worked example #

One shop compares 3 page types:

Page HTML size Text size Ratio What to do
Blog guide 90 KB 18 KB 20% Fine
Product page 240 KB 4 KB 1.7% Move 150 KB of inline script to a file
Category page 2.4 MB 6 KB 0.25% Over Google’s 2MB crawl limit: cut inline SVG and data

The category page is the urgent one. Its last products may never be indexed.

How to check it #

  1. Run the page through our SEO Checker or a full SEO audit to see size, headings and words together.
  2. Put the same address into our JavaScript SEO Checker: it shows which words exist before any script runs.
  3. Check the response headers and compression with our HTTP Header Checker, then time the load on our Page Speed Checker (coming soon).
  4. Test how easy the words are to read with our Readability Checker.
  5. Ask whether AI systems can read the text with our AI Readiness Checker.
  6. In URSY Pro, the asset diet report (Pro) lists the heaviest files, and the JavaScript rendering check (Pro) watches pages over time.

Questions #

What is a good code-to-text ratio? #

There is no official number. Look for outliers: pages far below others of the same type.

Will raising it lift my rankings? #

Not by itself. Faster pages and better answers can help; the ratio only points at them.

Does schema markup hurt the ratio? #

It lowers the figure, but it gives machines facts. Keep it if it matches the page.

Sources #

Updated 25 November 2026 by URSY.

Cite this page: Code-to-text ratio. URSY. Updated 25 November 2026. https://ursy.com/wiki/code-to-text-ratio/ · Section links

Tools for this

  • LiveImage SEO Checkeralt text, AVIF/WebP, sizes and licence markupRun the check →
  • LivePrompt Injection Checkerhidden text or planted AI instructions on a pageRun the check →
  • LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
  • LiveAI Bot Checkerwhich AI bots your robots.txt lets inRun the check →
  • LiveRobots.txt Checker + Generatortest any address against your rules, or write new onesRun the check →
  • LiveSchema Markup CheckerRun the check →
  • ProImage SEO auditAlt text, sizes, formats, image sitemapsIn URSY Pro →
  • ProAI shopping feedsOpenAI feed, AI catalogue text, JSONL, knowledge graph from your shopIn URSY Pro →
  • ProRead-to-click ratioAI reads vs Google clicksIn URSY Pro →

All 871 wiki entries, A to Z →