Images and media¶
Images, videos, and embedded content make pages engaging and informative.
Silex provides blocks for images, videos, and embedded content (maps, widgets, iframes). Once added, media behaves like any other element — it has a box with dimensions, padding, margins, and borders. What makes media special is how its content fits inside that box.
Key mental model: A media element is a box, and the media fills that box according to rules you set. The box size comes from width/height properties. How the media fits inside comes from Object-Fit and Object-Position.
Adding images¶
To add an image:
- Drag the Image block from the Blocks panel onto the canvas
- Silex places an
imgelement with a placeholder - Select the image
- In the Element settings (gear icon) on the right, find the src field (labeled "Image URL")
- Either:
- Enter a URL directly (e.g.,
https://example.com/photo.jpg) - Click the Asset Manager icon to upload and browse files
Asset Manager: uploading images¶
The Asset Manager is a media library for your project. When you upload an image, Silex stores it according to your hosting configuration. You can reuse images across pages — upload once, use many times.
To upload:
- Double-click an image element, or click the Asset Manager icon in the src field
- Click Upload or drag files into the manager
- Select the image you want to use
- It appears on your canvas and the src field fills automatically
Supported formats: - JPEG — best for photographs, high compression - PNG — good for graphics, transparent backgrounds - WebP — modern format, excellent compression for all types - SVG — vector graphics, scales perfectly to any size - GIF — simple animations
Use JPEG or WebP for photos, PNG for icons/graphics with transparency, SVG for logos/illustrations that need to scale.
Alt text: crucial for accessibility¶
Every image needs alt text. Alt text is read by screen readers for blind or low-vision visitors, shown when the image fails to load, and indexed by search engines.
To set alt text:
- Select the image
- In the Element settings (gear icon), find the alt attribute field
- Write a short, descriptive phrase describing what the image shows
Good alt text: "Two people collaborating at a desk with laptops" Bad alt text: "image", "photo", or empty
For decorative images (background textures, borders, dividers) that don't add information, set alt text to empty. This tells screen readers to skip them.
Alt text best practices: - Describe the image's content, not "picture of" or "image of" - Keep it under 125 characters — short but specific - Don't include "image of" or "a photo of" - Include relevant text visible in the image (signs, captions, text overlays)
Adding videos¶
To add a self-hosted video:
- Drag the Video block from the Blocks panel
- Silex creates a
<video>element - Select the video
- In the Element settings (gear icon), set the source URL (or use Asset Manager to upload)
- Configure options:
- autoplay — start playing automatically
- controls — show play/pause buttons
- loop — restart when finished
- muted — required for autoplay in many browsers
For YouTube, Vimeo, or other hosted video services:
Don't use the Video block. Instead:
- Drag the Map block (despite its name, it creates an iframe for any embedded content)
- Paste the embed code from the video service
- Or use the Custom code block for full HTML control
Embedded content (maps, widgets, social posts)¶
The Map block creates an <iframe> element. Despite its name, you can embed any third-party content:
- Google Maps
- Calendars
- Social media posts
- Surveys
- Chat widgets
- YouTube/Vimeo videos
To add embedded content:
- Drag the Map block from the Blocks panel
- Select it and look for the src field in the Element settings (gear icon)
- Paste the embed URL or iframe code
For full control, use the Custom code block instead. It lets you paste any HTML snippet, including JavaScript.
Audio players¶
Drag the Audio block (listed as a media element) to embed an audio player. Set the source URL in the Element settings (gear icon). Common uses: podcasts, music, sound effects.
Canvas and other replaced elements¶
The Canvas block creates a <canvas> element for drawings created with JavaScript. Most designers won't use this — it's for advanced scripting. The Object-Fit and Object-Position properties below also apply to canvas elements.
Controlling how media fits its box¶
When a media element's box and its content have different aspect ratios, CSS controls what happens: stretch the content, crop it, or letterbox it. This is where Object-Fit comes in.
Object-Fit¶
Object-Fit determines how media fills its box.
To set object-fit:
- Select an image, video, audio, iframe, embed, or canvas element
- Open the Object section in the Style panel (appears only for these elements)
- Choose an object-fit value
Available values:
| Value | Effect |
|---|---|
fill |
Stretch/squeeze the media to fill the box completely. May distort aspect ratio. |
contain |
Scale the media to fit inside the box without cropping. Letterbox if aspect ratios don't match. |
cover |
Scale the media to cover the entire box. May crop parts. Usually best for backgrounds. |
none |
Display the media at its natural size. May overflow or leave empty space. |
scale-down |
Use the smaller of none or contain. |
Examples:
coveron a hero image: fills the space, crops top/bottom if neededcontainon a product photo: shows the whole product without distortionfillon a video background: stretches to fill, may distortnoneon an icon: displays at exact size, no scaling
Object-Position¶
Object-Position controls where the media is positioned inside its box when it doesn't fill it exactly (when using contain, scale-down, or none).
Available positions (preset options):
| Position | Effect |
|---|---|
left top |
Align to top-left corner |
left center |
Align to left edge, vertically centered |
left bottom |
Align to bottom-left corner |
center top |
Horizontally centered, top edge |
center center |
Centered both ways (default) |
center bottom |
Horizontally centered, bottom edge |
right top |
Align to top-right corner |
right center |
Align to right edge, vertically centered |
right bottom |
Align to bottom-right corner |
Example: an image with object-fit: cover and object-position: center top crops the bottom and sides while preserving the top (good for photos where the important content is at the top).
Practical example: responsive image gallery¶
You want three images side by side, each 200px wide, that scale down on mobile.
- Create the gallery container:
- Add a Div, set tag to
section - Set Display to Flex, Flex-wrap to wrap
-
Set Column-gap to 16px
-
Create the image items:
- Add three Divs inside the section, set tag to
article - Set Flex-basis to 200px, Flex-grow to 0
-
Set Width to 100%, Height to 200px (square images)
-
Add images inside each article:
- Drag an Image block into each article
- Set Width to 100%, Height to 100%
- Set Object-fit to
cover - Set Object-position to
center center -
Add alt text to each image
-
Result: three square images side by side, photos cropped to fill without distortion. On narrow screens, they wrap naturally into rows.
Practical example: responsive hero image with text overlay¶
You want a full-width image with text on top.
- Create the hero container:
- Add a Div, set height to 400px (or your choice)
- Set Width to 100%
-
Set Position to relative (so text can position absolutely over it)
-
Add the background image:
- Drag an Image block into the hero Div
- Set Width to 100%, Height to 100%
- Set Object-fit to
cover, Object-position tocenter center -
This fills the hero box without distortion
-
Add text on top:
- Add a Div inside the hero
- Set Position to absolute, Top to 50%, Left to 50%
- Add text inside with a high Flex-basis to center it
- Style with color and shadows to stand out against the image
The image fills the hero area, text floats on top, and everything scales responsively.
Common mistakes¶
- Forgetting alt text. Every image needs alt text. Screen reader users and search engines depend on it.
- Using
fillobject-fit when you meantcover.filldistorts the image to stretch;covercrops while maintaining aspect ratio. - Not setting width/height on images. If an image has no set size, it displays at its natural resolution, which may be too large or small.
- Setting object-fit without understanding aspect ratio mismatch. Object-fit only matters when the box and image have different proportions.
- Using images as layout tools. For layout spacing and structure, use semantic elements (Sections, Divs, Flexbox). Images are for content.
Learn more¶
- MDN: object-fit — detailed reference
- MDN: object-position — positioning reference
- MDN: img element — image best practices
- MDN: Alt text — accessibility guidelines
- The box model — width and height for media elements
- Flexbox layout — arranging media in galleries
Advanced: replaced elements and how Silex handles them
Media elements (img, video, iframe, embed, audio, canvas) are called "replaced elements" in CSS. Unlike normal HTML elements, their appearance is determined by external content (the image file, video stream, etc.) rather than CSS boxes.
In Silex, images cannot be converted to links via the Tag Name selector. The image component removes the href and tag-name traits. If you want a clickable image, wrap it in a Link element instead.
The Object section (with object-fit and object-position properties) appears only when a replaced element is selected. This is done by registering the Object sector to show only for img, video, iframe, embed, audio, and canvas elements.
When you upload images via the Asset Manager, Silex converts URLs to a stored format internally and back to displayable URLs on the canvas — this is transparent to you.
Reference: Object-Fit and Object-Position values
Object-Fit values¶
| Value | Effect |
|---|---|
fill |
Stretches/squeezes the content to fill the box. Aspect ratio may not be preserved. |
contain |
Scales the content to fit inside the box. Preserves aspect ratio. May letterbox. |
cover |
Scales the content to cover the entire box. Preserves aspect ratio. May crop. |
none |
Content keeps its natural size. May overflow or leave space. |
scale-down |
Uses whichever is smaller: none or contain. |
initial |
Resets to CSS default (fill). |
inherit |
Uses the parent element's value. |
Object-Position values¶
| Position | Anchors to |
|---|---|
left top |
Top-left corner (0% 0%) |
left center |
Left edge, vertically centered (0% 50%) |
left bottom |
Bottom-left corner (0% 100%) |
center top |
Top edge, horizontally centered (50% 0%) |
center center |
Dead center (50% 50%, default) |
center bottom |
Bottom edge, horizontally centered (50% 100%) |
right top |
Top-right corner (100% 0%) |
right center |
Right edge, vertically centered (100% 50%) |
right bottom |
Bottom-right corner (100% 100%) |
initial |
Resets to CSS default (50% 50%) |
inherit |
Uses parent element's value |
unset |
Removes any set value |
Use these together: cover with center top crops the bottom, keeping the top visible.
Quiz¶
Q1: A company logo is in a tall sidebar and looks squished. What do you set?
- A) Object-fit to
fill - B) Object-fit to
contain - C) Width to 100%
Answer
B) Object-fit to contain — this scales the logo to fit without distortion. You may see empty space, but the aspect ratio is preserved.
Q2: A hero image has Object-fit: cover, but the subject (at the bottom) gets cropped. How do you fix it?
- A) Set Object-fit to
contain - B) Set Object-position to
center bottom - C) Increase the container height
Answer
B) Set Object-position to center bottom — the crop anchors to the bottom, keeping the subject visible.
Q3: A screen reader user visits your page. An image has no alt text. What happens?
- A) The screen reader reads the file name (IMG_4392.jpg)
- B) The screen reader skips it silently
- C) Either A or B depending on the screen reader
Answer
C) Either A or B depending on the screen reader — some read the file name, some skip it. Either way, add descriptive alt text so all visitors understand the image.
Q4: You want to embed a YouTube video. Which block should you use?
- A) Video block
- B) Map block or Custom code block
- C) Image block
Answer
B) Map block or Custom code block — the Video block is for self-hosted video files. Map block creates an iframe for embedded content.
Q5: Your 600px-wide image takes a long time to load. The original file is 5000px. What should you do?
- A) Use CSS to scale it down
- B) Set Object-fit to
scale-down - C) Resize the image to 1200px before uploading
Answer
C) Resize the image to 1200px before uploading — this cuts the file size dramatically. CSS scaling doesn't reduce the file size, it just displays it smaller.