Captures the user’s attention and communicate your message
Use for images with no responsive qualities.
Apply rules to an image using ratio and crop properties. The below example is cropped using top alignment with the aspect ratio set as 9:16.
Use the cover property to resize the background image to fill the entire container.
To use cover or crop properties without a defined aspect ratio, set ratio="auto"
and give the image an explicit height and/or width. This can be done in several ways:
height
or min-height
to the CdrImg element directlyheight: 100%
to the CdrImg element to have it take up the full height of it's container (which must also have a height defined through some means)Apply a radius to an image.
The below example is cropped using center alignment with the aspect ratio set as square and the radius set as rounded.
The below example is cropped using center alignment with the aspect ratio set as square and the radius set as circle.
CdrImg will bind any event handlers to the img
element that it wraps. This is intended to support attaching an error handler function in case an image does not load, but can be used for any HTML/JS event. Note that because images are usually not "interactive" elements you should not bind click handlers to them.
<cdr-img
src=""
@error="eventHandler"
/>
The CdrImg component accepts any valid HTML img
attribute. CdrImg works with native lazy loading (opens new window) by setting the loading
attribute.
To ensure that usage of this component complies with accessibility guidelines, provide descriptive text for alt
attribute for:
This component has compliance with WCAG guidelines by:
alt
attribute into the image element by defaultalt
attribute is needed to meet accessibility requirements for decorative imagesREI image requirements are described on the Launch and DefaultShop Image Sizes (opens new window) page.
Use conventional aspect ratios:
Images are cropped on y-axis with top value and on x-axis with left, x-center, and right values
Images are cropped on y-axis with y-center value and on x-axis with left, x-center, and right values
Images are cropped on y-axis with bottom value and on x-axis with left, x-center, and right values
<img>
element, add:
alt
attributerole="presentation"
alt
attributealt
attribute should contain the same words that appear in the imagealt
attribute to only one image for the entire groupalt
attributealt
attribute that describes the purpose or destination of the linksrcet
and sizes
attributes can be used to control which image loads at which screeen sizeThis component will bind any attribute that a native HTML img element (opens new window) accepts.
alt
name
string
type
empty
default
Sets the alternate text attribute for the image. Default value is empty.
src
name
string
type
empty
default
Sets image source URL.
ratio
name
string
type
N/A
default
Sets the aspect ratio and scales the image as large as possible without cropping or stretching the image. Possible values: { 'auto' | 'square' | '1-2' | '2-3' | '3-4' | '9-16' | '2-1' | '3-2' | '4-3' | '16-9' }
crop
name
string
type
N/A
default
Requires ‘ratio’ to define the starting position for cropping image. Image will overflow and not be displayed. Possible values: { ‘left’ | ‘x-center’ | ‘right’ | ‘top’ | ‘y-center’ | ‘bottom’ }
cover
name
boolean
type
N/A
default
Requires ‘ratio’ to scale the image to be as large as possible to fill the entire background area.
radius
name
string
type
N/A
default
Sets a border radius to the root element. Possible values: { 'circle' | ‘rounded’ }
modifier
name
string
type
N/A
default
Modifies the style variant for this component. Possible value: { ‘responsive’ }
containerClass
name
string
type
N/A
default
VUE 3 ONLY - Add a custom class to the `cdr-img-ratio` container div
Find more information about using Slots in the article Installing Cedar.
default
name
Set the innerHTML for CdrImg. This includes text and html markup.
contain
which resizes the background image to make sure it is fully visiblecover
propertycrop
propertycover
and crop
properties togetherratio
propertyratio
propertycrop=”top left”
):
left
: Orients the image to its horizontal leftright
: Orients the image to its horizontal rightx-center
: Orients the image to its horizontal centertop
: Orients the image to its topbottom
: Orients the image to its bottomy-center
: Orients the image to its vertical centercircle
or rounded
(for rounded rectangle)cdr-core.css
Following variants are available to the cdr-img
modifier attribute:
Value | Description |
---|---|
'responsive' | Sets the image to display block and 100% width |
For internal applications with large images or images that would benefit from changes due to platform or breakpoint, use the loading="lazy"
property to lazy load the images. The srcset
and sizes
properties can also be used to load the optimal image size for the user's screen. CdrImg supports any attribute that a native img
element accepts, see the MDN img docs (opens new window) for more information on the loading
, srcset
, sizes
, and other properties.