Hasty Briefsbeta

Bilingual

CSS as a Query Language

3 hours ago
  • #Web Development
  • #Datalog
  • #CSS
  • CSS basics involve selecting HTML elements (Things) and applying styles to them, but it lacks the ability to select based on styles themselves or perform recursive operations.
  • A hypothetical extension called CSSLog is proposed, inspired by Datalog, allowing recursive rules and dynamic changes to elements, such as adding classes or deriving new facts, enabling transitive queries like propagating dark mode through nested elements.
  • Datalog is a logic programming language that uses relations and rules to derive new facts recursively, similar to CSS selectors and declarations but with fixpoint semantics to handle cycles and ensure termination through monotonicity.
  • Container Queries in CSS allow querying ancestor styles but lack recursion and cannot propagate derived states transitively, highlighting limitations compared to a Datalog-like approach for complex tree-shaped data.
  • The author suggests flipping the approach: instead of adding Datalog semantics to CSS, create a new language with CSS-like syntax for recursive tree queries on data structures like JSON or ASTs, leveraging existing developer familiarity.