Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing Tags vs. Boolean Attributes: Guidance Seems To Contradict Intent #11

Open
RunnerRick opened this issue Aug 2, 2017 · 3 comments

Comments

@RunnerRick
Copy link

The guidance for HTML closing tags and boolean attributes seems to be contradictory.

I'm referring to this text:

From https:/thenerdery/html-css-standards/blob/master/standards/html.md#closing-tags:

Closing Tags

All elements should be closed via a tag pair or self closing declaration.

From https:/thenerdery/html-css-standards/blob/master/standards/html.md#boolean-attributes:

Boolean Attributes

Boolean attributes should not have a value.

I assume the reason you would want empty elements (i.e. <input>, <br>) to be "self closing" (e.g. <input />, <br />) is so that an XML parser would parse the HTML source as a well-formed XML document.

However, if boolean attributes "should not have a value," then an XML parser would not consider the document well-formed. See https://stackoverflow.com/questions/6926442/is-an-xml-attribute-without-a-value-valid.

I can see the reason for dropping the value from boolean attributes, because it saves bytes, but if that is the reason, then you should also drop the self-closing declaration.

In other words it seems consistent to use either boolean attribute values with self-closing declarations or drop them both:

<input type="checkbox" selected="selected" />

OR

<input type="checkbox" selected>

NOT

<input type="checkbox" selected />

With that said, I'm open to learning the reasoning behind the guidance.

@ccheney
Copy link
Contributor

ccheney commented Aug 2, 2017

I don't think there's a technical reason to self-close void tags if the doctype isn't xhtml. This standard is in place not to save bytes, but for readability and consistency amongst developers who are writing html.

@RunnerRick
Copy link
Author

Thanks for the clarification.

@noahblon
Copy link
Contributor

noahblon commented Feb 6, 2018

I agree with Rick. Self closing tags in HTML5 is a strange choice. It is not in line with industry convention and harms readability.

@noahblon noahblon reopened this Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants