<pre>Some text</pre>
This can be useful for displaying text that is formatted in a specific way, such as a poem or a song lyric.
Welcome to plus2net, you can learn following scripts here.
PHP Server side scripting language
ASP Server side scripting language
HTML Tags to use using web browser
JavaScript Client side scripting language
Welcome to plus2net, you can learn following scripts here. PHP Server side scripting language ASP Server side scripting language HTML Tags to use using web browser JavaScript Client side scripting language
While the <pre> tag preserves whitespace and formatting, we can enhance its appearance using CSS. For instance, we can add borders, background colors, or padding to improve readability.
<style>
pre.styled-pre {
background-color: #f5f5f5;
border-left: 3px solid #ccc;
padding: 10px;
overflow-x: auto;
}
</style>
<pre class="styled-pre">
function helloWorld() {
console.log("Hello, world!");
}
</pre>
The <pre> tag can be combined with other tags like <code>, <samp>, or <kbd> to semantically represent different types of text.
<pre><code>
SELECT * FROM users WHERE active = 1;
</code></pre>
By default, text inside a <pre> tag does not wrap, which can cause horizontal scrolling. To address this, we can use the CSS white-space property set to pre-wrap to allow long lines to wrap within the container.
<style>
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
<pre>
This is a very long line of text that will wrap within the pre tag container to prevent horizontal scrolling.
</pre>
When using the <pre> tag, it's important to consider accessibility. For example, when displaying ASCII art or diagrams, we should provide descriptive text alternatives for screen readers.
<pre role="img" aria-label="A simple smiley face made with ASCII art">
:-)
</pre>
Previously, the <pre> tag supported a width attribute to specify the number of characters per line. This attribute is now deprecated and should be replaced with CSS for controlling layout and presentation.
<style>
pre {
width: 80ch; /* 80 characters wide */
}
</style>
By incorporating these enhancements and additional examples, we can provide a more comprehensive understanding of the <pre> tag and its practical applications in web development.