不需要结束标签的标签叫什么?

发布于 2024-09-23 23:55:39 字数 176 浏览 1 评论 0原文

有一些 HTML 标签,例如 )。描述这种类型标签的术语是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

流年里的时光 2024-09-30 23:55:39

根据您使用的语言,此语法有多种名称。找出它的名称的最佳方法是查看特定语言的规范。

HTML 4.x

我在 HTML 4.x 规范中找不到任何提及此语法的内容。这不是有效的语法。

HTML 5

在 HTML 5 规范中,/ 字符(称为 SOLIDUS)有效,但对 void 元素,例如


等以及 外来元素(例如 SVG 标签)它指定标记为自关闭的开始标签。它不是所有其他标签的有效语法(例如您问题中提到的

然后,如果该元素是空元素之一,或者如果该元素是外来元素,则可能有单个 U+002F SOLIDUS 字符 (/)。该字符对 void 元素没有影响,但在外部元素上,它将开始标记标记为自闭合

XML

根据 XML 规范称为空元素标签

空元素的表示形式是紧随其后的开始标记或结束标记,或者是空元素标记

XHTML

根据XHTML 规范,它被称为空元素的最小化标签语法

C.2。空元素

在尾随 / 和 > 之前包含一个空格空元素,例如


Karen。另外,对空元素使用最小化标记语法,例如
,作为替代语法

。 XML 允许的结果在许多现有的用户代理中给出了不确定的结果。

C.3。元素最小化和清空元素内容

给定内容模型不为 EMPTY 的元素的空实例(例如,空标题或段落),请勿使用最小化形式(例如使用

)。

一般来说,如果您想要精确,我建议使用适当标准中定义的名称。然后,如果人们不太确定您的意思,他们可以在标准中查找以找出答案。但是,如果您不想在标准中使用该名称,则可以随意将其称为其他名称。重要的是与你交流的人能够理解你。如果您在 XML 文档中使用术语“自闭合标签”来表示标记,我认为任何人都不会误解您,即使标准正式将其称为其他名称。

感谢 Alohci 提供 HTML 5 参考。

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.

蓝梦月影 2024-09-30 23:55:39

该术语是自动关闭的。

The term is self-closing.

狠疯拽 2024-09-30 23:55:39

HTML 标签可以有两种类型。它们是

  1. 配对标签

  2. 未配对标签

配对标签

如果文本位于标签与其伴随标签之间,则称该标签为配对标签。在成对标签中,第一个标签称为“开始标签”,第二个标签称为“结束标签”。

例子:
此文本为斜体。

注意:这里的称为开始标签。 称为结束标签。

未配对标签

未配对标签没有伴随标签。未配对的标签也称为单一标签或独立标签。

示例:


等。这些标签不需要任何伴随标签。

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.

南城旧梦 2024-09-30 23:55:39

这些标签称为“独立标签”。独立标签在 HTML 中没有结束标签,

但在 XHTML 中,它们必须通过在结束尖括号之前添加正斜杠来自动结束

Those tags are called "Standalone Tags". Standalone tags are having no closing tags in HTML

But in XHTML they have to be self closed by adding forward slash before the closing angular bracket

若言繁花未落 2024-09-30 23:55:39

我一直称它们为 Singleton 标签!

I've always called them Singleton tags!

叫嚣ゝ 2024-09-30 23:55:39

可选的结束标签,如pli

还值得一提的是,除了问题中提到的标签之外,其他几个标签不需要结束标签:当标准中指定的内容出现时,它们会自动关闭。

例如:

<body>
<p>abc
<p>def
</body>

相当于:

<body>
<p>abc
</p>
<p>def
</p>
</body>

因为 p 在以下位置关闭两者:

  • 另一个 p 的开始处
  • p的父级关闭时,

这是指定的在 12.1.2.4“可选标签”https://html.spec。 Whatwg.org/multipage/syntax.html#optional-tags 但我认为除了“带有可选结束标记的元素”之外没有实际名称。

另请参阅:P-end-tag (

HTML 中不需要 )

Optional closing tags like p, li, etc.

It is also worth mentioning that several other tags besides those mentioned in the question don't need a closing tag: they just close automatically when something specified in the standard appears.

For example:

<body>
<p>abc
<p>def
</body>

is equivalent to:

<body>
<p>abc
</p>
<p>def
</p>
</body>

because the p closes both at:

  • the start of another p
  • when the parent of the p closes

This is specified at 12.1.2.4 "Optional tags" https://html.spec.whatwg.org/multipage/syntax.html#optional-tags but I don't think there's an actual name besides "an element with an optional closing tag".

See also: P-end-tag (</p>) is not needed in HTML

天涯沦落人 2024-09-30 23:55:39

这就是所谓的自闭合标签

That is called a self closing tag

口干舌燥 2024-09-30 23:55:39

有配对标签和未配对标签

未配对的标签会被打开并且不必关闭。他们是孤独的。

<img />, <input /> and <button />

There are paired and unpaired tags.

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

<img />, <input /> and <button />
海螺姑娘 2024-09-30 23:55:39

我知道它们是单身汉标签。
例如这里: http://moodle.cs .huji.ac.il/cs09/file.php/67782/xml-intro.pdf(第30页)

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

ぽ尐不点ル 2024-09-30 23:55:39

我称它们为自闭合、单一标签和单标签,但我不知道为什么我没有采用单一术语。

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

小傻瓜 2024-09-30 23:55:39

我见过它们被称为单线态(这可能是单标签的缩写形式)

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

她如夕阳 2024-09-30 23:55:39

这种元素是一个空元素(因为它不包含任何内容,所以它可能有属性)。根据规范,这是正确的方法,AFAIK。 (如果元素不为空,则元素由开始标记、结束标记以及中间的内容组成。)

这些标记也称为“未配对”、“单个”或“单身标记”。我不喜欢“自动关闭”这个术语,因为它们不会比其他标签更多地关闭自己,仍然是您或您的程序将“/>”在那里。

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.

风情万种。 2024-09-30 23:55:39

根据此处

元素由开始标记、内容和结束标记组成。

According to here:

An element consists of a start tag, content, and an end tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文