A Visual Studio Code extension that converts HTML structure to CSS, LESS, or SCSS selectors. This extension helps you quickly generate CSS selectors from HTML markup, with support for BEM methodology and various optimization options.
- Convert HTML structure to CSS/LESS/SCSS selectors
- Support for BEM methodology
- Smart tag hiding when classes or IDs are present
- Sibling reduction for cleaner output
- Parent combination for better organization
- Support for clickable elements (hover, active, focus states)
- Configuration options for customization
- Support for multiple file extensions (.css, .less, .scss, .sass)
- Open Visual Studio Code
- Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X)
- Search for "HTML to CSS"
- Click Install
- Copy your HTML code to the clipboard
- Open a CSS/LESS/SCSS file in VS Code
- Place your cursor where you want to insert the converted code
- Press
Ctrl+Alt+V
(Windows/Linux) orCmd+Alt+V
(Mac) - The converted CSS/LESS/SCSS code will be inserted at the cursor position
The extension can be configured through VS Code settings:
{
"htmlToCss.hideTags": true, // Hide tag selectors if element has class or id
"htmlToCss.convertBEM": true, // Convert BEM classes to nested selectors
"htmlToCss.preappendHtml": false, // Add original HTML as a comment
"htmlToCss.reduceSiblings": true, // Combine identical sibling elements
"htmlToCss.combineParents": true // Combine identical parent elements
}
<div class="card">
<div class="card__header">
<h2 class="card__title">Title</h2>
</div>
<div class="card__body">
<p class="card__text">Content</p>
</div>
</div>
.card {}
.card__header {}
.card__title {}
.card__body {}
.card__text {}
.card {
&__header {}
&__title {}
&__body {}
&__text {}
}
When using SCSS or LESS, the extension automatically converts BEM classes to nested selectors using the &
parent selector.
The extension automatically adds hover, active, and focus states for clickable elements (a, button).
When an element has classes or IDs, the tag selector is hidden to reduce specificity.
Identical sibling elements are combined to reduce code duplication.
Similar parent elements are combined to improve code organization.
Contributions are welcome! Please feel free to submit a Pull Request.
This extension is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have suggestions, please file them in the GitHub issues.