
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
vue-safe-html
Advanced tools
A Vue directive which renders sanitised HTML dynamically. Zero dependencies, compatible with Vue versions 3 and 2, TypeScript-ready.
Note: This library is not XSS-safe, but only strips tags programmatically.
Install package:
npm install vue-safe-html
# OR
yarn add vue-safe-html
Use the plugin:
import Vue from 'vue';
import VueSafeHTML from 'vue-safe-html';
Vue.use(VueSafeHTML);
In your component:
<template>
<div v-safe-html="myUnsafeHTML">
</template>
export default {
computed: {
myUnsafeHTML() {
return '<script>oh my!</script> I am safe!';
}
}
}
Renders to:
<div>I am safe!</div>
Array of strings. Default: ['a', 'b', 'br', 'strong', 'i', 'em', 'mark', 'small', 'del', 'ins', 'sub', 'sup']
.
Customize the tags that are allowed to be rendered, either by providing new ones:
Vue.use(VueSafeHTML, {
allowedTags: ['marquee', 'blockquote'],
});
Or extending the default ones:
import VueSafeHTML, { allowedTags } from 'vue-safe-html';
Vue.use(VueSafeHTML, {
allowedTags: [...allowedTags, 'marquee', 'blockquote'],
});
If no tags are passed, all tags are stripped:
import VueSafeHTML from 'vue-safe-html';
Vue.use(VueSafeHTML, {
allowedTags: [],
});
It is also possible to provide custom allowed tags directly to the directive tag, using directive modifiers. This allows local override of the option:
<template>
<!-- only allow p and strong tags -->
<div v-safe-html.p.strong="myUnsafeHTML">
</template>
Array of strings. Default: []
Customize the tag attributes that are allowed to be rendered:
Vue.use(VueSafeHTML, {
allowedTags: ['a'],
allowedAttributes: ['title', 'class', 'href'],
});
### Nuxt
`vue-safe-html` is written as a Vue plugin so you can easily use it inside Nuxt by following [the Nuxt documentation](https://nuxtjs.org/docs/2.x/directory-structure/plugins#vue-plugins).
## License
[Do No Harm](./LICENSE)
FAQs
A Vue directive which renders sanitised HTML dynamically
The npm package vue-safe-html receives a total of 4,707 weekly downloads. As such, vue-safe-html popularity was classified as popular.
We found that vue-safe-html demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.