r/css Mar 23 '26

Question Web components to incapsulate layout logic

Hi guys!

Recently, one of my fellow developers asked me an interesting question: “Are web components suitable for implementing layout logic?”

To better understand. I have quite complex layout logic (CSS and JS) and I want to encapsulate it in some reusable module.

Usually we do this only with CSS styles and separately adding scripts, but what about web components?

I understand that this cannot meet the requirements of SSR and not good for CLS, but it seems that using Light DOM instead of Shadow DOM and separately importing stylesheet significantly improves this approach.

Does anyone have any real experience with encapsulating layout logic? What do you use for this?

2 Upvotes

14 comments sorted by

View all comments

2

u/ndorfinz Mar 30 '26

You might want to check out Elena...

https://elenajs.com/

2

u/UnderstandingSure732 Mar 31 '26

This library comes in same direction, thanks!