? HTML5 has tags that must have start and end tags, even if...">

Why should some HTML5 tags have start and end tags instead of closing them with / ">?

HTML5 has tags that must have start and end tags, even if their contents are empty:

<script></script>   <!-- Right way. -->
<div></div>         <!-- Right way. -->
<content></content> <!-- Right way. -->

<script/>  <!-- Wrong way. -->
<div/>     <!-- Wrong way. -->
<content/> <!-- Wrong way. -->

In XML, this difference does not exist: <node/>and <node></node>- it is one and the same entity.

Why type of tag script, divand contentcan not simply be defined as follows: <script/>, <div/>and <content/>?

+4
source share
5 answers

From w3c :

. . , . HTML, . , . XHTML . , , .

, , , JavaScript , /.

+4

, "" .

, , img base, /" > , .

+2

( void) />

area, base, br, col, embed, hr, img, input, keygen, link, menuitem, meta, param, source, track, wbr

:

void

MathML/SVG />, , .

(HTML5 Ref)

+1

HTML5 "", - .

script . javascript ( src ), javascript script. , - , javascript .

HTML ( HTML5) XML-. (, disabled checked).

0
<script></script>   <!-- Right way. -->
<div></div>         <!-- Right way. -->
<content></content> <!-- Right way. -->

, .

- :

<input type="text" velue="Hello" />
<img src="image.jpg" />

, . , , .

So this is not a “right or wrong” question. This is a question of what the tag is actually used for.

-1
source

Source: https://habr.com/ru/post/1612767/


All Articles