Space Before Closing Slash

Space Before Closing Slash?

The answer is people wish to adhere to Appendix C of the XHTML1.0 specification. Which you only need to do if you are serving XHTML as text/html. Which most people do, because XHTML's real MIME type (application/html+xml) does not work in Internet Explorer.

No current browser cares for the space. Browsers are very tolerant of these things.

The space used to be required to ensure HTML parsers treated the trailing slash as an unrecognised attribute.

XML formatting conventions: Why leave a space before / ?

It is likely done to be safe with XHTML XML, which requires the space in some early XHTML browsers.

Better answer: Space Before Closing Slash?

How to prevent VS Code from adding space before self-closing JSX tag?

To my knowledge there is no such formatting option within the javascript.format options. But you can always look into extensions for this kind of job.

A lot of people use Prettier these days, but it is opinionated and there is no guarantee it will work well with all your ESLint options. It has an ESLint integrationn though, so maybe you want to have a look at this.

You can also have a look at react-beautify, which seems to have an option for this. But I am not familiar with this extension.

Do we still need the space before the slash in hr / and others?

According to the HTML5 specs, void elements don't need the self closing / character.

Their exact phrasing is

Then, if the element is one of the
void elements, or if the element is a
foreign element, then there may be a
single U+002F SOLIDUS character (/).
This character has no effect on void
elements, but on foreign elements it
marks the start tag as self-closing.

They list void elements as area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

I may be understanding it wrong, but that seems like the following are all valid for html5

<hr>
<hr/>
<hr />

So it seems it really depends on the doctype you use

Is a closing script tag valid with a space in it?

go to jsFiddle website and test it out.

  <script>
window.onload(document.write("success"))
</script>

and afterwards just put a space into the closing tag.
you can also close the tag like this:

  <script>window.onload(document.write("success"))/>


Related Topics



Leave a reply



Submit