Week 2: Formatting Text and Creating Links
Learn how to style text semantically and connect pages together.
Explore Chapter 2Creating Hyperlinks (<a>)
The anchor tag <a> is used to create hyperlinks, allowing users to navigate between pages or resources.
Basic Link Structure
<a href="url">Link Text</a>
- href Attribute: Specifies the destination URL (Uniform Resource Locator) of the link. This is the most important attribute.
- Link Text: The visible part of the link that users click on.
Linking to External Pages
<a href="https://www.google.com">Visit Google</a>
Linking to Internal Pages (within your site)
Use relative paths (explained in the next section).
<a href="about.html">About Us</a>
<a href="contact.html">Contact Page</a>
Linking to Sections on the Same Page
Use the # symbol followed by the id attribute of the target element.
<!-- Link -->
<a href="#section2">Go to Section 2</a>
<!-- Target Element -->
<h2 id="section2">Section 2</h2>
Linking to Email Addresses
Use `mailto:` within the `href` attribute.
<a href="mailto:info@example.com">Email Us</a>
The `target` Attribute
Specifies where to open the linked document.
- _self: (Default) Opens in the same window/tab.
- _blank: Opens in a new window or tab.
- _parent: Opens in the parent frame.
- _top: Opens in the full body of the window.
<!-- Opens Google in a new tab -->
<a href="https://www.google.com" target="_blank">Google (New Tab)</a>