Live data from Hacker News

You can make up HTML tags

maurycyz.com

11–20 of 202 posts

Re: You can make up HTML tags

#12

  
  
  
  
  ... a bunch more HTML ...
  
  
  
  
Just one quibble over this specific example (not the broader concept, which is sound): it probably didn’t have to be div soup to begin with. Something like this may have been more reasonable:

  
  
  
... a bunch more HTML ...

Re: You can make up HTML tags

#13

As someone who writes html only rarely (I'm more of a "backend" guy, and even use that term loosely.. most of my webdev experience dates back to the CGI days and often the html was spat out by Perl scripts) and usually in vim, I am pleased to know there is an in-built solution outside of me properly indenting or manually counting divs. Thanks for enlightening me.

A more common alternative to counting divs would be CSS classnames or (for unique elements on the page) IDs. You'd do `document.querySelector('.my-class')` to locate `` or similar, rather than using the fact that e.g. something is nested 3 divs inside .

Even if this custom element trick didn't work, I don't see why one would need to count divs (at least if you control the markup, but if not then made-up tags aren't an option anyway). The article even mentions using class names as an option.

Re: You can make up HTML tags

#14
Wow, this is great, unlocks lots of freedom. I was under the impression that this was not possible, maybe through web components or .

As a side note, I’ve been going through all the HTML elements slowly to learn the fundamentals, and it turns out that lots of elements are just a or , with different default styles and default ARIA things.

And a is just a with display block…

This and TFA both help me to realize HTML is pretty darn simple.

Re: You can make up HTML tags

#15
post #3

You sure can! They all have inline defaults like ` ` so set some CSS baseline on them as needed, but this is like the best kept secret of HTML or something? Unknown tags will become `HTMLUnknownElement` and behave like a span. Edit: the reason for avoiding this in the past was name-spacing. But the standard says you can use a hyphen and then you're OK, native elements won't ever use a `-`. Edit 2: also it's great bec…

Nitpick: If a nonstandard element name contains a hyphen (and is otherwise a syntactically valid custom element name), the element's DOM object is an instance of HTMLElement, not HTMLUnknownElement.

Quoth the standard: "The use of HTMLElement instead of HTMLUnknownElement in the case of valid custom element names is done to ensure that any potential future upgrades only cause a linear transition of the element's prototype chain, from HTMLElement to a subclass, instead of a lateral one, from HTMLUnknownElement to an unrelated subclass."

Re: You can make up HTML tags

#17
post #14

Wow, this is great, unlocks lots of freedom. I was under the impression that this was not possible, maybe through web components or . As a side note, I’ve been going through all the HTML elements slowly to learn the fundamentals, and it turns out that lots of elements are just a or , with different default styles and default ARIA things. And a is just a with display block… This and TFA both help me to realize HTML is…

[deleted]

Re: You can make up HTML tags

#18
post #14

Wow, this is great, unlocks lots of freedom. I was under the impression that this was not possible, maybe through web components or . As a side note, I’ve been going through all the HTML elements slowly to learn the fundamentals, and it turns out that lots of elements are just a or , with different default styles and default ARIA things. And a is just a with display block… This and TFA both help me to realize HTML is…

> And a is just a with display block…

It's a bit more subtle than that. HTML5 defines "Content Models", two of which are 'Phasing Content' and 'Flow Content'. Phasing Content can only contain text and text-like tags (em, strong, bold) whereas Flow Content can contain anything.

Technically is defined as accepting Phrasing Content and accepts Flow Content. Changing this with CSS doesn't change the content model.

Although browsers are very forgiving so it all works anyways and this is very in the deep end, I can't think of the last time I've consciously thought of this stuff.

https://html.spec.whatwg.org/#the-span-element

https://html.spec.whatwg.org/#the-div-element

https://html.spec.whatwg.org/#content-models

Re: You can make up HTML tags

#19
post #13

As someone who writes html only rarely (I'm more of a "backend" guy, and even use that term loosely.. most of my webdev experience dates back to the CGI days and often the html was spat out by Perl scripts) and usually in vim, I am pleased to know there is an in-built solution outside of me properly indenting or manually counting divs. Thanks for enlightening me.

A more common alternative to counting divs would be CSS classnames or (for unique elements on the page) IDs. You'd do `document.querySelector('.my-class')` to locate ` ` or similar, rather than using the fact that e.g. something is nested 3 divs inside . Even if this custom element trick didn't work, I don't see why one would need to count divs (at least if you control the markup, but if not then made-up tags aren't…

Sorry, I didn't mention class names because the article explicitly did and I assumed that my aversion to the extra typing would be presumed by a reader of my comment. My mistake.

So yeah, I guess what wasn't obvious from my statement of gratitude was that I appreciate knowing that there is a more concise way of keeping track - even without CSS styling. If I make up tags, they will just inherit default styling but to my eye I can be clear about where things are closed, and where to insert things later. I was talking about the manual editing (in vim, as I mentioned), rather than any dynamic query selectors. Make more sense?

Re: You can make up HTML tags

#20

https://lit.dev/ That's the premise behind Lit (using the custom elements api)! I've been using it to build out a project recently and it's quite good, simpler to reason about than the current state of React imo. It started at google and now is part of OpenJS.

I just evaluated Lit for work and while we didn't go with it, it was very nice. I love the base custom elements API regardless of using Lit or not, turns out that's all you really need to make intricate UIs that feel seamless.

Something about Lit/web components that's not written clearly on the label is the hoops you have to jump through to style elements. If you're using tailwind in the whole app, you just want to pull it into your custom elements without much boilerplate. My main app compiles a single minified app.css, it felt not so modular to now include that in every single component. The alternative is create a subclass that injects tailwind into Lit components. It'd be perfect it just had a switch to inherit everything the page already has.
Post reply on HN