Do the tags that have no closure have any particular purpose?

Asked

Viewed 4,788 times

1

I often come across tags HTML being used in two ways.

First form:

<title>Stackoverflow</title>

Second form:

<meta charset="utf-8">

Note that in the tag title there was closure </> and in the tag meta there was no closure.

In situations where there are tags which has closure and others which does not have closure I have the following doubt.

Doubt

As tags that no closures have any particular purpose? They are only tags that serves to configure something in the page? As well as the tag meta defining the codification.

1 answer

3


No, they are just tags that do not need to be closed, that is, it has no content that it controls. It can be a <meta> or it may be a <br>. To tag exists on its own. It can have attributes, as shown in the question. A <img> has in the properties everything it needs, the closure would only be necessary to indicate that the content is over, but not any content linked to tag but.

Most of tags simple (no closure) render something even if it does not have an associated content. The content may be determined in an attribute, case of <img> where it is already the image itself or <br> that only renders a "skip line".

I have already cited two cases that are not for configuration of anything. Others:

  • area
  • base
  • col
  • command
  • embed
  • hr
  • input
  • keygen
  • link
  • menuitem
  • param
  • source
  • track
  • wbr

Forgot any? Maybe new versions have other examples.

Tags that have terminators need to have an associated content, which can be a text or a tag or a set of tags. Having closure is something that is only necessary when there is something that needs to be determined that finished what needed to be described.

Think about the ; and the { } in most programming languages. Why is there something that only indicates the end and something that indicates beginning and end? It’s the same reason, one element indicates something unique and another indicates something composite, which needs an indicator that the composition has finished.

The same could be said of quotation marks. Why do not you need a terminator in a number or a true? Because there is a rule that identifies its composition, unlike string that it needs something that determines its beginning and end. It is only because of this that there is the terminator or lack of it.

Why do this?

<meta charset="utf-8"></meta>

If that’s enough?

<meta charset="utf-8">

I put in the Github for future reference.

Related: The right is <br> or <br/> or <br />?.

  • So the tags that are closed, usually have content that will be rendered by the browser and displayed to the user, would that be?

  • 1

    Not exactly, it needs to have an associated content, which can be a text or a tag or a set of tags. If it were all that will be rendered to <img> It would have to have closure, but it doesn’t, because what it renders has nothing associated with it, it’s already the image itself. Having closure is something that is only necessary when there is something that needs to be determined that has finished what needed to be described. Think about ; and the { } in most programming languages. Why is there something that indicates beginning and end and something that only indicates the end? It’s the same reason. To be something unique or composed

  • 1

    @Bigown your complimentary comment is practically another answer! This example given is so explanatory, do not think it would be interesting as part of the answer?

  • @diegofm made.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.