The HTML <td> nowrap attribute is used to prevent the text inside a table data cell from wrapping onto multiple lines. It keeps the content displayed in a single line within the cell.
- Used inside the <td> tag to disable text wrapping.
- Helps keep table content in one continuous line.
- In modern HTML, CSS white-space: nowrap; is preferred instead of the nowrap attribute.
Syntax:
<td nowrap>Note: It is not supported by HTML5.
Example: Illustrates the use of <td> nowrap with an HTML document.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML nowrap Attribute</title>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
padding: 6px;
margin: auto;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML <td> nowrap Attribute</h2>
<!--Driver Code Ends-->
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td nowrap>Alen</td>
<!-- This cell will take up space on two rows -->
<td rowspan="2">24</td>
</tr>
<tr>
<td>Harry</td>
</tr>
</table>
<!--Driver Code Starts-->
<p>The nowrap attribute is not supported in HTML5. Use CSS instead.</p>
</body>
</html>
<!--Driver Code Ends-->