Sometimes you don’t want to trust the browser to render spacing, tabs, and returns on its own. Poetry, formulas, or programming code, for example, may have their meaning changed or be harder to read if the browser is allowed to do its own thing.
But there’s an easy workaround you can use: the
element. The text betweenandis preserved in its original state and won’t reflow the text when the browser window is resized. The code for this element looks like this:
This text breaks
like a poem would
yet is not, in fact,
a poem, as far
as I can tell.
However, you can’t retain everything from the original text. Browsers render preformatted text in a monospaced font, resembling Courier, and retain only simple formatting, such as bold and italics.
Get SpecializedThese special treatments of text are essential parts of any Web author’s knowledgebase. Keep them on hand when you need to create quotes, let others know when you have inserted text, or maintain the original formatting for a block of text.
The
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. Text in theelement is displayed in a fixed-width font, but it can be changed using CSS. Thetag requires a starting and end tag.
Syntax:
Contents...Below examples illustrate the
tag in HTML:
Example 1:
HTML
GeeksforGeeks
A Computer Science Portal For Geeks
Output:
Example 2:
HTML
pre tag with CSS
pre {
font-family: Arial;
color: #009900;
margin: 25px;
}
GeeksforGeeks
A Computer Science Portal For Geeks
Output:
Supported Browsers:
- Google Chrome
- Edge 12
- Internet Explorer
- Firefox 1
- Opera
- Safari
How do you maintain formatting in HTML?
tagin 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.
How do you preserve space in HTML?
tagdefines preformatted text preserving both whitespace and line breaks in the HTML document. This tag is also commonly referred to as the
element.
What is font formatting in HTML?
What is preformatted text in HTML?
: The Preformatted Text element. The HTML element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically rendered using a non-proportional, or monospaced, font. Whitespace inside this element is displayed as written.