Category: HTML

  • Iframe Code: Embed a Page, Set Dimensions, and Control Scrolling

    Iframe Code: Embed a Page, Set Dimensions, and Control Scrolling

    Use this iframe code to embed another HTML page inside the current page:

    <iframe src=”https://example.com/embed” title=”Example embedded page” width=”800″ height=”450″></iframe>

    The src attribute supplies the URL to load. The title describes the embedded content for people using assistive technology. The width and height set the iframe viewport, usually in CSS pixels when declared as HTML attributes.

    How do you write basic iframe code with src, title, width, and height?

    Start with the smallest complete element, then add styling only when the embed requires it. The opening and closing tags create the embedded browsing context, while the attributes define its source, accessible name, and initial dimensions.

    • src: The page or resource displayed inside the iframe. Use the complete embed URL provided by the service or application.
    • title: A short, meaningful description such as “Product demonstration” or “Store locator.” Avoid repeating a generic label across several iframes.
    • width: The initial horizontal size of the embedded viewport.
    • height: The initial vertical size of the embedded viewport.

    Keep the title even when the iframe is visually obvious. It provides context to visitors who navigate by landmarks or embedded content.

    How should you set an iframe’s width and height?

    Use CSS for responsive sizing and reserve HTML width and height attributes for a simple fallback or an intrinsic starting size. A common stylesheet is:

    iframe { display: block; width: 100%; max-width: 800px; height: 450px; }

    This makes the iframe fill its available container up to 800 pixels while keeping a predictable 450-pixel viewport. Set a definite height when the embedded page must remain usable on smaller screens. Width alone does not make the height adapt to the embedded page.

    For a consistently proportioned video or presentation, CSS can use an aspect ratio instead:

    iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; }

    Test the result at narrow and wide viewport sizes. An embed that is too short may create unnecessary internal scrolling, while an oversized fixed height can leave excessive empty space.

    How do you style an iframe border with CSS instead of legacy frameborder?

    Style the iframe element with the CSS border property:

    iframe { border: 1px solid #c7c7c7; }

    Use border: 0; when the embedded design should blend into the surrounding page. You can also set individual sides, color, width, and radius in CSS. The phrase iframe frame border usually refers to this visible edge around the embedded viewport.

    The frameborder HTML attribute is legacy markup. Do not use frameborder=”0″ as the current implementation. Replace it with a CSS rule such as border: 0;, or define the border explicitly so its appearance remains consistent across browsers and themes.

    How does iframe scrolling work, and what replaces the legacy scrolling attribute?

    An iframe has its own document and viewport. When the embedded document is taller or wider than that viewport, the embedded page normally scrolls inside the frame. Changing the iframe’s dimensions does not automatically resize it to fit all of the embedded content.

    The scrolling attribute is legacy markup. Do not use values such as scrolling=”no” or scrolling=”auto” for new implementations. Control overflow in the embedded document with CSS:

    html, body { overflow: auto; }

    Use overflow: hidden; only when the embedded content is designed to fit without scrolling:

    html, body { overflow: hidden; }

    This CSS must apply inside the embedded page. If the iframe loads content from another origin, the parent page cannot directly change that page’s overflow rules. In that case, use the provider’s responsive embed method, an appropriate fixed height, or a documented messaging and resize system. The host page’s CSS can size and border the iframe, but the embedded document controls its own internal layout and scrolling.

  • How to Make a Link Clickable in HTML

    How to Make a Link Clickable in HTML

    To make a link clickable in HTML, place the destination in an anchor element and put the visible link text between its opening and closing tags. The anchor works for page URLs, email addresses, and phone numbers; only the href value changes.

    This basic pattern shows how to make a link clickable:

    <a href=”https://example.com”>Visit Example</a>

    How to Make a Link Clickable in HTML

    The opening tag identifies the element as an anchor. Its href attribute holds the destination. In this example, the href value is https://example.com, while Visit Example is the clickable link text. The closing tag ends the anchor. When a visitor activates it, the browser requests the address in href.

    Use quotation marks around every href value, and keep the opening and closing tags paired. An anchor can wrap text or another inline element, so the destination remains attached to the content users activate.

    HTML does not make a URL clickable merely because it appears as visible text. The URL must be assigned to href, and the words or element users select must appear between the anchor tags. An anchor without href is not a working navigation link.

    How to Create a Clickable Link With Absolute and Relative URLs

    An absolute URL contains the full protocol and domain, such as https://www.example.com/pricing. It identifies the same destination from any page on the web. Use an absolute URL for an external website or when you need an explicit address that can be copied and shared.

    A relative path leaves out the protocol and domain because the browser resolves it from the current site. A root-relative path begins with a slash, as in:

    <a href=”/pricing”>Pricing</a>

    This points to the pricing page at the site’s root. A document-relative path names a location based on the current folder, as in:

    <a href=”contact.html”>Contact us</a>

    Relative paths are useful for links between pages in the same website, but they depend on the site’s folder structure. If the current page is inside a subfolder, a path such as ../contact.html moves up one folder before looking for the file. Check the deployed URL structure rather than assuming it matches your local files.

    How to Hyperlink a Website, Email Address, or Phone Number

    Website navigation uses the same anchor syntax. An absolute URL is usually safest when linking to another domain, while a relative path suits another page within your own site:

    <a href=”https://www.example.com”>Example website</a>

    For an email address, use a mailto: destination instead of a page URL:

    <a href=”mailto:[email protected]”>Email us</a>

    Clicking a mailto link typically opens the visitor’s default email application with the address ready in the To field. This is an email action, not ordinary page navigation. A subject can be added with a query value, such as mailto:[email protected]?subject=Project%20enquiry.

    For a phone number, use tel: followed by the number:

    <a href=”tel:+15551234567″>Call +1 555 123 4567</a>

    On a compatible device, clicking it opens the phone app or prompts the visitor to call. A tel link does not load a website page.

    How to Check Link Text and Destination Values

    Check both sides of the link before publishing. The text should describe the destination, and the destination should match what the text promises. “Read the pricing guide” is more useful than “click here” when the link leads to pricing information.

    • Confirm that href contains the complete intended URL or the correct relative path.
    • Check the protocol, domain spelling, slashes, and quotation marks.
    • Test the link from the page where it appears, especially when using a relative path.
    • For mailto and tel links, verify the email address or phone number separately.
    • Use descriptive link text so visitors understand the destination before activating it.

    If the browser displays the words but clicking does nothing, look for a missing href, malformed quotes, a misspelled protocol, or an incorrect relative path. If the link opens the wrong page, compare the path with the site’s folder structure and check slash placement. A correctly paired anchor, valid href value, and accurate link text produce a working clickable link.