Sunday, 10 November 2024

br Tag: How and When to Use Line Breaks in HTML

The <br> tag in HTML stands for "break." It is used to insert a line break within the text, effectively move the content that follows it to a new line. Unlike paragraph tags (<p>), which create space between blocks of text, the <br> tag simply breaks the line without adding any extra space. In simple terms, it acts like pressing the "Enter" key on your keyboard.

 

The <br> tag is an empty element, meaning it does not have a closing tag. In XHTML or some stricter HTML standards, you might see it written as <br />, but in regular HTML5, <br> is sufficient.

 

line-break.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Linebreak Example</title>
</head>
<body>
    Line one of text<br>
    Line two of text<br>
    Line three of text        
</body>
</html>

Above snippet generate below screen.



 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment