What is the main difference of
and

前端 未结 1 1427
独厮守ぢ
独厮守ぢ 2021-02-19 07:17

What is the main difference between
and
in html markup? Can someone explain the main difference of the two because it\'s confus

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 08:00

    In practice,
    does not exist. Just
    or
    .

    However, the difference is the position, and is universal for all XML tags. indicates the beginning of a tag, and indicates the end of a tag. When a tag is used with nothing between it, then a self-closing, or null tag can be used, which combines the beginning and end. It looks like .

    In XML, any tag can be self closing, however, with HTML, only tags which are defined as such should be used that way. So you should never do

    , instead you should use
    , even if it's empty. Some self closing tags in HTML are, as already noted,
    , also things like , and . You can view the full list here.

    So, basically, elements in the link above are allowed to be self closing. They often have attributes to indicate their data, but no additional elements are allowed inside of them. Other elements, which can have additional elements inside of them require both and to be complete.

    Note that under less strict rules, in HTML, self closing tags do not require the ending slash, so
    is equivalent to
    . However, the latter form is preferred, and much cleaner looking. Also, any tags that aren't self closing, that aren't closed property (i.e. has a ) will cause you a nightmare because elements will have a parent who should be a sibling.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题