
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
svelte-body
Advanced tools
Apply styles to the body in routes! Designed to work with Svelte Kit and Routify.
Currently in Svelte Kit and Routify, applying styles per page to the body doesn't work. You can't use :global(body)
since the style tags aren't removed and reapplied on route change. svelte-body
handles that for you. It's available as an action or component.
npm i svelte-body -D
This library is made for Svelte 5, if you'd like to use Svelte 3/4 checkout v1.
Just like in regular html you can apply classes with class=""
and styles with style=""
.
<script>
import { Body } from 'svelte-body';
</script>
<Body class="some classes" style="color: blue" />
Alternativley you can use a style object like so:
<script>
import { Body } from 'svelte-body';
const style = {
backgroundColor: 'violet',
color: 'white',
'--cool-css-prop': '😎',
};
</script>
<Body {style} />
We use clsx under the hood, which allows you to pass different shapes and only have truthy names applied as classes. Read me about it on their docs.
<script>
import { classList } from 'svelte-body';
let isBlue = $state(true);
</script>
<Body class="red green blue" />
<Body class={{ red: true, blue: isBlue }} />
<Body class={['red', isBlue && 'blue']} />
<Body class={['red', { blue: isBlue }]} />
We also provide a classList
and style
action, which can be used on <svelte:body />
(or any other element).
classList
<script>
import { classList } from 'svelte-body';
</script>
<svelte:body use:classList={"red green blue"} />
<svelte:body use:classList={{ red: true, blue: isBlue }} />
<svelte:body use:classList={['red', isBlue && 'blue']} />
<svelte:body use:classList={[ 'red', { blue: isBlue } ]} />
style
<script>
import { style } from 'svelte-body';
</script>
<svelte:body use:style={'background-color: blue;'} />
It can also take an object:
<script>
import { style } from 'svelte-body';
</script>
<svelte:body
use:style={{ backgroundColor: 'blue', '--cool-css-prop': '😎' }} />
FAQs
Apply styles to the body in routes! Designed to work with Svelte Kit and Routify.
The npm package svelte-body receives a total of 656 weekly downloads. As such, svelte-body popularity was classified as not popular.
We found that svelte-body demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.