HTML Strip Attributes (VS Code Extension)
HTML Strip Attributes is a lightweight and configurable VS Code extension that removes attributes from HTML tags — giving you precise control over what gets nuked and what stays.
You can:
- Completely skip stripping on specific tag names
- Preserve certain attributes (globally or per tag)
- Or go full chaos-mode and strip only a specific set of attributes
✅ Features
- ✂️ Strip all attributes by default
- 🧩 Use
excludedTags
to completely skip certain tags (e.g., <img>
)
- 🧠 Use
ignoredAttributes
to preserve certain attributes, globally or per tag
- 🎯 Use
stripOnlyAttributes
to remove only a defined set of attributes (e.g., just class
and style
)
- 🛠️ Process entire files with one command
🔧 Example
<a href="https://example.com" class="btn" role="link" title="click me">Link</a>
<img src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/cat.jpg" alt="A cat" class="img">
<video src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/movie.mp4" class="media"></video>
Using ignoredAttributes
:
"htmlAttributeStripper.excludedTags": ["img"],
"htmlAttributeStripper.ignoredAttributes": {
"*": ["src"],
"a": ["href", "title"],
"img": ["alt", "src"]
}
Output:
<a href="https://example.com" title="click me">Link</a>
<img src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/cat.jpg" alt="A cat" class="img">
<video src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/movie.mp4"></video>
Using stripOnlyAttributes
:
"htmlAttributeStripper.stripOnlyAttributes": ["class", "style"]
Output:
<a href="https://example.com" role="link" title="click me">Link</a>
<img src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/cat.jpg" alt="A cat">
<video src="https://github.com/coffeepostal/html-strip-attributes/raw/HEAD/movie.mp4"></video>
⚠️ About Conflicts Between Settings
If stripOnlyAttributes
is used, it takes precedence and overrides ignoredAttributes
.
This means:
- The extension will only remove attributes listed in
stripOnlyAttributes
- All other attributes will be preserved
ignoredAttributes
is ignored in this mode — as expected
⚙️ Configuration
Add this to your settings.json
:
"htmlAttributeStripper.excludedTags": ["img"],
"htmlAttributeStripper.ignoredAttributes": {
"*": ["src"],
"a": ["href", "title"],
"img": ["alt", "src"]
},
"htmlAttributeStripper.stripOnlyAttributes": []
🚀 Usage
- Open any HTML/XML file
- Run the command:
Strip HTML Attributes
from the Command Palette (Cmd+Shift+P
/ Ctrl+Shift+P
)
🧑💻 Author
Created by Adam Farnsworth
Published under the farnsco
namespace
GitHub Repo
📄 License
MIT — see LICENSE file.