Belajar Anchor Element dan HTML Attributes (Untuk Membuat Hyperlink di Website)

Anchor Element dan HTML Attributes

Halo teman-teman!

Setelah sebelumnya kita belajar tentang nested list dan indentasi, kali ini kita akan mengenal anchor element yang digunakan untuk membuat hyperlink. Kita juga akan mempelajari apa itu HTML attributes untuk menambahkan informasi ekstra ke elemen HTML. Yuk, kita mulai!


Apa Itu Anchor Element?

Anchor element adalah elemen HTML yang digunakan untuk membuat hyperlink. Dengan hyperlink, kita bisa membuat teks yang ketika diklik akan membawa pengguna ke halaman lain.

Struktur dasar anchor element:

<a href="URL">Teks Link</a>
  • <a>: Tag pembuka anchor.
  • href: Attribute untuk menentukan URL tujuan link.
  • Teks Link: Teks yang bisa diklik oleh pengguna.
  • </a>: Tag penutup anchor.

Contoh Penggunaan Anchor Element

1. Link ke Website Lain

Berikut contoh anchor element yang mengarahkan pengguna ke sebuah website:

<a href="https://www.google.com">Kunjungi Google</a>

Hasil di browser:

  • Teks "Kunjungi Google" akan tampil sebagai link biru dengan garis bawah.
  • Ketika diklik, link tersebut akan membawa pengguna ke situs Google.

2. Menambahkan Anchor ke List

Anchor element juga bisa digunakan di dalam list. Contoh:

<ol>
    <li><a href="https://www.google.com">Google</a></li>
    <li><a href="https://www.youtube.com">YouTube</a></li>
    <li><a href="https://www.wikipedia.org">Wikipedia</a></li>
</ol>

Hasil di browser:

  1. Google
  2. YouTube
  3. Wikipedia

Apa Itu HTML Attributes?

HTML attributes adalah informasi tambahan yang diberikan pada elemen HTML untuk menentukan perilaku atau properti tertentu.
Struktur umum attribute:

<elemen nama-attribute="nilai">Konten</elemen>

Contoh pada anchor element:

<a href="https://www.google.com" target="_blank">Kunjungi Google</a>
  • href: Menentukan URL tujuan link.
  • target="_blank": Membuka link di tab baru.

Proyek: Website Favoritku

Kita akan membuat website sederhana yang berisi daftar 5 situs favorit kalian, lengkap dengan hyperlink.

Langkah 1: Struktur Dasar HTML

Buat file baru bernama index.html, lalu tambahkan struktur dasar berikut:

<!DOCTYPE html>
<html>
<head>
    <title>Website Favoritku</title>
</head>
<body>
    <h1>Website Favoritku</h1>
</body>
</html>

Langkah 2: Tambahkan Ordered List

Buat ordered list untuk daftar website favorit:

<ol>
    <li><a href="https://www.google.com">Google</a></li>
    <li><a href="https://www.youtube.com">YouTube</a></li>
    <li><a href="https://www.wikipedia.org">Wikipedia</a></li>
    <li><a href="https://www.github.com">GitHub</a></li>
    <li><a href="https://www.medium.com">Medium</a></li>
</ol>

Langkah 3: Tambahkan Attribute Tambahan

Tambahkan target="_blank" agar link terbuka di tab baru:

<li><a href="https://www.google.com" target="_blank">Google</a></li>

Fitur Tambahan: Mulai Nomor dari 5

Kita bisa menggunakan attribute start untuk memulai ordered list dari nomor tertentu. Contoh:

<ol start="5">
    <li><a href="https://www.google.com">Google</a></li>
    <li><a href="https://www.youtube.com">YouTube</a></li>
    <li><a href="https://www.wikipedia.org">Wikipedia</a></li>
</ol>

Hasilnya, daftar akan dimulai dari nomor 5.


Hasil Akhir Kode

Berikut kode lengkapnya:

<!DOCTYPE html>
<html>
<head>
    <title>Website Favoritku</title>
</head>
<body>
    <h1>Website Favoritku</h1>
    <ol start="5">
        <li><a href="https://www.google.com" target="_blank">Google</a></li>
        <li><a href="https://www.youtube.com" target="_blank">YouTube</a></li>
        <li><a href="https://www.wikipedia.org" target="_blank">Wikipedia</a></li>
        <li><a href="https://www.github.com" target="_blank">GitHub</a></li>
        <li><a href="https://www.medium.com" target="_blank">Medium</a></li>
    </ol>
</body>
</html>

Kesimpulan

Anchor element dan HTML attributes sangat penting untuk membuat website interaktif dan fungsional. Dengan memahaminya, kalian bisa membuat hyperlink yang rapi dan sesuai kebutuhan.

Di pelajaran berikutnya, kita akan belajar tentang Image Elements untuk menambahkan gambar ke 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...

Image

Calculate Business Loan Payments, Interest, and Total Cost Easily and Accurately Loan Amount (USD) Annual Interest Rate (%) Loan Term (Years) Extra Monthly Payment (USD) Reset Calculate Hi everyone! If you're looking for extra capital to launch a startup or expand your existing business, it's important to know how much you'll need to repay—monthly and overall. Don’t commit to a loan without understanding the full picture. That’s where our Online Business Loan Calculator comes in handy. This tool is designed for business owners, entrepreneurs, or anyone seeking a full breakdown of a loan. It helps you calculate monthly payments, total interest, repayment period, and overall cost automatically with just a few simple inputs. How to Use the Business Loan Calculator Fill in the following fields based on your situation: Loan Amount (USD): Ent...

Hi everyone! Let’s explore CSS Grid together—a powerful feature that helps us build two-dimensional layouts on the web. In this guide, we’ll start from the basics and work our way up to controlling the size and position of elements with more flexibility. If you're already familiar with Flexbox, Grid will feel like a fun and useful complement! CSS Grid is perfect for building complex layouts like dashboards, photo galleries, or any page that requires a clean structure both horizontally and vertically. Let’s dive in! What is Grid? By adding display: grid to an element, we turn it into a grid container . While Flexbox works in one direction (horizontal or vertical), Grid works in both—columns and rows simultaneously. Grid was introduced to solve layout challenges that couldn’t easily be handled by Flexbox or older techniques like float . Think of Grid as a two-dimensional layout system that gives you full control over element placement and sizing. Why Use Grid? Great for la...