-1

Here are my HTML test codes using Google HTML/CSS guide.

<table>
    <thead>
      <tr>
        <th>Date
        <th>Country
    <tbody>
      <tr>
        <td>24/07/2018
        <td>Myanmar
      <tr>
        <td>31/06/2018
        <td>France
  </table>

The following is how browser interprets it.

<table>
     <thead>
        <tr>
          <th>Date
          </th>
          <th>Country
          </th>
        </tr>
      </thead>
      <tbody>
         <tr>
            <td>24/07/2018
            </td>
            <td>Myanmar
            </td>
         </tr>
          <tr>
            <td>31/06/2018
            </td>
            <td>France
            </td>
          </tr>
       </tbody>
    </table>

Here is my questions.

  • How the browser detect the lack of closing tag and how they interprets it.

  • It is preferable to use without closing elements? If it is, when should I use?

  • If it is not preferable, why?
  • Will it be impact on styling and adding interactivity on HTML semantic style?
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

Answers:

  1. This is beyond the scope of SO, but just like any compiler detects something that opened is not closed. You can try and program something that identifies a valid bracket series, it would probably be similar.
  2. Not using closing elements may break your page beyond being horribly un-maintainable. Always use closing elements.
  3. See 2.
  4. See 2.

Browsers sometimes can guess what you meant (better say, they parse luckily in a way that produces what you meant), but might also be wrong. See this:

<div>Hello<span>world

is this:

<div>Hello</div><span>world></span>

or

<div>Hello<span>world></span></div>

both are valid, and the browser has no idea which you meant. If you really want to get into how browsers are supposed to parse HTML, see this great link by @modu and @kalido: http://w3c.github.io/html/syntax.html#tokenization . You may be able to workout how a browser should parse the above line.

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • There is a set of rules for browsers to follow: http://w3c.github.io/html/syntax.html#tokenization But we all know they won't follow them the same way. – Gökhan Mete ERTÜRK Jul 26 '18 at 07:26
  • @modu Yup I am familiar. I do not think SO is the appropriate place to list them, but I will add your great suggestion as a reference. – kabanus Jul 26 '18 at 07:26
  • @kabanus Thanks for sharing knowledge. I will look up to the resources – Ko_phayaung Jul 26 '18 at 08:05