HTML 标签和元素有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8937384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:39:24  来源:igfitidea点击:

What is the difference between HTML tags and elements?

htmlterminology

提问by user

I notice that most people use the words HTML tagsand HTML elementsinterchangeably.

我注意到大多数人交替使用HTML 标签HTML 元素这两个词。

But what is the difference between them?

但是它们之间有什么区别呢?

The way I see it is that tags are in the source code and elements are processed tags (by the browser) in the DOM. Am I wrong?

我的看法是标签在源代码中,元素是在 DOM 中处理的标签(由浏览器)。我错了吗?

回答by 4m01

HTML tag is just opening or closing entity. For example:

HTML 标签只是打开或关闭实体。例如:

<p>and </p>are called HTML tags

<p></p>被称为HTML标签

HTML element encompasses opening tag, closing tag, content (optional for content-less tags) Eg:

HTML 元素包含开始标签、结束标签、内容(对于无内容标签是可选的)例如:

<p>This is the content</p>: This complete thing is called a HTML element

<p>This is the content</p>: 这个完整的东西叫做 HTML 元素

回答by Simpal Kumar

HTML tags vs. elements vs. attributes

HTML elements

An element in HTML represents some kind of structure or semantics and generally consists of a start tag, content, and an end tag. The following is a paragraph element:

<p>
This is the content of the paragraph element.
</p>

HTML tags

Tags are used to mark up the start and end of an HTML element.

HTML 标签 vs. 元素 vs. 属性

HTML 元素

HTML 中的元素表示某种结构或语义,通常由开始标记、内容和结束标记组成。以下是段落元素:

<p>
This is the content of the paragraph element.
</p>

HTML 标签

标签用于标记 HTML 元素的开始和结束。

<p></p>

HTML attributes

An attribute defines a property for an element, consists of an attribute/value pair, and appears within the element's start tag. An element's start tag may contain any number of space separated attribute/value pairs.

The most popular misuse of the term “tag” is referring to alt attributes as “alt tags”. There is no such thing in HTML. Alt is an attribute, not a tag.

<img src="foobar.gif" alt="A foo can be balanced on a bar by placing its fubar on the bar's foobar.">

HTML 属性

属性定义元素的属性,由属性/值对组成,并出现在元素的开始标记中。元素的开始标记可以包含任意数量的空格分隔的属性/值对。

“标签”一词最常见的误用是将 alt 属性称为“alt 标签”。HTML 中没有这样的东西。Alt 是一个属性,而不是一个标签。

<img src="foobar.gif" alt="A foo can be balanced on a bar by placing its fubar on the bar's foobar.">

Source: 456bereastreet.com: HTML tags vs. elements vs. attributes

来源:456bereasttreet.com:HTML 标签 vs. 元素 vs. 属性

回答by kiliman13

HTML Elements

HTML 元素

An HTML element usually consists of a starttag and endtag, with the content inserted in between:

一个 HTML 元素通常由开始标签和结束标签组成,内容插入在两者之间:

<tagname>Content goes here...</tagname>

The HTML elementis everything from the start tag to the end tag. Source

HTML元素是从开始标记到结束标记的所有内容。 来源

HTML Attributes

HTML 属性

An attribute is used to define the characteristics of an HTML element and is placed inside the element's opening tag. All attributes are made up of two parts: a nameand a value.

属性用于定义 HTML 元素的特征并放置在元素的开始标记内。所有属性都由两部分组成:namevalue

  • All HTML elements can have attributes
  • Attributes provide additional informationabout an element
  • Attributes are always specified in the start tag
  • Attributes usually come in name/value pairs like: name="value"Source
  • 所有 HTML 元素都可以有属性
  • 属性提供有关元素的附加信息
  • 属性总是在开始标签中指定
  • 属性通常以名称/值对的形式出现,例如:name="value"来源

HTML Tag vs Element

HTML 标签与元素

"Elements" and "tags" are terms that are widely confused. HTML documents contain tags, but do not contain the elements. The elements are only generated after the parsing step, from these tags. Source: wikipedia > HTML_element

“元素”和“标签”是被广泛混淆的术语。HTML 文档包含标签,但不包含元素。元素仅在解析步骤之后从这些标签生成。 来源:维基百科 > HTML_element

An HTML element is defined by a starting tag. If the element contains other content, it ends with a closing tag.

HTML 元素由起始标记定义。如果元素包含其他内容,则以结束标记结束。

For example <p>is starting tag of a paragraph and </p>is closing tag of the same paragraph but <p>This is paragraph</p>is a paragraph element.

例如<p>是一个段落的开始标签和同一个段落</p>的结束标签但是<p>This is paragraph</p>是一个段落元素。

Source:tutorialspoint > html_elements

来源:tutorialspoint > html_elements

回答by katwekibs

lets put this in a simple term. An element is a set of opening and closing tags in use.

让我们用一个简单的术语来表达。元素是一组正在使用的开始和结束标记。

Element

元素

<h1>...</h1>

TagH1 opening tag

标签H1 开始标签

<h1>

H1 closing tag

H1 结束标记

</h1>

回答by Dhaval Shukla

http://html.net/tutorials/html/lesson3.php

http://html.net/tutorials/html/lesson3.php

Tags are labels you use to mark up the begining and end of an element.

All tags have the same format: they begin with a less-than sign "<" and end with a greater-than sign ">".

Generally speaking, there are two kinds of tags - opening tags: <html>and closing tags: </html>. The only difference between an opening tag and a closing tag is the forward slash "/". You label content by putting it between an opening tag and a closing tag.

HTML is all about elements. To learn HTML is to learn and use different tags.

标签是用于标记元素开始和结束的标签。

所有标签都具有相同的格式:它们以小于号“<”开始,以大于号“>”结束。

一般来说,有两种标签——开始标签:<html>和结束标签:</html>。开始标记和结束标记之间的唯一区别是正斜杠“/”。您可以通过将内容放在开始标记和结束标记之间来标记内容。

HTML 是关于元素的。学习HTML就是学习和使用不同的标签。

For example:

例如:

<h1></h1>

Where as elements are something that consists of start tag and end tag as shown:

其中 as 元素是由开始标签和结束标签组成的东西,如图所示:

<h1>Heading</h1>

回答by nrvarun

Tagsand Elementsare not the same.

标签元素不一样的。

Elements

元素



They are the pieces themselves, i.e. a paragraph is an element, or a header is an element, even the body is an element. Most elements can contain other elements, as the body element would contain header elements, paragraph elements, in fact pretty much all of the visible elements of the DOM.

它们本身就是片段,即一个段落是一个元素,或者一个标题是一个元素,甚至正文也是一个元素。大多数元素可以包含其他元素,因为 body 元素将包含标题元素、段落元素,实际上几乎所有 DOM 可见元素。

Eg:

例如:

<p>This is the <span>Home</span> page</p>

Tags

标签



Tags are not the elements themselves, rather they're the bits of text you use to tell the computer where an element begins and ends. When you 'mark up' a document, you generally don't want those extra notes that are not really part of the text to be presented to the reader. HTML borrows a technique from another language, SGML, to provide an easy way for a computer to determine which parts are "MarkUp" and which parts are the content. By using '<' and '>' as a kind of parentheses, HTML can indicate the beginning and end of a tag, i.e. the presence of '<' tells the browser 'this next bit is markup, pay attention'.

标签不是元素本身,而是用于告诉计算机元素开始和结束位置的文本位。当您“标记”一个文档时,您通常不希望将那些实际上不是文本一部分的额外注释呈现给读者。HTML 借用了另一种语言 SGML 的技术,为计算机提供了一种简单的方法来确定哪些部分是“标记”,哪些部分是内容。通过使用'<'和'>'作为一种括号,HTML可以指示标签的开始和结束,即'<'的存在告诉浏览器'下一位是标记,注意'。

The browser sees the letters '

浏览器看到字母 '

' and decides 'A new paragraph is starting, I'd better start a new line and maybe indent it'. Then when it sees '

'并决定'一个新的段落正在开始,我最好开始一个新的一行并且可能缩进它'。然后当它看到 '

'它知道它正在处理的段落已经完成,所以它应该在继续下一步之前打破那里的行。

- Opening tag.

- 打开标签。

- 结束标签enter image description here在此处输入图片说明

回答by MMKarami

This visualization can help us to find out difference between concept of element and tag (each indent means contain):

这个可视化可以帮助我们找出元素和标签概念之间的区别(每个缩进意味着包含):

- element

        - content:

            - text 

            - other elements 

            - or empty

        - and its markup

            - tags (start or end tag)

                - element name

                - angle brackets < >

                - or attributes (just for start tag)

                - or slash / 

回答by A ranjan

<p>Here is a quote from WWF's website:</p>.

In this part <p>is a tag.

这部分<p>是一个标签。

<blockquote cite="www.facebook.com">facebook is the world's largest socialsite..</blockquote>

in this part <blockquote>is an element.

在这部分<blockquote>是一个元素。