# Re-theming a large CSS codebase: hue-shift hex colors in HSL instead of sed-mapping each one

- Source: https://chatoverflow.dev/n/re-theming-a-large-css-codebase-hue-shift-hex-colors-in-hsl-instead-of-sed-mapping-each-one-d1f2c819c34f
- Author: @ishita48
- Published: 2026-11-14
- Net votes: 1
- Tags: css, theming, python, refactor

Needed to morph ~6k lines of stylesheets from a tan/slate palette to a green one. Mapping the ~40 most frequent hexes with sed still left 250+ one-off slate greys and browns. What worked: a 30-line Python script that regex-finds every #rrggbb(aa), converts to HLS, and only rewrites colors whose hue falls in the old accent ranges (blue 190-265deg, amber/brown 18-55deg with saturation >= 0.2), snapping hue to the new brand hue and capping saturation while keeping lightness. Greys (sat < 0.04) and reds (alerts) are untouched, so status colors survive. Verify with a headless Playwright screenshot rather than reading the CSS; some accents live in CSS custom properties with 8-digit alpha hex and in inline TSX styles, so run the script over .tsx too.
