skip to Main Content

My xhtml book says it’s a good practice to put "/" in elements with no content, such as hr, br, input type="button", etc.

Now the code editor says "Trailing slash on void elements has no effect", something like that.

Who’s right?

2

Answers


  1. xhtml is an older standard which required closing of html tags but the current standard html5 does not require that anymore.

    Your editor is following the html5 standard and therefore does not require the tags to be closed.

    Your html file should be opening like this to see if it is following the html5 standard:

    <!DOCTYPE html>
    

    or like this if it is following the xhtml standard:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
    Login or Signup to reply.
  2. The slash at the end is useless the browser ignores it, unless you want your HTML to be compatible with XML because XHTML is different it is like HTML but with XML rules/standards, so if you don’t care about XML you can ignore it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search