How to prevent text in a table cell from wrapping using CSS? Last Updated : 23 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Preventing text from wrapping in a table cell ensures the content stays on one line, maintaining the layout's integrity. Using the CSS property white-space: nowrap;, you can control text behavior, avoiding unwanted line breaks within table cells.Syntax:white-space: normal|nowrap|pre|pre-wrap|pre-line;Example 1: In this example we use the white-space: nowrap; CSS property within the <th> tags to prevent text from wrapping in table headers. It ensures that the headings remain on a single line. html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>white-space property</title> <style> th { white-space: nowrap; } </style> </head> <body> <table border="1" collap> <thead> <tr> <th>First Heading of GeeksforGeeks</th> <th>Second Heading of GeeksforGeeks</th> <th>Third Heading of GeeksforGeeks</th> <th>Fourth Heading of GeeksforGeeks</th> </tr> </thead> <tbody> <tr> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> </tr> </tbody> </table> </body> </html> Output: Example 2: In this example we use the white-space: nowrap; CSS property on specific table headers (<th>) to prevent text wrapping, ensuring the first and third headings stay on a single line within the table. html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>white-space property</title> </head> <body> <table border="1" collap> <thead> <tr> <th style="white-space: nowrap;"> First Heading of GeeksforGeeks </th> <th>Second Heading of GeeksforGeeks</th> <th style="white-space: nowrap;"> Third Heading of GeeksforGeeks </th> <th>Fourth Heading of GeeksforGeeks</th> </tr> </thead> <tbody> <tr> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> </tr> </tbody> </table> </body> </html> Output: Preventing text wrapping in table cells is essential for maintaining a clean and organized table layout, especially when dealing with long strings of text. By utilizing the CSS white-space property, you can control text behavior within your tables, ensuring that content remains on a single line. Comment More infoAdvertise with us Next Article How to prevent text in a table cell from wrapping using CSS? S shivangsharma15 Follow Improve Article Tags : Web Technologies CSS CSS-Misc Similar Reads How to wrap a text in a <pre> tag using CSS ? In this article, we will learn how to wrap a text in a <pre> tag. The <pre> tag is used to display the block of preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers. By default, the <pre> tag does no 2 min read How to Remove Cellspacing from Tables using CSS? Removing cellspacing from tables using CSS means eliminating the default space or gaps between table cells. This can be achieved with properties like border-collapse: collapse or border-spacing: 0, resulting in a more compact and seamless table layout.Here we have some common apporaches:Table of Con 2 min read How to Align Right in a Table Cell using CSS ? Aligning right in a table cell means positioning the content of the cell to the right side. In CSS, this can be achieved by applying the text-align property to the table cell or using the td selector.Align right in a table cell Using text-align propertyTo align the contents of a table cell to right, 2 min read How to Wrap Table Cell td Content using CSS? The word-wrap, and word-break properties in CSS are used to wrap content within a table cell (<td>).HTML<h3 style="text-align:center;"> Simple Example Without Word Wrap </h3> <table width="600" style="border-spacing: 0px; table-layout: fixed; margin-left:auto; margin-right:auto; 3 min read How to wrap text inside and outside box using CSS ? In CSS, controlling how text wraps inside and outside a box is essential for creating a visually appealing and readable layout. When the content of a text element is too long to fit in its container, text wrapping comes into play. Using properties like word-wrap, word-break, and overflow-wrap, devel 2 min read Like