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

If you’ve ever struggled to align elements neatly in CSS—or tried to make a layout look good on both desktop and mobile— Flexbox CSS is your new best friend. Short for "Flexible Box Layout," Flexbox is a layout module in CSS3 that provides an efficient way to distribute space and align items in a container, even when their sizes are dynamic. In this flexbox tutorial for beginners , we’ll guide you step-by-step through what Flexbox is, why it’s essential for responsive design, and how to use it to build clean, adaptable layouts. By the end of this guide, you’ll be able to use Flexbox confidently to build elements like navigation bars, feature sections, and even a CSS flexbox pricing table example . Whether you're a self-taught developer, a student, or someone shifting into a front-end career, Flexbox will become one of your most powerful tools in building responsive, user-friendly websites. Before diving into the code, if you're not yet familiar with CSS fundamenta...

Image

Hello everyone! In our last post about Grid Layouts , we explored how to create a basic grid structure in CSS. Now, let’s take that one step further. Today, we're diving into Grid Sizing — how to size columns and rows inside your grid layout. By the end of this post, you’ll know exactly when to use fixed units like px , flexible units like fr , and responsive functions like minmax() . We’ll even explore some cool developer tools and an interactive test. Ready? Let’s go! What is Grid Sizing? Grid Sizing refers to how we control the size of the rows and columns inside our CSS Grid layout. Depending on what kind of content you're building (e.g., dashboards, cards, galleries), you'll want your grid to behave differently. In CSS Grid, we use properties like: grid-template-rows grid-template-columns grid-auto-rows grid-auto-columns Let’s break these down together. 1. Fixed Sizes with px and rem You can define static sizes for rows and columns using pixels ...