frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Show HN: I made Logic gates using CSS if() function

https://yongsk0066.github.io/css_if_logic_gate/
72•yongsk0066•4d ago

Comments

webdevver•11h ago
cant wait to hang pages with ring oscillators
mmastrac•10h ago
I'm a little behind on my CSS, but apparently you can now evaluate styles in the container and act on them, at least in Chrome:

https://developer.chrome.com/blog/new-in-chrome-137

The example uses a newer `style(..)` condition I haven't seen yet:

https://developer.mozilla.org/en-US/docs/Web/CSS/@container#...

I'm curious if you can accidentally make loops using some of these, and if there's some sort of settling/recursion limit.

EDIT: Apparently `style(..)` can only evaluate vars in this `if()`? It looks like `@container` is a way to manage generic style queries and that supports the full gamut of CSS queries.

https://developer.mozilla.org/en-US/docs/Web/CSS/if

  A @container query does have some advantages — you 
  can only set single property values at a time with
  if() style queries, whereas @container queries can
  be used to conditionally apply whole sets of rules.
  The two approaches are complementary, and have
  different uses.

  Note that container style queries currently don't
  support regular CSS properties, just CSS custom 
  properties. For example, the following won't work: [..]
EDIT 2: OK, this required digging out the spec. They cannot cause recursion because of the substitution context rules:

https://drafts.csswg.org/css-values-5/#if-notation

  For example, in --foo: if(style(--foo: bar): baz);
  the style() query is automatically false, since
  property replacement has already established a 
  «"property", "--foo"» substitution context. "
... and there are rules around cyclic evaluation in CSS:

https://drafts.csswg.org/css-values-5/#cyclic-substitution-c...

  When a cycle is detected, all participants in the cycle
  become invalid. For example, all of the following 
  declarations become invalid at computed-value time."
Phew.
jordanscales•10h ago
I assume this is not more powerful computationally than existing selectors, right? What exactly keeps CSS+HTML from being Turing-complete?
shakna•10h ago
If you include the user clicking, then it already is. [0]

[0] https://github.com/brandondong/css-turing-machine

cluckindan•10h ago
Nothing. Given infinite memory, a NAND gate is Turing complete by itself and trivial to construct based on the OP examples.
csmantle•7h ago
Unfortunately the examples provided by OP only contain combinational circuits, which by def. have no memory.
cluckindan•4h ago
Well, there are half and full adders, maybe a flip-flop would be feasible?
amelius•7h ago
Ok, so NoScript should also block (parts of) CSS now, and not just JavaScript?
cdaringe•7h ago
I’m going to assume this is a joke. However, if it’s not a joke, no. We as a community have gone to great lengths to use responsive design over the past few years. There are still styling cases for complex elements that can’t be implemented without JavaScript. This is just an additional step of the journey to allow intermediate styling for complex cases.

If anything, it should enable (minor) expansion of noscript!

cdaringe•7h ago
Id actually like to redact that prior message and think further, here. We already have information egress thru URIs, with some amount of “protection” via CSP. But I didn’t think of other types of attack vectors at length. Someone above remarked that this is just a general form of conditional, which perhaps unlocks new vectors. Im always surprised by CSS so i should slow down and keep an open mind :)
zamadatix•6h ago
It lacks a usable form of pure-CSS recursion (which was intentionally excluded in this implementation) but that's not as big a problem as one would expect for a lot of practical things.
Dylan16807•6h ago
Basic arithmetic plus iteration is Turing complete. CSS has basic arithmetic but not iteration.

Some people have already claimed it's Turing complete by making the user hit tab and space to copy data between iterations, but I wouldn't listen to them. That copying role is simple but it's not negligible.

montroser•10h ago
Neat. But side note: do we really need if() in CSS? Like, the complexity that adds is going to be worth the functionality it brings? It's introducing a whole new paradigm to solve what real problem?
cluckindan•9h ago
See the MDN examples:

https://developer.mozilla.org/en-US/docs/Web/CSS/if

I for one would much rather use local conditionals than do the logical equivalent through conditionally set CSS variables. It is much more readable and extendable than several layers of abstraction (design token vars -> semantic vars -> theme vars potentially complexed by media/container queries -> element styles).

Of course I wouldn’t replace all of that, but if() would certainly make many things easier to grok for the next guy. Just don’t overuse it.

alwillis•8h ago
We already have specialized conditionals in CSS, such as @supports, minmax, media queries, etc.

if() is just a general purpose conditional.

Using if() is going to reduce complexity for a whole range of use cases. Right now, developers are using custom property hacks to simulate true conditionals [1].

[1]: "The --var: ; hack to toggle multiple values with one custom property"—https://lea.verou.me/blog/2020/10/the-var-space-hack-to-togg...

masterj•5h ago
JS is inherently single-threaded and mobile cores aren't really getting faster, but we are getting more of them. Allowing you to express more in CSS means you get faster-loading, more highly-performant, less energy-draining web UIs.
franky47•9h ago
Soon it’ll be shift registers, ALUs, and before we know it we’ll have DOOM in CSS.
Mtinie•9h ago
Not exactly what you are asking for but we’re moving closer to your vision of the future:

https://github.com/yurkagon/Doom-Nukem-CSS

Show HN: I wrote a "web OS" based on the Apple Lisa's UI, with 1-bit graphics

https://alpha.lisagui.com/
219•ayaros•4h ago•69 comments

Show HN: Simple wrapper for Chrome's built-in local LLM (Gemini Nano)

https://github.com/kstonekuan/simple-chromium-ai
18•kstonekuan•5h ago•1 comments

Show HN: Pixel Art Generator Using Genetic Algorithm

https://github.com/Yutarop/ga-pixel-art
13•ponta17•8h ago•7 comments

Show HN: AI-Powered SLA Breach Predictor for Jira (Open Source, Python)

https://github.com/aroojjaved93/AI-Powered-Ticket-Routing-SLA-Breach-Prediction-in-JIRA
2•aroojjaved•3h ago•0 comments

Show HN: I made a crowd counting game

https://crowdle.xyz/
3•3yanlis1bos•3h ago•2 comments

Show HN: Pelyos – A calm, minimal task manager for clarity and focus

https://pelyos.app/
2•pavelparma•3h ago•0 comments

Show HN: I made Logic gates using CSS if() function

https://yongsk0066.github.io/css_if_logic_gate/
72•yongsk0066•4d ago•18 comments

Show HN: a community for collaborating on sideprojects

https://relentlessly.no/
34•0dKD•4d ago•24 comments

Show HN: Kuqu: SQL for Kubernetes Resources

https://github.com/ynqa/kuqu
2•aqny•7h ago•0 comments

Show HN: Guess the Sharpe

https://guessthesharpe.in
3•sankethchebbi•7h ago•0 comments

Show HN: Comically – TUI manga and comic optimizer for e-readers

https://github.com/nicoburniske/comically
3•nicoburniske•8h ago•3 comments

Show HN: GraphFlow – A lightweight Rust framework for multi-agent orchestration

https://github.com/a-agmon/rs-graph-llm
2•alonagmon•8h ago•0 comments

Show HN: ParsePoint – AI OCR that pipes any invoice straight into Excel

https://parsepoint.app
2•marcinczubala•9h ago•1 comments

Show HN: Chat Capsule – Convert ChatGPT Chats to Markdown (For Notion, etc.)

https://chat-capsule.com/
3•bekoeppel•9h ago•0 comments

Show HN: AirBending – Hand gesture based macOS app MIDI controller

https://www.nanassound.com/products/software/airbending
88•bepitulaz•2d ago•22 comments

Show HN: Virby, a vfkit-based Linux builder for Nix-Darwin

https://github.com/quinneden/virby-nix-darwin
3•qeden•11h ago•0 comments

Show HN: BunkerWeb – the open-source and cloud-native WAF

https://docs.bunkerweb.io/latest/
101•bnkty•2d ago•30 comments

Show HN: I AI-coded a tower defense game and documented the whole process

https://github.com/maciej-trebacz/tower-of-time-game
302•M4v3R•2d ago•150 comments

Show HN: From Photos to Positions: Prototyping VLM-Based Indoor Maps

https://arjo129.github.io/blog/5-7-2025-From-Photos-To-Positions-Prototyping.html
4•accurrent•23h ago•0 comments

Show HN: Fast Thermodynamic Calculations in Python

https://dlr-institute-of-future-fuels.github.io/gaspype/
58•Saloc•2d ago•11 comments

Show HN: A cross-platform terminal emulator written in Java

https://github.com/sebkur/forceterm
63•sebkur•5d ago•20 comments

Show HN: HomeBrew HN – Generate personal context for content ranking

https://www.hackernews.coffee/
123•azath92•3d ago•48 comments

Show HN: Lush extends Lua with string interpolation and other useful features

https://crates.io/crates/lush
2•thiagomg•16h ago•2 comments

Show HN: MCP-123, a 2-line MCP server/client (Windows-friendly)

https://github.com/Tylersuard/MCP-123
14•tylersuard•1d ago•1 comments

Show HN: Spots – Map of good places to work remotely for the day

https://spots-9a3a718d1c74.herokuapp.com/
7•bcbernstein•18h ago•5 comments

Show HN: ASCII Fireworks

https://asciifireworks.com/
17•theli0nheart•1d ago•0 comments

Show HN: YouTube Shorts Blocker Chrome Extension

https://chromewebstore.google.com/detail/youtube-shorts-blocker/efamilphiiimpohdgneapebopkcjlilp
3•krispycreame•7h ago•1 comments

Show HN: A continuation of IRS Direct File that can be self-hosted

https://github.com/openfiletax/openfile
244•elijahwright_•6d ago•33 comments

Show HN: Tinykv – Minimal file-backed key-value store for Rust

https://crates.io/crates/tinykv
24•hasanyildiz•2d ago•6 comments

Show HN: Jobs by Referral: Find jobs in your LinkedIn network

https://jobsbyreferral.com/
174•nicksergeant•5d ago•64 comments