пятница, 10 июля 2020 г.

Chocolate in Ukraine

Ultimate Guide to HTML Iframes: Best Practices and Examples

The HTML <iframe> element embeds another HTML page within the current one, perfect for integrating videos, maps, or external content seamlessly.

Basic Syntax and Essential Attributes

Start with the core src attribute for the URL, and always add a title for accessibility so screen readers describe the content.

  • height and width: Set dimensions in pixels or use CSS for responsiveness.
  • frameborder="0" or style="border: none;": Removes default borders.
  • allowfullscreen: Enables full-screen mode for videos.

Example:

<iframe src="https://example.com" height="300" width="400" title="Example Content" style="border: none;"></iframe>

Making Iframes Responsive

Use a wrapper div with relative positioning and padding-top for aspect ratios like 16:9, ideal for YouTube videos as shown above.

.container { position: relative; width: 100%; padding-top: 56.25%; }
.responsive-iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }

Advanced Attributes for Security and Performance

  • sandbox: Restricts scripts, forms, and popups (e.g., sandbox="allow-same-origin allow-forms").
  • loading="lazy": Defers loading until near viewport.
  • referrerpolicy="no-referrer": Controls referrer information.

For full-screen embeds like flower delivery videos, explore our flowers category or order a stunning 25 Red Roses bouquet.

Full-Page Iframe Setup

Reset margins and use viewport units for iframes that fill the entire screen:

html, body { height: 100%; margin: 0; }
iframe { display: block; width: 100%; height: 100%; border: none; }

Enhance gifts pages with gifts embeds or pair with a Ferrero Rocher Box.

Комментариев нет:

Отправить комментарий