# CSS snippet don't work in live preview mode

**URL:** <https://forum.obsidian.md/t/css-snippet-dont-work-in-live-preview-mode/38126>\
**Category:** Help\
**Tags:** custom-css, live-preview\
**Created:** [May 28, 2022, 1:09pm UTC](https://forum.obsidian.md/t/css-snippet-dont-work-in-live-preview-mode/38126 "2022-05-28T13:09:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PauLuke](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/p/898d66/32.png) [@PauLuke](https://forum.obsidian.md/u/PauLuke)\
**Post date:** [May 28, 2022, 1:09pm UTC](https://forum.obsidian.md/t/css-snippet-dont-work-in-live-preview-mode/38126/1 "2022-05-28T13:09:54Z")

</div>

I don’t know if my question is too silly, but I would like to know how to make a snippet work in live preview mode.

I’m trying to make this snippet I found on the internet, which centers images, work in live preview mode:

```auto
.centerImg img {
  display: block;
  margin: 0px auto;
}

```

In a note I put a code like this:

```auto
<span class='centerImg'>![[image.png|200]]</span>

```

But it only works in reading mode, otherwise the only thing I see is “![[image.png|200]]”.

---

<div class="post-metadata">

**Author:** ![PauLuke](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/p/898d66/32.png) [@PauLuke](https://forum.obsidian.md/u/PauLuke)\
**Post date:** [May 28, 2022, 1:15pm UTC](https://forum.obsidian.md/t/css-snippet-dont-work-in-live-preview-mode/38126/2 "2022-05-28T13:15:22Z")

</div>

I noticed how to do that!

I deleted what was before in the snippet file and put the following:

```auto
/*Center Image*/
img:is([alt*="ctr"], [alt*="center"]),
.image-embed[src*="#ctr"] .image-embed[alt*=ctr],
.image-embed[src*="#center"] .image-embed[alt*=center],
.imgctr img {
display: block;
margin-left: auto;
margin-right: auto;
}

```

And in the note I put:

![[image.png|center|200]]

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [August 26, 2022, 1:15pm UTC](https://forum.obsidian.md/t/css-snippet-dont-work-in-live-preview-mode/38126/3 "2022-08-26T13:15:28Z")

</div>

Closed on August 26, 2022, 1:15pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
