HTML pre

HTML Preformatted <pre> tag is used to define preformatted text in an HTML document.

Example

A simple Preformatted element is shown in the following example.

index.html

Note: HTML Preformatted element starts with the tag <pre> and ends with an end tag </pre>.

ADVERTISEMENT

Default CSS for HTML <pre>

By default, following CSS properties are set for a Preformatted element.

display: block;
font-family: monospace;
white-space: pre;
margin: 1em 0px;

Inline Style for HTML Preformatted Element

We can change the style of Preformatted element through inline styling using style attribute.

In the following example, we have set the color to red for the Preformatted element.

index.html

Apply CSS for HTML Preformatted Element

We can apply CSS for all Preformatted elements using the pre tag.

index.html

Conclusion

In this HTML Tutorial, we learned about HTML <pre> tag and went through different examples that cover defining an HTML Preformatted element, and styling it.