views:

387

answers:

10

There are HTML tags, such as <img />, <input /> and <button />, that need no ending tag (</img>, </input> and </button>). What is the term that describes this type of tags?

+17  A: 

The term is self-closing.

tvanfosson
Maybe you know this, what is the difference between a self-closing tag and a void element (like <br />)? see this wiki (http://en.wikipedia.org/wiki/HTML_element)
Tim
Sounds right. One more thing. What would be the term for a tag that needs a closing tag? Regular tag?
Emanuil
@Tim self-closing tags and "void elements" are the same thing.
Fara
@Emanuil - I suppose I would call it an opening tag or refer to it by its name, i.e, an anchor tag or span tag. As @Mark Byers suggests, the important thing is that people understand what you're talking about. I think opening/closing tag and self-closing are pretty widely used. In conversation I prefer not to be pedantic, but you really ought to make sure that your mark up is legal for whatever document type you're using. I normally write XHTML for what it's worth.
tvanfosson
+1  A: 

That is called a self closing tag

Dennis Haarbrink
+1  A: 

There are paired and unpaired tags.

Unpaired tags are opened and do not have to be closed. They stand alone.

<img />, <input /> and <button />
JapanPro
+1  A: 

It is called : Shorttag

Marc Uberstein
+1  A: 

HTML tags can be of two types. They are

  1. Paired Tags

  2. Unpaired Tags

Paired Tags:

A tag is said to be a paired tag if the text is placed between a tag and its companion tag. In paired tags, the first tag is referred to as Opening Tag and the second tag is referred to as Closing Tag.

Example: <i>This text is in italics. </i>

Note: Here <i> is called opening tag. and </i> is called closing tag.

Unpaired Tags:

An unpaired tag does not have a companion tag. Unpaired tags are also known as Singular or Stand-Alone Tags.

Example : <br> , <hr> etc. These tags does not require any companion tag.

Alpesh
+14  A: 

This syntax has a variety of names depending on what language you are using. The best way to find out what it is called is to look at the specification for the specific language.

HTML 4.x

I can't find any mention of this syntax in the HTML 4.x specification. It is not valid syntax.

HTML 5

In the HTML 5 specification the / character (called a SOLIDUS) is valid but has no effect for void elements such as <br />, <hr />, <img />, <input />, etc. and for foreign elements (such as SVG tags) it designates a start tag that is marked as self-closing. It is not a valid syntax for all other tags (such as <button /> mentioned in your question).

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

XML

According to the XML specification it is called an empty-element tag:

The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag.

XHTML

According to the XHTML specification it is called the minimized tag syntax for empty elements:

C.2. Empty Elements

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).

In general if you want to be precise I would recommend using the names as defined in the appropriate standard. Then if people aren't exactly sure what you mean they can look it up in the standard to find out. However if you don't want to use the name in the standard you are free to call it something else if you want. The important thing is that the people who communicate with you can understand you. I don't think anyone would misunderstand you if you used the term 'self-closing tag' for a tag in an XML document even if the standard officially calls it something else.

Thanks to Alohci for the HTML 5 reference.

Mark Byers
This is undoubtedly the correct answer, but the important part is that in practice nearly everyone I know calls them "self-closing" tags.
Dan Diplo
A: 

I know them as bachelor tags.
e.g. here: http://moodle.cs.huji.ac.il/cs09/file.php/67782/xml-intro.pdf (page 30)

David דוד
A: 

I've called them self-closing, single tags and monotags, I don't know why I haven't adopted a single term though.

AcidSoldier
+1  A: 

I've seen them referred to as singlet (Which is presumably a short form of single-tag)

troelskn
+1  A: 

This sort of Element is an empty element (since it does not contain anything, it just may have attributes). That's the correct way according to the specification, AFAIK. (If the Element is not empty, the Element consists of the opening tag, the closing tag, and the content inbetween.)

Those tags are also called "unpaired", "single", or "bachelor tags". The term "self-closing" I don't like because they don't close themselves any more than other tags, it's still you or your program that puts the "/>" in there.

foo