Add an option to prefer void tags over self closing tags.
See original GitHub issueUpdate:
I have change my opinion on this, and I don’t think I require this any more. If this is ever implemented I would probably use it, but I really don’t mind this behavior at all. If you want to read more, I wrote a post in dev.to
Original post:
Prettier 1.14.3 Playground link
# Options (if any):
Input:
<input type="button">
Output:
<input type="button" />
Expected behavior: I would like an option to prefer void element tags over the current implementation of self-closing element tags. I understand why is this the default behavior, as this is xml compatible, but several style guides suggest the usage of void tags as they are valid HTML5 tags. As I understand in the option philosophy, if there is enough usage from developers there is a justification to add the option.
Style Guides:
- https://google.github.io/styleguide/htmlcssguide.html#Document_Type
- http://codeguide.co/#html-syntax
- http://www.codestyle.co/Guidelines/html
- https://github.com/gocardless/html-style-guide
# Options:
--prefer-void-tags=true
<input type="button">
Issue Analytics
- State:
- Created 5 years ago
- Reactions:253
- Comments:121 (34 by maintainers)
Top Results From Across the Web
What are the allowed ways to close self-closing tags for void ...
According to the specification you link to: "Void elements only have a start tag; end tags must not be specified for void elements",...
Read more >I changed my opinion about Prettier not formatting void ...
I open an issue to give support to an option because I was against this behavior. Several guide styles about HTML recommend void...
Read more >Restrict "self-closing" tags to only void elements in ... - Drupal
Updated: #174 Problem/Motivation drupal_pre_render_html_tag() is not specific in allowing which tags can be void (no closing tag).
Read more >Self-Closing Tags in HTML [Guide] - Treehouse Blog
TL;DR: In HTML5 it is not strictly necessary to close certain HTML tags. ... Let's take a look at some more examples. Optional...
Read more >vue/html-self-closing
enforce self-closing style. ... The style of well-known HTML elements except void elements. html.component ( "always" by default) .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think we need option. I think we should print this as in source code, i.e. if you have
<input type="button" />
print this as is.Why:
prettier
, here should be used linter to avoidHTML
errors.I went even deeper.
When searching for “html style guide” and “html best practice”, these were the serious results (and I am not nit-picking):
https://google.github.io/styleguide/htmlcssguide.html#Document_Type https://contribute.jquery.org/style-guide/html/ https://www.w3schools.com/html/html5_syntax.asp https://github.com/hail2u/html-best-practices#dont-mix-empty-element-format https://developer.mozilla.org/en-US/docs/MDN/Guidelines/Code_guidelines/HTML
and none of them use self-closing tags.
Even the same doc specifying it as valid doesn’t use it: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
Furthering my case of it being a weird thing to do.
Surely this is unexpected for beginners and whoever just trying out prettier. It sure was for me.
And surely the cost of this disruption, beginners and alike, is greater than to support XML / XHTML? Is there any point of XHTML nowadays?
It seems to me like it should be an option to have the old XML / XHTML behaviour, as it seems to be this way due to “because of history” and “compatibility reasons”, as said in the options philosophy.
It is also the third highest upvoted html issue now, if that has any weight.