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 ?
Definition and Usage The <pre> tag defines preformatted text. Text in a <pre> element is displayed in a fixed-width font, and the text preserves both spaces and line breaks. The text will be displayed exactly as written in the HTML source code.
The <p> tag defines a paragraph. Browsers automatically add some space (margin) before and after each <p> element while, the <pre> tag defines pre-formatted text. Text in a <pre> element is displayed in a font (usually Courier), and it preserves both spaces and line breaks.
Definition and Usage. The <code> tag is used to define a piece of computer code. The content inside is displayed in the browser's default monospace font.
The <pre> tag in HTML is used to define the block of preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers.
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.
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With