What a slash is part of

On page 68 of the fifth edition of PHP & MYSQL: NOVICE TO NINJA is the following.

<div><input type=”submit” value=”GO”></div>

On page 72 is the following.

<div><input type=”submit” value=”GO”/></div>

They are the same, except for an additional slash on page 72. What does this slash do?

The slash is html4. Without is html5

1 Like

The trailing slash is an html4 mandatory self closing of an empty element, or a replaced like the img element. In html5 it became optional.

As @benanamen already said. :slightly_smiling_face:

In HTML(all releases), the input element is an empty element; it requires no closing slash.

In XHTML, the input element requres a closing slash as do all empty elements.

If the code is correct then page 68 should be within an HTML context and the example on page 72 should be within an XHTML context OR an HTML5 context. HTML5 specs tolerate the XHTML closing slash.

The example that you are showing shows “smart quotes” (curly quotes) which are not acceptable in any coding language of which I am aware. Please be aware of details and replicate carefully :wink: .

2 Likes

Thanks for the clarification and correct info. :blush:

According to the specs:
HTML4: Empty elements do not use a trailing slash in their tag. It is invalid.*
HTML5: A trailing slash in an empty element is allowed.
XHTML: The trailing slash in an empty element is required.

*) Parsing html4: a trailing slash in an empty element is ignored. Thus the occasional advice to always put a trailing slash in empty elements just to be safe does no harm:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.