HTML•Hyperlinks & Media
HTML Links and Images: <a> href and <img> src Attributes
Learn attribute syntax for navigation links, opening tabs safely with rel="noopener", and image accessibility.
Syntax
<a href="https://compilra.app" target="_blank" rel="noopener">Link</a>
<img src="img.jpg" alt="Description" />
Parameters & Values
Key components and acceptable values for this structure:
| Parameter | Type | Description |
|---|---|---|
| href | Attribute | Hypertext reference URL destination. |
| alt | Attribute | Accessible alternative text describing image. |
Ready-to-Run Code Example
Executable in CompilraRun this complete, working example directly without installing HTML locally:
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: sans-serif; padding: 20px; text-align: center; }
.card { border: 1px solid #cbd5e1; border-radius: 12px; padding: 20px; max-width: 320px; margin: auto; }
a.btn { display: inline-block; background: #2563eb; color: white; padding: 8px 16px; border-radius: 6px; text-decoration: none; font-weight: bold; }
</style>
</head>
<body>
<div class="card">
<h2>Compilra IDE</h2>
<p>Run 10+ programming languages online with real-time cloud compilation.</p>
<a href="/compiler" class="btn">Launch Compiler →</a>
</div>
</body>
</html>Expected Output:
[Rendered Interactive Card with Title, Description, and Styled Call-to-Action Link Button]
How It Works: Step-by-Step
- Lines 10-15: Constructs interactive card with styled anchor <a> tag.
Key Concepts
- The <a> tag creates hyperlinks to external URLs or internal routes.
- Always supply the alt attribute on <img> tags for screen readers and SEO.
Common Mistake: Using target="_blank" without rel="noopener noreferrer"
Opening external links in new tabs without rel="noopener" creates a security vulnerability (tabnabbing).
❌ Incorrect
<a href="https://example.com" target="_blank">Link</a>
✅ Correct
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Link</a>
Related HTML Tutorials & Compiler
HTML5 Semantic Structural Boilerplate and Metadata Configurations
Structure HTML5 documents with semantic boilerplate tags (<!DOCTYPE html>, <meta>, <header>, <main>, <nav>, <footer>) and responsive viewport configurations.
HTML Headings, Paragraphs, and Text Formatting Tags
Structure text content with heading hierarchy (h1 through h6), paragraphs, strong, and code.
HTML Form Validation: Client-Side Input Requirement Attributes and Constraint Tags
Enforce client-side input validation and conditional submission guards using HTML5 constraint attributes (required, pattern, minlength, min/max).
HTML Online Compiler
Open in Compilra IDE
Run and test HTML on Compilra
Execute this code snippet with pre-supplied standard input (stdin) in Compilra’s cloud compiler.