use: <tag-name></tag-name>
ANY tagname with a dash is a valid HTMLElement
Let me repeat that for clarity:
๐ ANY ๐คฏ tagname with a dash is a valid HTMLElement
NOT HTMLUnknownElement
as some claim
That means you can replace EVERY <div>
with Semantic HTML
Then this DIV-soup:
Becomes Semantic HTML:
๐ง Good to know
โ Absolutely NO JavaScript required, its only HTML and CSS
โ
This is standard behaviour in all browsers since 2020
(When Microsoft Edge switched to the Chromium Engine)
and already in Chrome, Safari, Firefox many moons before 2020
โ
The Browsers default stylesheet defines CSS [hidden] { display:none }
.
But Custom Elements do not inherit the default stylesheet;
so you have to add that behaviour yourself in your stylesheet.
โ
<DIV>
is display:block
only in the default stylesheet
You have to set ๐๐๐จ๐ฅ๐ก๐๐ฎ: ๐๐ก๐ค๐๐ / ๐๐ฃ๐ก๐๐ฃ๐-๐๐ก๐ค๐๐ ; on these elements yourself
(You will forget this 20 times, then you never make the mistake again)
โ CSS :๐๐๐๐๐ฃ๐๐ targets standard HTML tags and JavaScript defined Custom Elements
โ
Thus CSS :๐ฃ๐ค๐ฉ(:๐๐๐๐๐ฃ๐๐) targets the ๐ช๐ฃ๐๐๐๐๐ฃ๐๐ elements
they are still valid HTMLElement
, CSS applies like any element
โ
<you-are-not-bound-to-one-dash>
โ
Declarative ShadowDOM:
<template shadowrootmode="open">
creates undefined Custom Elements (with a shadowDOM)
๐๐๐
No more hunting for that closing </div>
tag
</tag-name>
is just there!
Are they Web Components?
Technologies NOT used:
<template>
- shadowDOM
- Custom Elements API (create defined elements with JavaScript)
๐ Prove ANY tagname with a dash IS a HTMLElement
for:
<div></div>
<tagname></tagname>
<tag-name></tag-name>
<tag-name-foo></tag-name-foo>
<tag-name-bar></tag-name-bar>
NO MORE DIV-SOUP!
Top comments (0)