Home >Web Front-end >CSS Tutorial >How Can I Achieve Line Breaks in HTML Without Using ``?
Standard practice dictates the use of
tags to create new lines in HTML. However, what if there was an alternative method to achieve line breaks without resorting to
?
The key lies in utilizing the "white-space" property in CSS. By setting the "white-space" property to "pre", elements can mimic the behavior of
tags, which retain newlines within their content.</p> <h3>A Practical Example</h3> <p>To illustrate this concept, consider the following example:</p> <pre class="brush:php;toolbar:false"><p>hello <br/> How are you</p>
This code produces the following output:
hello How are you
Now, let's replace the
tag with CSS:
p { white-space: pre; }
<p>hello How are you</p>
Voila! The newlines are preserved, resulting in the exact same output as before without the need for
.
The above is the detailed content of How Can I Achieve Line Breaks in HTML Without Using ``?. For more information, please follow other related articles on the PHP Chinese website!