Cara menggunakan html new line

Tulis sesuatu tentang diri Anda di sini. Jelaskan secara singkat siapa Anda dan apa yang Anda lakukan untuk kehidupan Anda. Ingatlah untuk menggunakan teks tebal dan miring, untuk lebih memahami HTML lebih lanjut.

A line break, as the name implies, is a break in line 😅. A line break in HTML is a point where a line ends horizontally, and the next line starts on a new line.

In HTML, when you write a string like this:

Hello, I am trying to create a new line

The whitespaces (the tab space before "Hello", the space between "am" and "trying", "a" and "new") will be ignored. The result on the screen will appear like this:

Hello, I am trying to create a new line

One way to fix this (though it's not very effective) is to create three

tags like this:

Hello, I am

trying to create a

new line

This will result in the following:

Hello, I am
trying to create a
new line

Because p tags create

Hello, I am trying to create a new line
0 elements, they occupy the entire horizontal space and the next element goes to the next line – as you can see from the result above.

This solution is not effective because you have created three paragraphs. In cases where a screen reader is to interpret this, it will read it as three paragraphs instead of a single sentence. This can affect web accessibility.

So how do you add a line break for an inline element?

How to Add a Line Break in HTML

HTML has tags for numerous purposes, including to create line breaks. You can use the

Hello, I am trying to create a new line
1 tag in HTML to add line breaks. It can go between inline elements to break the elements into multiple parts.

Here is an example of a paragraph with the

Hello, I am trying to create a new line
1 tag:

Hello, I am
trying to create a
new line

The

Hello, I am trying to create a new line
1 tag is a void element that doesn't have a closing tag. Instead, it is a self-closing tag.

The above code results in this:

Hello, I am
trying to create a
new line

You can use this tag for other forms of inline elements like links. For example, look at this code:


Anchor tags,

Hello, I am trying to create a new line
4, are inline elements, so instead of the second link showing on the next line, it shows in the same line like this:

Cara menggunakan html new line

You can use the

Hello, I am trying to create a new line
1 tag between the links to break the first link line:


Cara menggunakan html new line

Conclusion

The

Hello, I am trying to create a new line
1 tag in HTML starts the next element on a new line, similar to the carriage return
Hello, I am trying to create a new line
7 in strings.

Instead of using block elements for putting elements in new lines, you can use the line break tag:

Hello, I am trying to create a new line
1.

In cases like sentences, using the

Hello, I am trying to create a new line
1 tag serves as a visual line break and doesn't affect accessibility. Screen readers will read the sentence as it is without pause.

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT


Cara menggunakan html new line
Dillion Megida

Developer Advocate and Content Creator passionate about sharing my knowledge on Tech. I simplify JavaScript / ReactJS / NodeJS / Frameworks / TypeScript / et al My YT channel: youtube.com/c/deeecode


If you read this far, tweet to the author to show them you care. Tweet a thanks

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Elemen br sebaiknya digunakan hanya untuk garis baru yang benar-benar merupakan bagian dari sebuah konten, seperti digunakan pada baris syair, puisi dan alamat.


Global AttributesAtribut Secara Global (Keseluruhan)


tag mencakup global attributes, yang artinya tag tersebut dapat disisipkan semua attributes yang termasuk dalam global attributes yang secara umum berlaku untuk semua HTML tags.

Silahkan, lihat referensi mengenai HTML Global Attribute

Event AttributesAtribut event (Peristiwa)


tag mencakup event attributes, yang artinya attribute tersebut dijalankan ketika ada interaksi dari user atau dalam suatu peristiwa (kejadian). Contoh: menjalankan script (JavaScript) ketika halaman web pada jendela browser hendak ditutup, dan lain sebagainya.

Silahkan, lihat referensi mengenai HTML Events Attribute

ExampleContoh HTML
element

Contoh Penggunaan dalam baris alamat.

HTML

<p>
  Jln. Raya Serang KM.76<br>
  Kragilan<br>
  Serang-Banten
p>

Contoh Lengkap

Contoh source code lengkap disertai dengan link "editor" untuk mencoba (try it) dan melihat hasil (preview) kode.

Manakah tag HTML untuk memasukkan line break?

Tag
adalah tag yang di sediakan pada html untuk membuat baris baru atau sering dan lebih mudah di sebut dengan membuat enter.

Apa tag dari HTML yang berfungsi untuk membuat baris baru?

Fungsi utama tag
adalah untuk membuat baris baru.

Bagaimana cara penulisan tag?