-1

<div> tags are display: block per default. <span> tags are display: inline per default. Could there be a tag that is display: flex per default? I don't mean a class, like bootstrap has. I mean a tag, like <flex>. Or better yet, a <row> and a <column> tag with the corresponding directions set per default. I've heard that defining your own tags could have a lot of unforeseen side effects and is considered bad practice. So I'm asking, is there any chance it could become part of official html? Who is in charge of this? Is there a place one can submit proposals? I know that it is probably not considered "semantic", but nesting 15 divs for layout reasons isn't semantic either imo.

4
  • I assume flex refers to flexbox. I'm not seeing how you can support much of the functionality of flexbox without a stylesheet. Of course, new tags can and are added to the spec but I'm not seeing a lot of value with this. Maybe I'm missing something.
    – JimmyJames
    Commented Nov 30, 2023 at 17:38
  • HTML doesn't care how elements are rendered. HTML does care about the context in which elements can appear, for example "flow content" or "phrasing content". There is no separate "flexbox content" category, instead flow content and thus <div> would be appropriate here. See MDN or the WHATWG spec on content categories for details. If you really want you can create a custom element, just remember that its name must contain a hyphen.
    – amon
    Commented Dec 1, 2023 at 1:44
  • @JimmyJames I would like to read html and get a rough idea of what the website looks like. Knowing that an element is a row or a column would help me.
    – Lycodo
    Commented Dec 1, 2023 at 18:53
  • @Lycodo You can create a basic table with rows and columns using flexbox but you realize that it can do much more than that, right? HTML already has tables so I'm still not sure what this would accomplish.
    – JimmyJames
    Commented Dec 1, 2023 at 19:13

2 Answers 2

6

This question is wildly in need of focus, but most of the questions have an easy answer.

  1. Who is in charge of this? The W3C.
  2. Is there a place to submit proposals? Yes. See the link above.

The first question and your comment about these tags not being semantic is an answerable question, in my opinion.

Over the years, the HTML spec has continually removed presentational elements and attributes in favor of semantic attributes. Your quip about "not being semantic" is precisely why tags like <flex>, <column>, and <row> will not likely ever be a part of the HTML spec. The meanings of those words are inherently presentational in nature.

CSS already provides a more expressive and flexible means to style HTML. The language is built specifically for style. HTML has evolved into a language defining data and structure of a document, with ECMA Script providing behavior. Separating these aspects of a web page allows languages to be designed that solve problems specific to styling (think: flexbox, colors, floats, position, etc), data meaning and structure (think: html) and application behavior (e.g. ECMA Script). These languages can be specialized and evolved independently as the web ecosystem changes.

Plenty of developers, frameworks and applications define their own tags and attributes. The HTML standard does leave room for custom elements. Custom attributes are also supported with the data- prefix.

All of these recommendations and "best practices" center on the ability to change the HTML spec in the future without impacting code you have written. You could argue that a custom element called <compass> is not a good idea. Maybe some future HTML spec will include this tag to render a compass in the browser. Will your custom element mean the same thing? It's a judgement call. You could also argue that a <stackoverflow> tag is safe to use. What are the odds that the W3C will add a website-specific tag to a general markup language? Probably not likely, and it would be safe to use if you have a genuine use case for it.

2
  • While arguing from your custom/wanted semantics about the likelihood of the element ever being included with any semantics is fundamentally unsound, that one making it still seems supremely unlikely. Commented Nov 30, 2023 at 18:40
  • Regarding custom elements, the convention is the name contain a dash, since the HTML spec promise to never introduce a new element with a dash in its name. So <stack-overflow> would be safe to use, but <stackoverflow> would not.
    – JacquesB
    Commented Dec 1, 2023 at 20:27
1

Just add this to your stylesheet:

flex { display: flex; }

And now you have a <flex> element you can use as you want.

There is the tiny risk that HTML in the future might introduce an element called flex with a different purpose, which might break your pages. To be safe, you should use an element name containing a dash, e.g. <flex-box>, since the HTML standard promises never to introduce a new element with a dash in its name.

HTML is unlikely to add an element like <flex> to the official standard though. You are right that <div> and <span> only differ in presentation and has no additional semantics. But they were introduced to HTML before CSS support were widespread, as a way to add styles without breaking the layout in a browser which didn't support CSS. This is not a relevant concern anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.