The <br> tag in HTML is used to insert a line break or line break-like spacing within the content. It is an empty tag, meaning it doesn't have a closing tag. When the browser encounters <br>, it moves the content that follows it to the next line.
Here's an example of how the <br> tag is used:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML BR Tag Example</title>
</head>
<body>
<p>This is some text.<br>And this is on a new line.</p>
</body>
</html>
In this example:
- The text "This is some text." and "And this is on a new line." are part of the same paragraph.
- The <br> tag is used to create a line break between the two lines of text.
While the <br> tag is useful for creating simple line breaks, for more complex layouts and spacing, it's often better to use CSS for better control and responsiveness.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML BR Tag with CSS Example</title>
<style>
.new-line {
margin-top: 10px;
}
</style>
</head>
<body>
<p>This is some text.</p>
<p class="new-line">And this is on a new line with CSS spacing.</p>
</body>
</html>
In this CSS example, a class named "new-line" is used to create spacing between paragraphs, providing more control over the layout. The use of CSS for spacing is generally preferred for modern web development.