Images, videos, audio, and embedded content with modern styling
The Img element embeds images with support for alt text, lazy loading, and responsive sizing.
// Basic image
Img(src: "logo.png", alt: "Company Logo")
// Styled image
Img(src: "hero.jpg", alt: "Hero Image")
.class("img-rounded img-shadow")
.style("width", "100%")
.style("max-width", "600px")
// Image with loading optimization
Img(src: "product.jpg", alt: "Product")
.attribute("loading", "lazy")
.attribute("width", "300")
.attribute("height", "200")
<!-- Basic image -->
<img src="logo.png" alt="Company Logo">
<!-- Styled image -->
<img src="hero.jpg" alt="Hero Image" class="img-rounded img-shadow" style="width: 100%; max-width: 600px;">
<!-- Image with loading optimization -->
<img src="product.jpg" alt="Product" loading="lazy" width="300" height="200">
Basic image:
Styled image with gradient background:
Thumbnail with attributes:
Picture element provides art direction and format selection for responsive images.
Picture {
Source(srcset: "hero-mobile.webp", media: "(max-width: 768px)", type: "image/webp")
Source(srcset: "hero-desktop.webp", media: "(min-width: 769px)", type: "image/webp")
Source(srcset: "hero-mobile.jpg", media: "(max-width: 768px)", type: "image/jpeg")
Source(srcset: "hero-desktop.jpg", media: "(min-width: 769px)", type: "image/jpeg")
Img(src: "hero-fallback.jpg", alt: "Hero Image")
}
<picture>
<source srcset="hero-mobile.webp" media="(max-width: 768px)" type="image/webp">
<source srcset="hero-desktop.webp" media="(min-width: 769px)" type="image/webp">
<source srcset="hero-mobile.jpg" media="(max-width: 768px)" type="image/jpeg">
<source srcset="hero-desktop.jpg" media="(min-width: 769px)" type="image/jpeg">
<img src="hero-fallback.jpg" alt="Hero Image">
</picture>
Resize your browser to see different images:
Video element embeds video content with playback controls and multiple source support.
Video(src: "movie.mp4", controls: true) {
P("Your browser does not support the video tag.")
}
.attribute("width", "320")
.attribute("height", "240")
// With multiple sources and poster
Video(controls: true, autoplay: false, loop: false, muted: true) {
Source(type: "video/mp4", src: "movie.mp4")
Source(type: "video/ogg", src: "movie.ogg")
P("Your browser does not support the video tag.")
}
.attribute("poster", "poster.jpg")
<video src="movie.mp4" controls width="320" height="240">
<p>Your browser does not support the video tag.</p>
</video>
<!-- With multiple sources and poster -->
<video controls poster="poster.jpg">
<source type="video/mp4" src="movie.mp4">
<source type="video/ogg" src="movie.ogg">
<p>Your browser does not support the video tag.</p>
</video>
Sample video with controls:
💡 Video features: play/pause, volume control, fullscreen
Audio element embeds sound content with playback controls.
Audio(src: "audio.mp3", controls: true) {
P("Your browser does not support the audio element.")
}
// With multiple sources
Audio(controls: true) {
Source(type: "audio/ogg", src: "audio.ogg")
Source(type: "audio/mpeg", src: "audio.mp3")
P("Your browser does not support the audio element.")
}
.class("audio-player")
<audio src="audio.mp3" controls>
<p>Your browser does not support the audio element.</p>
</audio>
<!-- With multiple sources -->
<audio controls class="audio-player">
<source type="audio/ogg" src="audio.ogg">
<source type="audio/mpeg" src="audio.mp3">
<p>Your browser does not support the audio element.</p>
</audio>
Audio player with controls:
🎵 Features: play/pause, seek bar, volume control
IFrame element embeds external content within your page.
// Basic iframe
IFrame(src: "https://example.com", title: "Example Website")
.style("width", "100%")
.style("height", "400px")
// YouTube embed
IFrame(
src: "https://www.youtube.com/embed/dQw4w9WgXcQ",
title: "YouTube video player"
)
.attribute("frameborder", "0")
.attribute("allowfullscreen", "true")
<!-- Basic iframe -->
<iframe src="https://example.com" title="Example Website" style="width: 100%; height: 400px;"></iframe>
<!-- YouTube embed -->
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="YouTube video player" frameborder="0" allowfullscreen></iframe>
Embedded OpenStreetMap:
🌐 IFrames can embed maps, videos, documents, and other web content