<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro" -->

---
title: From URL to Theme: How {css2r} Steals a Website’s...
description: ThinkR built {css2r}, an R package and Shiny app (Shiny Copy) that scrapes a website's CSS to auto-generate a bslib::bs_theme() call matching the site's brand...
canonical: https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: From URL to Theme: How {css2r} Steals a Website’s Colours, and Where It Gives Up | daily.dev
og:description: ThinkR built {css2r}, an R package and Shiny app (Shiny Copy) that scrapes a website's CSS to auto-generate a bslib::bs_theme() call matching the site's brand...
og:url: https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro
og:image: https://api.daily.dev/og/posts/NUwSatRRO.png
og:image:alt: From URL to Theme: How {css2r} Steals a Website’s Colours, and Where It Gives Up
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# From URL to Theme: How {css2r} Steals a Website’s Colours, and Where It Gives Up

**[R-bloggers](https://daily.dev/sources/rbloggers)** · 14 min read · 0 upvotes · 0 comments

## Summary

ThinkR built {css2r}, an R package and Shiny app (Shiny Copy) that scrapes a website's CSS to auto-generate a bslib::bs_theme() call matching the site's brand colours. It works by downloading same-domain stylesheets, extracting six-digit hex codes via regex, splitting neutrals from brand colours, and assigning bg/fg/primary/secondary by frequency and luminance. Testing it against real sites (ThinkR's own site, Le Monde, Posit, Tailwind CSS, Stripe) reveals three failure modes: CSS served from a different CDN domain is invisible (total failure on Stripe), only six-digit hex is parsed so rgb(), hsl(), three-digit hex and CSS custom properties (var(--...)) are ignored (missing ~40% of colour data and failing entirely on modern design systems like Tailwind and Posit), and frequency is a poor proxy for brand identity since the most common colour is usually neutral text/border grey rather than the actual brand colour (Le Monde's blue ranks 10th, ThinkR's own orange ranks 3rd and is dropped). The team's fix is a human-in-the-loop UI letting users click alternate swatches, though this doesn't help when the correct colour never makes the shortlist. The post ends with a roadmap of improvements: ranking by chroma instead of count, normalising colour notations, reading inline styles, resolving CSS custom properties, and adding contrast checks.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.r-bloggers.com/2026/09/from-url-to-theme-how-css2r-steals-a-websites-colours-and-where-it-gives-up>

## Questions this post answers

### Why does a CSS colour-frequency extraction tool pick the wrong brand colour on a company website?

Frequency is a poor proxy for brand identity because the most common colour in a stylesheet is almost always interface plumbing like body text or border grey, not the brand colour. On ThinkR's own site, the dark slate grey #38404C appeared 133 times and was picked as primary, while the actual brand orange #F05622 appeared only 40 times and ranked third, getting dropped from the generated theme entirely.

_Anyone automating brand theming in Shiny apps can follow practical write-ups like this on daily.dev._

### Why does a website's CSS colour scraper fail completely on sites like Stripe that use a CDN subdomain?

The scraper filters stylesheets to same-domain links only, so when all CSS is hosted on a separate CDN subdomain such as b.stripecdn.com instead of stripe.com, every stylesheet gets discarded and extraction returns nothing. This affects most large organisations that serve assets from dedicated CDNs, since a plain domain-string comparison cannot bridge genuinely different domains.

_Developers debugging cross-domain asset filtering issues can find grounded examples like this on daily.dev._

### Why do regex-based CSS colour extractors miss colours defined with CSS custom properties (var(--...))?

A simple regex matching six-digit hex codes counts each colour only where the literal hex value appears, but modern design systems declare a brand colour once in a custom property like --brand-primary: #F05622 and reference it thousands of times via var(--brand-primary). The frequency counter then sees that brand colour only once, while a grey hardcoded inline across fifteen legacy components scores fifteen, inverting the true importance ranking.

_Teams evaluating CSS parsing approaches for design-system tooling can track these gotchas on daily.dev._

## Similar posts on daily.dev

- [Building user-customizable themes with Tailwind CSS](https://daily.dev/posts/building-user-customizable-themes-with-tailwind-css-fcgbgtxmt) · RUBYLAND · 33 upvotes · 6 comments
- [Dynamic Colour Schemes With Modern CSS](https://daily.dev/posts/dynamic-colour-schemes-with-modern-css-unbd3csjb) · Always Twisted · 5 upvotes · 0 comments
- [A few ways of specifying per-theme colours in only CSS — Chris Morgan](https://daily.dev/posts/a-few-ways-of-specifying-per-theme-colours-in-only-css-chris-morgan-yeihwzack) · Lobsters · 0 upvotes · 0 comments
- [Tailwind CSS v4 Dynamic Themes with CSS Variables](https://daily.dev/posts/tailwind-css-v4-dynamic-themes-with-css-variables-g2jkzxglo) · SitePoint · 30 upvotes · 0 comments
- [Algorithmic Theming Engines: Building Self-Correcting Color Systems With contrast-color\(\) — Smashing Magazine](https://daily.dev/posts/algorithmic-theming-engines-building-self-correcting-color-systems-with-contrast-color-smashing-afte9iv44) · Smashing Magazine · 4 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css), [#r](https://daily.dev/tags/r), [#crawling](https://daily.dev/tags/crawling)

[View this post on daily.dev](https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"From URL to Theme: How {css2r} Steals a Website’s Colours, and Where It Gives Up","url":"https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro"},"datePublished":"2026-09-18T20:52:28.888Z","dateModified":"2026-09-18T20:52:58.469Z","description":"ThinkR built {css2r}, an R package and Shiny app (Shiny Copy) that scrapes a website's CSS to auto-generate a bslib::bs_theme() call matching the site's brand...","image":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","thumbnailUrl":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","isAccessibleForFree":true,"articleSection":"R-bloggers","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"R-bloggers","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/98bcbbdf72774292a55ceda8f2277f1e","url":"https://daily.dev/sources/rbloggers"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css,r,crawling","timeRequired":"PT14M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"R-bloggers","item":"https://daily.dev/sources/rbloggers"},{"@type":"ListItem","position":3,"name":"From URL to Theme: How {css2r} Steals a Website’s Colours, and Where It Gives Up"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/from-url-to-theme-how-css2r-steals-a-website-s-colours-and-where-it-gives-up-nuwsatrro#faq","mainEntity":[{"@type":"Question","name":"Why does a CSS colour-frequency extraction tool pick the wrong brand colour on a company website?","acceptedAnswer":{"@type":"Answer","text":"Frequency is a poor proxy for brand identity because the most common colour in a stylesheet is almost always interface plumbing like body text or border grey, not the brand colour. On ThinkR's own site, the dark slate grey #38404C appeared 133 times and was picked as primary, while the actual brand orange #F05622 appeared only 40 times and ranked third, getting dropped from the generated theme entirely. Anyone automating brand theming in Shiny apps can follow practical write-ups like this on daily.dev."}},{"@type":"Question","name":"Why does a website's CSS colour scraper fail completely on sites like Stripe that use a CDN subdomain?","acceptedAnswer":{"@type":"Answer","text":"The scraper filters stylesheets to same-domain links only, so when all CSS is hosted on a separate CDN subdomain such as b.stripecdn.com instead of stripe.com, every stylesheet gets discarded and extraction returns nothing. This affects most large organisations that serve assets from dedicated CDNs, since a plain domain-string comparison cannot bridge genuinely different domains. Developers debugging cross-domain asset filtering issues can find grounded examples like this on daily.dev."}},{"@type":"Question","name":"Why do regex-based CSS colour extractors miss colours defined with CSS custom properties (var(--...))?","acceptedAnswer":{"@type":"Answer","text":"A simple regex matching six-digit hex codes counts each colour only where the literal hex value appears, but modern design systems declare a brand colour once in a custom property like --brand-primary: #F05622 and reference it thousands of times via var(--brand-primary). The frequency counter then sees that brand colour only once, while a grey hardcoded inline across fifteen legacy components scores fifteen, inverting the true importance ranking. Teams evaluating CSS parsing approaches for design-system tooling can track these gotchas on daily.dev."}}]}
```

