Search code examples
htmlpre

If you set a style for a pre or div once, do you need to set again?


for example, if i do:

pre style="white-space:pre-wrap;"

at the beginning of my first pre block, would this apply to all pre blocks? it doesn't seem to have the effect I want.


Solution

  • No, if you define your style directly inside your <pre> tag, it will only be applied to this element.

    Define your CSS properties in a <style> block, and it will be applied to all <pre> elements:

    <style>
    pre {
        white-space: pre-wrap;
    }
    </style>
    

    Simply place this block inside the <head> of your HTML document.