What is the difference between tag and element and html document and page?

Asked

Viewed 528 times

4

I would like to know the differences between an element for a tag in HTML.

Example 1

The example below is an element or a tag?

<p></p>

Example 2

And in the example below is tag or element?

<p>Esse é um parágrafo</p>

I would also like to know the difference between a document HTML one-page.

2 answers

6


Page x Document

You can have an HTML document that isn’t even a page, it can be a email marketing for example, or it may be only a fraction of a document (but with the extension .html/.htm), without having the doctype declared. This fraction of HTML is not a page itself and can be used as a "component" in another document. Then see that you may have an HTML file, but without one <!DOCTYPE html> avowed...

Remembering that if you don’t declare the doctype of HTML it will be interpreted in quirks mode by browser

An HTML tag can be for example meta tags or the head, which are HTML markup tags, but which do not render visually on the page.

These are common HTML content types

inserir a descrição da imagem aqui

Metadata content is usually "tags only" ex: <base>, <command>, <link>, <meta>, <noscript>, <script>, <style> e <title>.

Already tags the Flow Contentes, Phrasing Content Headers and Tags Semânticas usually are HTML elements that are visible on the screen to the user.

This link might interest you: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Categorias_de_conteudo


An HTML tag does not need to have content to be an "element", even empty it is an element, and can still be accessed in the DOM by CSS or JS

See in this example that using CSS, the div:empty has the background other than div that has content within...

div {
  width:100px;
  height:100px;
  background: blue;
}
div:empty {
  background: red;
}
<div></div>

<div>Esse é um parágrafo</div>

  • Thanks! but in the case of my examples who is who? or else element is the same thing that tag and vice versa?

  • 2

    @Joãobatista element all are, because all represent something, even if the user does not see on the screen. So everything is tag, and everything is element, what varies is the type of element, and whether it is an element at the interface level (visible on the screen), or at the code level (only visible to HTML interpreters). The code of your example does not make much sense, there vc has an HTML tag, which in one case is empty :empty, or with a content inside. The tag does not need to have content to be an element as you can see in the reply. Qq thing speaks there

  • 1

    @joãobatista edited the answer, see at the end of it, how I used your code and CSS to style an empty element

  • Thank you very much, hugocsl! helped a lot, another doubt that stayed about my question, was on a site that I had seen that spoke HTML document is the file with .html already the page would be the visible part that the user will see when accessing the site, this is right? or as a rule everything is the same thing? html document is the same thing as page?

  • 2

    @joãobatista depending on the context may be right what you saw, but I believe it is wrong, because you may have HTML tag inside files, . PHP, . JS, . ASP, and so on... doesn’t need to be an . HTML to have HTML tags. Vc can have an HTML in a . TXT, and use another language to take this HTML and put it on a page. Also, a page can be . PHP, not even need to be . HTML rss, already in my view an HTML document is only HTML even if you have the <!DOCTYPE html> declared within it, regardless of whether it is a page or a loose fraction of code

  • True! You’re absolutely right, thanks for the strength.

Show 1 more comment

5

It seems to me that’s what’s starting from < up to the >, as well as has opening tag:

<nomedatag>

And closing tag

</nomedatag>

And the element would encompass the opening tag until the closing tag, then the element would be all of this (having content or not):

<nomedatag>Conteudo</nomedatag>

In this case the element can contain more tags and text (texts are also considered "nodes/nodes"), element seems to me that is something considered by the interpreter (as a "parser") or rendering engine, in this case would get as element same, but I could be wrong about this last point.

It is worth remembering that there are elements of the "void type", which have no closing tag, as examples:

  • <input>
  • <br>
  • <hr>

In these cases the understanding is that from < up to the > would be the tag and also the element.

I’m not even assuming here browsers only, because an interpreter may not be from a browser, it may be for example the:

That make the interpretation of the document and can obtain the "element", already the type of content (for example in Phrasing content) is irrelevant to determine what is the element, because the content is only part of it, and does not change what is element.


HTML document can refer:

  • the page itself
  • to a static HTML file
  • Or simply "DOM processed" by the engine (HTML interpreter)

Now "page" itself seems to me a generic term, it can be of different formats, both HTML and other types of page as examples:

  • swf ("dead", was the flash)
  • images
  • pdf

Of course, engines usually process a pre-html to ship different types of documents, but this is a browser feature and not a rule

Browser other questions tagged

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