RepositoryHTMLCACanada
GN

gnat/css-scope-inline

🌘 Scope your inline style tags in pure vanilla CSS! Only 16 lines. No build. No dependencies.

696stars
18forks
2issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: inline-css

#1 Repository of the month

1
TINIX TRENDING·Topic: lob

#1 Repository of the month

1
TINIX TRENDING·Topic: scoped-css

#1 Repository of the month

🌘 CSS Scope Inline

cover (Art by shahabalizadeh)

Why does this exist?

  • You want an easy inline vanilla CSS experience without Tailwind CSS.
  • Hate creating unique class names over and over.. to use once.
  • You want to co-locate your styles for ⚡️ Locality of Behavior (LoB)
  • You wish this would work in ` red
    green
    green
    green
    yellow
    blue
    green
    green
red
green
green
green
yellow
blue
green
green
```

Variables and child elements example.

At first glance, Tailwind Example 2 looks very promising, but:

  • 🔴 Every child style requires an explicit selector.
    • Tailwinds' shorthand advantages start to disappear.
    • Tailwind becomes larger than vanilla CSS when more child elements are added.
    • This limited example is the best case scenario for Tailwind.
  • 🔴 Not visible on github: no highlighting for properties and units becomes painful.


    
        
        
        
    
    
        <!-- CSS Scope Inline -->
        <div>
            
            <div><a href="#">Home</a></div>
            <div><a href="#">Team</a></div>
            <div><a href="#">Profile</a></div>
            <div><a href="#">Settings</a></div>
            <div><a href="#">Log Out</a></div>
        </div>

        <!-- Tailwind Example 1 -->
        <div class="mx-2 my-4">
            <div><a href="#" class="block py-2 px-3 my-2 bg-[--color-1] rounded-lg text-center hover:bg-[--color-1-active] hover:text-white">Home</a></div>
            <div><a href="#" class="block py-2 px-3 my-2 bg-[--color-1] rounded-lg text-center hover:bg-[--color-1-active] hover:text-white">Team</a></div>
            <div><a href="#" class="block py-2 px-3 my-2 bg-[--color-1] rounded-lg text-center hover:bg-[--color-1-active] hover:text-white">Profile</a></div>
            <div><a href="#" class="block py-2 px-3 my-2 bg-[--color-1] rounded-lg text-center hover:bg-[--color-1-active] hover:text-white">Settings</a></div>
            <div><a href="#" class="block py-2 px-3 my-2 bg-[--color-1] rounded-lg text-center hover:bg-[--color-1-active] hover:text-white">Log Out</a></div>
        </div>

        <!-- Tailwind Example 2 -->
        <div class="mx-2 my-4
            [&_div_a]:block [&_div_a]:py-2 [&_div_a]:px-3 [&_div_a]:my-2 [&_div_a]:bg-[--color-1] [&_div_a]:rounded-lg [&_div_a]:text-center
            [&_div_a:hover]:bg-[--color-1-active] [&_div_a:hover]:text-white">
            <div><a href="#">Home</a></div>
            <div><a href="#">Team</a></div>
            <div><a href="#">Profile</a></div>
            <div><a href="#">Settings</a></div>
            <div><a href="#">Log Out</a></div>
        </div>
    

🔎 Technical FAQ

  • Why do you use querySelectorAll() and not just process the MutationObserver results directly?
    • This was indeed the original design; it will work well up until you begin recieving subtrees (ex: DOM swaps with htmx, ajax, jquery, etc.) which requires walking all subtree elements to ensure we do not miss a <style>. This unfortunately involves re-scanning thousands of repeated elements. This is why querySelectorAll() ends up the performance (and simplicity) winner.

🌘 Change Log

1.1.0

  • Started change log.
  • Fix for domain names ending in .me when used url() properties.

Similar Projects

Discover other similar projects and AI models.

RepositoryMDX
thedaviddias/Front-End-Checklist

🗂 The essential checklist for modern web development, for humans and AI agents

74.9k
Oct 31, 2026
RepositoryJavaScript
haizlin/fe-interview

前端面试每日 3+1,以面试题来驱动学习,提倡每日学习与思考,每天进步一点!每天早上5点纯手工发布面试题(死磕自己,愉悦大家),6000+道前端面试题全面覆盖,HTML/CSS/JavaScript/Vue/React/Nodejs/TypeScript/ECMAScritpt/Webpack/Jquery/小程序/软技能……

26.2k
Oct 26, 2025
Repository
The-Cool-Coders/Project-Ideas-And-Resources

A Collection of application ideas that can be used to improve your coding skills ❤.

17.3k
Oct 16, 2026
RepositoryJavaScript
twbs/bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

175.1k
Dec 1, 2026
RepositoryC++
electron/electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

124.3k
Dec 2, 2026
Repository
florinpop17/app-ideas

A Collection of application ideas which can be used to improve your coding skills.

98.8k
Oct 11, 2025
RepositoryJavaScript
microsoft/Web-Dev-For-Beginners

24 Lessons, 12 Weeks, Get Started as a Web Developer

97.2k
Dec 1, 2026
RepositoryJavaScript
h5bp/html5-boilerplate

A professional front-end template for building fast, robust, and adaptable web apps or sites.

57.7k
Dec 2, 2026
RepositoryCSS
jgthms/bulma

Modern CSS framework based on Flexbox

50.0k
Nov 24, 2026