How to Use the CSS White-Space Property

The white-space property determines how sequences of whitespace are displayed. You can learn how to use the CSS white-space property in just a few steps.

  1. You first need to know the values you can use with the white-space property and what they do. They are:
    Property Collapses Series of Spaces and/or Tabs in Code Collapses Line Breaks in Code Wraps to Fit Containing Box
    normal Yes Yes Yes
    pre No No No
    nowrap Yes Yes No
  2. Next, enter the code in the HTML, as follows:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>White-Space</title>
    </head>
    <body>
    
    <h1>White-Space</h1>
    
    <div style="white-space: normal;">
    	white-space: normal
    	white-space: normal
    	white-space: normal white-space: normal white-space: normal white-space: normal 
    	white-space: normal white-space: normal
    </div>
    <hr>
    <div style="white-space: nowrap;">
    	white-space: nowrap
    	white-space: nowrap
    	white-space: nowrap white-space: nowrap white-space: nowrap white-space: nowrap 
    	white-space: nowrap white-space: nowrap
    </div>
    <hr>
    <div style="white-space: pre;">
    	white-space: pre
    		white-space: pre
    			white-space: pre
    </div>
    
    </body>
    </html>

    This code renders the following:
    White Space

Author: Chris Minnick

Chris Minnick, the co-founder of WatzThis?, has overseen the development of hundreds of web and mobile projects for customers from small businesses to some of the world’s largest companies. A prolific writer, Chris has authored and co-authored books and articles on a wide range of Internet-related topics including HTML, CSS, mobile apps, e-commerce, e-business, Web design, XML, and application servers. His published books include Adventures in Coding, JavaScript For Kids For Dummies, Writing Computer Code, Coding with JavaScript For Dummies, Beginning HTML5 and CSS3 For Dummies, Webkit For Dummies, CIW E-Commerce Designer Certification Bible, and XHTML.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.