Skip to content

[Proposed Solution] Image alignment via alt text broken in Obsidian v1.12.4+ #708

@Mug521

Description

@Mug521

Image alignment via alt text (supported by the theme, e.g., |L, |R, |C) stopped working after the Obsidian 1.12.4 update. This caused images in the vault to become misaligned.

I've adapted a solution originally discussed in this Obsidian Forum thread and modified it to include left and right alignment as well: https://forum.obsidian.md/t/image-centring-css-broken-as-of-v1-12-4/111707/2

This suggested fix restores alignment support for:

  • Left: by using |L or |l
  • Right: by using |R or |r
  • Center: by using |C or |c

The following CSS has been tested and works both in Live Preview and Reading Mode. I’m proposing this for potential implementation to make image alignment via alt text functional again from within the theme, without the need for external snippets.

/* LEFT */
img:is([alt="L" i], [alt^="L|" i]),
.cm-content .image-embed:is([alt="L" i], [alt^="L|" i]) {
  display: block;
  margin-left: 0 !important;
  margin-right: auto;
}

/* RIGHT */
img:is([alt="R" i], [alt^="R|" i]),
.cm-content .image-embed:is([alt="R" i], [alt^="R|" i]) {
  display: block;
  margin-left: auto;
  margin-right: 0 !important;
}

/* CENTER */
img:is([alt="C" i], [alt^="C|" i]),
.cm-content .image-embed:is([alt="C" i], [alt^="C|" i]) {
  display: block;
  margin-inline: auto !important;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions