Programming Examples

Write HTML code to demonstrate the following anchor tag behaviors.


Write HTML code to demonstrate the following anchor tag behaviors.

  • a. Create a hyperlink that opens a .pdf file in a new tab.
  • b. Create a hyperlink that opens a downloadable .docx file in the same window.
  • c. Jump from the top of the page to a specific section titled “Contact Us”.
  • d. Jump from “Contact Us” back to the top.
Solution

<!DOCTYPE html>
<html>
<head>
    <title>Anchor Tag Demonstration</title>
</head>
<body>

    <h2 id="top">Anchor Tag Examples</h2>

    <!-- a. Open PDF in new tab -->
    <p>
        <a href="sample.pdf" target="_blank">Open PDF in New Tab</a>
    </p>

    <!-- b. Download DOCX in same window -->
    <p>
        <a href="sample.docx" download>Download DOCX File</a>
    </p>

    <!-- Spacer for scrolling -->
    <p style="margin-top: 800px;">Scroll down...</p>

    <!-- c. Jump to Contact Us section -->
    <h2 id="contact">Contact Us</h2>
    <p>
        Email: example@example.com<br>
        Phone: 123-456-7890
    </p>

    <!-- d. Jump back to top -->
    <p>
        <a href="#top">Back to Top</a>
    </p>

</body>
</html>
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad