Belajar Nesting dan Indentasi di HTML (Membuat List Bertingkat dengan Rapi)

Nesting dan Indentasi di HTML

Halo teman-teman!

Di pelajaran sebelumnya, kita sudah belajar membuat ordered list dan unordered list. Nah, kali ini kita akan memperdalamnya dengan nested list dan memahami pentingnya indentasi. Ini langkah penting agar kode kita rapi dan mudah dibaca, terutama saat membuat struktur list yang lebih kompleks.

Apa Itu Nested List?

Nested list adalah list yang berada di dalam list lain. Dengan kata lain, kalian bisa membuat list di dalam sebuah item list. Contohnya seperti ini:

Contoh Nested List:

  • Item A
  • Item B
    • Subitem B1
    • Subitem B2
  • Item C

Dengan nested list, kalian bisa membuat hierarki dalam daftar, seperti daftar bahan atau langkah-langkah yang saling berkaitan.


Cara Membuat Nested List

1. Struktur Dasar

Untuk membuat nested list, gunakan <ul> (unordered list) atau <ol> (ordered list) di dalam sebuah <li> (list item). Contohnya:

<ul>
    <li>Item A</li>
    <li>Item B
        <ul>
            <li>Subitem B1</li>
            <li>Subitem B2</li>
        </ul>
    </li>
    <li>Item C</li>
</ul>

Hasil di browser:

  • Item A
  • Item B
    • Subitem B1
    • Subitem B2
  • Item C

2. Menggabungkan Ordered dan Unordered List

Kalian juga bisa menggabungkan <ol> dan <ul> untuk membuat struktur yang lebih kompleks:

<ol>
    <li>Langkah 1</li>
    <li>Langkah 2
        <ul>
            <li>Detail A</li>
            <li>Detail B</li>
        </ul>
    </li>
    <li>Langkah 3</li>
</ol>

Hasil di browser:

  1. Langkah 1
  2. Langkah 2
    • Detail A
    • Detail B
  3. Langkah 3

Pentingnya Indentasi

Indentasi membuat kode lebih rapi dan mudah dibaca. Contoh tanpa indentasi:

<ul><li>Item A</li><li>Item B<ul><li>Subitem B1</li><li>Subitem B2</li></ul></li><li>Item C</li></ul>

Dibandingkan dengan indentasi yang benar:

<ul>
    <li>Item A</li>
    <li>Item B
        <ul>
            <li>Subitem B1</li>
            <li>Subitem B2</li>
        </ul>
    </li>
    <li>Item C</li>
</ul>

Kenapa penting?

  • Kode lebih mudah dibaca dan dipahami, terutama untuk nested list.
  • Membantu menemukan kesalahan (debugging) saat ada masalah di kode.

Contoh Proyek: Nested List untuk Daftar Belanja

Kita akan membuat nested list untuk daftar belanja:

<!DOCTYPE html>
<html>
<head>
    <title>Daftar Belanja</title>
</head>
<body>
    <h1>Daftar Belanja</h1>
    <ul>
        <li>Bahan Makanan
            <ul>
                <li>Beras</li>
                <li>Sayuran</li>
                <li>Buah-buahan</li>
            </ul>
        </li>
        <li>Kebutuhan Rumah Tangga
            <ul>
                <li>Sabun</li>
                <li>Sampo</li>
            </ul>
        </li>
        <li>Minuman
            <ul>
                <li>Teh</li>
                <li>Kopi</li>
                <li>Air Mineral</li>
            </ul>
        </li>
    </ul>
</body>
</html>

Hasil di browser:

  • Bahan Makanan
    • Beras
    • Sayuran
    • Buah-buahan
  • Kebutuhan Rumah Tangga
    • Sabun
    • Sampo
  • Minuman
    • Teh
    • Kopi
    • Air Mineral

Tips untuk Nested List

  1. Perhatikan penutup tag: Setiap tag pembuka harus memiliki tag penutup yang tepat.
  2. Indentasi otomatis: Gunakan fitur di teks editor seperti Visual Studio Code untuk otomatis merapikan indentasi (Ctrl+S atau Cmd+S).
  3. Periksa hasil secara berkala: Gunakan fitur preview untuk melihat hasil kode di browser.

Kesimpulan
Nested list membantu kita membuat daftar yang lebih terstruktur dan kompleks. Dengan indentasi yang benar, kode kalian akan lebih rapi dan mudah dipahami. Selanjutnya, kita akan belajar tentang Anchor Element untuk membuat hyperlink di website. Sampai jumpa di pelajaran berikutnya! 😊

Comments

Postingan Populer

Image

Superingan is a Blogger template designed with simplicity and functionality in mind, offering a clean and user-friendly platform for professional websites. This theme is perfect for various website types, including personal blogs, online magazines, news websites, and portfolios. Features: Responsive Design: Your website will look its best across all devices, from desktops and laptops to tablets and smartphones. Customizable Colors: Easily change the template's colors to match your branding or preferences. Custom Headers: Upload your own header image to add a personal touch to your website. Custom Menus: Create and manage your website's navigation menus with ease. Widget Areas: Add widgets to display additional content and features on your website's sidebar. Clean HTML & CSS Code: The template is built with clean and well-structured code, making it easy to learn and customize further. Superingan is an ideal choice for those seeking a professional website with a sim...

Hello friends, how are you doing? If you own a blog or website and want to earn more revenue through Google AdSense, you’ve come to the right place. In this comprehensive article, we’re going to explore a variety of methods to increase your Cost Per Click (CPC) and Click-Through Rate (CTR), two crucial metrics that greatly influence how much you earn from ads on your blog. We will dig into how to make your blog more appealing to advertisers so that the monetary value of each ad click (CPC) goes up, and the percentage of people who click on your ads (CTR) also rises. We’ll discuss why these two factors matter, how to optimize your content, strategies for choosing the right topics, and how to place ads strategically. We’ll also highlight the importance of SEO so that your blog becomes easier for people to find through search engines. With increased visibility in search results, you can attract more visitors—and with more visitors, your opportunities for higher ad clicks multiply, which ...

Halo teman-teman! Kali ini, kita akan belajar bagaimana membuat website multi-halaman . Kalau sebelumnya kita hanya membuat satu halaman HTML saja, sekarang kita akan menambahkan halaman lain, seperti halaman "About" dan "Contact". Yuk, kita mulai! Apa Itu Website Multi-Halaman? Website multi-halaman adalah situs yang memiliki lebih dari satu file HTML. Contohnya: Halaman utama: index.html Halaman tentang: about.html Halaman kontak: contact.html Semua file ini disimpan dalam satu Project folder . Folder ini juga bisa berisi gambar, file CSS, atau file lainnya yang mendukung website. Cara Menautkan Halaman dengan Anchor Tag Untuk berpindah antar halaman, kita menggunakan anchor tag ( <a> ). Contoh: <a href="./about.html">Tentang Kami</a> Kode di atas akan membuat link yang mengarahkan pengguna ke file about.html . Catatan: ./ : Artinya file ada di folder yang sama dengan index.html . Kalau file ada di folder lain, gunak...