<!DOCTYPE html><html lang="en"> <head> <base href="/cheerio/" /> <meta charset="utf-8" /> <meta name="description" content="Post-process the resulting HTML with Cheerio to move inline styles into the head." /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="color-scheme" content="dark" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link rel="stylesheet" href="/index.css?v=mwqv51qv" /> <link rel="stylesheet" href="/cheerio/index.css?v=mwqv51qv" /> <link rel="canonical" href="https://expo.jeasx.dev/cheerio" /> <script type="module" src="/index.js?v=mwqv51qv"></script> <title>Extract inline styles with Cheerio » Jeasx - JSX with Ease</title> <style> .c0 { --heading: orange; } .c1 { text-align: center; } .c2 { color: orange; } .c3 { color: var(--muted); } </style> </head> <body> <header class="shell-header"> <nav class="container"> <ul> <li> <a href="/" class="shell-brand" ><span class="shell-gradient">Jeasx</span> Expo</a > </li> <li><a href="/" class="shell-back">← All examples</a></li> </ul> <ul> <li> <a href="https://github.com/jeasx/jeasx-expo/tree/main/src/cheerio" class="shell-source" title="View source code" ><img src="/github-GDUVNX2O.svg" width="20" height="20" alt="" /><span>Source</span></a > </li> </ul> </nav> </header> <main class="container"> <section class="cheerio-hero c0 c1"> <h1>Extract inline styles with Cheerio</h1> <p class="lead"> Jeasx lets you post-process the finished HTML with a <a href="https://www.jeasx.dev/faq#response-handler" >response handler</a >. This example uses <a href="https://cheerio.js.org">Cheerio</a> to turn all inline styles into CSS classes in the head of the page. </p> </section> <ol class="cheerio-steps"> <li> <strong class="c2">Render</strong ><span>JSX produces HTML full of inline style attributes.</span> </li> <li> <strong class="c2">Collect</strong ><span >Cheerio finds each declaration; identical ones share a single class.</span > </li> <li> <strong class="c2">Rewrite</strong ><span >Classes go into one style tag in the head and Prettier formats the result.</span > </li> </ol> <p class="c1 c3"> Compare the original and the rewritten markup of this very page below. </p> <div class="compare"> <figure class="compare-item"> <figcaption> <i></i><i></i><i></i>Original source<em>before</em> </figcaption> <iframe title="Original source" src="?view=code&source=raw" ></iframe> </figure> <figure class="compare-item"> <figcaption> <i></i><i></i><i></i>Rewritten markup<em>after</em> </figcaption> <iframe title="Rewritten markup" src="?view=code"></iframe> </figure> </div> </main> <footer class="container shell-footer"> <p> <a href="https://www.jeasx.dev">jeasx.dev</a ><span aria-hidden="true">·</span ><a href="https://github.com/jeasx/jeasx-expo">GitHub</a> </p> <p>© 2026 · powered by Jeasx on Node@26.13.1</p> </footer> </body></html>