What is difference between <pre> and <code> HTML Tag? [duplicate]

情到浓时终转凉″ 提交于 2019-11-26 19:27:38

问题


How does a <pre> HTML tag differs from <code> html tag.

I have checked on W3Schools page, it seems they are just the same.

If there any major difference between them ?


回答1:


Don't go to w3schools. Check the w3c documentation for pre and code instead.

PRE:

The PRE element tells visual user agents that the enclosed text is "preformatted". When handling preformatted text, visual user agents:

  • May leave white space intact.
  • May render text with a fixed-pitch font.
  • May disable automatic word wrap.
  • Must not disable bidirectional processing.

CODE:

Designates a fragment of computer code.




回答2:


<pre> says "The whitespace in this element is important" (so new lines and spaces get rendered as new lines and spaces).

<code> says "This is code".

They have nothing in common aside from being HTML elements.

W3Schools page, it seems they are just the same

W3Schools is often wrong, often out of date, and often teaches worst practises. If they claim the two elements do the same thing, then that is just another reason to avoid the site.



来源:https://stackoverflow.com/questions/16065677/what-is-difference-between-pre-and-code-html-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!