Skip to content

Add height / width attribute to images to avoid layout shifts #4853

@sapphi-red

Description

@sapphi-red

Is your feature request related to a problem? Please describe.

When using ![alt](img), height / width attributes are not set and browsers cannot avoid layout shifts caused by the image.

For example, when clicking the non-inherit badge on the right side of each header on https://deploy-preview-20471--vite-docs-main.netlify.app/config/dep-optimization-options.html, the image above the link is shown in the viewport after the image is loaded.

Describe the solution you'd like

Vitepress to generate height / width attributes for the images.

Describe alternatives you've considered

Add it manually by writing ![alt](link){height=100 width=200} or ![alt](link){style="aspect-ratio:2; width:100%"}

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildRelated to the build system

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions