logoalt Hacker News

CSS Web Components for marketing sites (2024)

89 pointsby zigzag312today at 3:15 PM40 commentsview on HN

Comments

spankaleetoday at 4:53 PM

I'm a big web components guy, but calling these web components is a massive stretch of the word component.

The word "component" has to mean something ultimately, and to me the defining feature of a web component is that it's self-contained: it brings along its own dependencies, whether that's JavaScript, templates, CSS, etc. Web components shouldn't require an external framework or external CSS (except for customization by the user) - those things should be implementation details depended on directly by the component.

This here is just CSS using tag names for selectors. The element is doing nothing on its own.

Which is fine! It's just not web components.

edit: Also, don't do this:

    <link-button>
      <a href="">Learn more</a>
    </link-button>
That just adds HTML bloat to the page, something people with a singular focus on eliminating JavaScript often forget to worry about. Too many HTML elements can slow the page to a crawl.

Use classes:

    <a class="button" href="">Learn more</a>
They're meant for this, lighter weight, and highly optimized.
show 6 replies
hawkticehursttoday at 5:45 PM

Author of the blog post here! Since this blog post, I put this idea to practice on the VS Code website (https://code.visualstudio.com/) to create all the interactive graphics on the homepage. Which is a slightly different use case than what I described in the post, but cool and effective none-the-less.

What woud have been a soup of `div` elements with various class names are now more meaningfully named elements like `<top-bar>`, `<chat-container>`, etc. that were mixed and remixed to create all the graphics.

Also no issues regarding performance that we've seen up to this point, which makes sense; browsers are very good and fast at rendering HTML elements (native or custom).

show 1 reply
kelvindegreestoday at 5:27 PM

Is this not exactly what DaisyUI (https://daisyui.com) is?

dgb23today at 5:45 PM

I like that the author came to the idea by cross pollination via web components.

However, it's basically describing the "modifiers" part of BEM, which is a pattern that emerged from structuring CSS. Neither custom element or attributes are needed, even though they might feel different.

If you like that kind of pattern to structure CSS, then combining it with custom CSS properties (often called "variables", example: --block-spacing: 2rem) makes it even more modular. These properties follow the cascade rule.

hyperhellotoday at 4:33 PM

The reason fixing ads from the inside won’t work is that they are designed to disrupt. An ad that ruins your scrolling for three seconds is preferable to one that ruins your scrolling for 2.5 seconds. All ads are designed to wreck the environment that they are in, to create a space for irrationality to enter.

vayliantoday at 4:34 PM

I've never been deep into XSLT, but I kind of have the impression, that this would have solved the issue.

senfiajtoday at 5:14 PM

I'm not a fan of these custom elements. Unless you do something really interactive, dynamic and reusable (an element with complex behavior), I don't think it's worth to use them. The SEO / accessibility becomes more challenging. Also, worth to noting, web components require JS, so they are not pure "CSS" web components. Web components are useful for isolation, when used with shadow DOM.

show 1 reply
Zardoz84today at 7:19 PM

Using a expression from Spain : Es mas viejo que el cagar.

pier25today at 4:34 PM

Why not just use CSS?

show 2 replies