Skip to content
| Marketplace
Sign in
Visual Studio Code>Linters>CSS Structure AnalyzerNew to Visual Studio Code? Get it now.
CSS Structure Analyzer

CSS Structure Analyzer

Noorakhyar

| (0) | Free
On-demand static CSS analysis using HTML, limited PHP and JavaScript class references to identify unused CSS candidates, duplicate styles, similar styles, and provide manual refactoring recommendations. Dynamic behavior requires manual review.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

🧩 CSS Structure Analyzer

On-demand CSS static analysis and manual refactoring guidance for Visual Studio Code.

Identify unused CSS candidates, exact duplicate declarations, and similar styles, while inspecting supported static class references in HTML, PHP, and JavaScript.

Version: 0.1.0 · Publisher: akhyaru · Distribution: VS Code extension (.vsix)

Source repository

🛡️ Safety first: This extension never executes a website, PHP, or JavaScript; it does not modify CSS automatically. Findings are candidates for human review, not definitive browser-runtime results.

Table of contents

  • Overview
  • Features
  • Supported languages and scope
  • How it works
  • Installation
  • Usage
  • Examples
  • Understanding the results
  • Development and testing
  • Limitations
  • FAQ
  • License and feedback

Overview

CSS Structure Analyzer helps developers inspect stylesheet structure directly from Visual Studio Code. The analysis runs only when requested and produces a report in the CSS Analyzer Output Channel and a navigable CSS Analyzer sidebar.

Capability Current behavior
Analysis mode On demand (not real-time)
Input .css, .html, .php, and .js within supported static patterns
CSS findings Unused candidates, exact duplicates, similar declarations
Guidance Manual refactoring suggestions with safety warnings
Results Summary, Output Channel, and expandable sidebar findings
Navigation Open CSS source locations from supported findings
Code changes Suggestion only; no automatic edits
Runtime verification Not performed

Features

A quick look at the features available in this release:

  • 🧹 Unused CSS candidates — identify class names that have no matching reference in the supported static source files, when the evidence is sufficient.
  • 🧩 Exact duplicate CSS — group CSS rules with identical property–value declarations, even when declaration order differs.
  • 🔍 Similar CSS detection — identify non-identical rules that share property–value declarations and view their similarity scores.
  • 💡 Refactoring recommendations — receive suggestions to review repeated styles, with warnings about CSS specificity and the cascade.
  • 📄 HTML class analysis — inspect supported static HTML class attributes while ignoring comments and some inactive contexts.
  • 🐘 PHP static coverage — inspect supported literal markup, output, and local includes without executing PHP.
  • 🟨 JavaScript static coverage — recognize selected literal DOM/class patterns without claiming to know runtime behavior.
  • 🧭 Navigable results — review an expandable VS Code sidebar, an Output Channel report, and available CSS source links.
  • ⚠️ Manual-review safeguards — report Not calculated when unused CSS cannot be assessed reliably from the available source.
  • 🔒 No automatic changes — analysis runs only on demand; the extension does not remove or rewrite your CSS.

1. 🔎 Unused CSS candidates

The extension compares CSS class names with class references found in supported static source content. When the available evidence is sufficiently complete, class names without references can be reported as unused candidates.

Important: A missing static reference does not prove that a class is unused at runtime. If source files are unreadable, markup is dynamic, or relevant behavior cannot be verified, the extension may report Unused CSS: Not calculated and Manual Review Required instead of giving a potentially misleading verdict.

2. 🧩 Exact duplicate CSS

Rules containing the same property-value declarations can be grouped as exact duplicates, including when declaration order differs. The comparison takes supported @media, @supports, and @layer contexts into account. Some rules with repeated declarations are excluded to avoid confusing fallback or cascade behavior with straightforward duplication.

3. 🔍 Similar CSS

The extension identifies non-identical CSS rules with overlapping property-value declarations. Results can include the selectors, a similarity score, and shared declarations. Similarity is based on declaration data—not proof of equivalent visual rendering.

4. 💡 Refactoring recommendations

For duplicate and similar declarations, the extension suggests areas worth reviewing, such as consolidating equivalent rules or extracting shared declarations. Recommendations include relevant context and cautionary information about specificity, source order, the cascade, !important, and CSS at-rules.

5. 🧠 Supported static HTML, PHP, and JavaScript references

  • 📄 HTML: Reads supported static class attributes; HTML comments and certain inactive contexts are excluded.
  • 🐘 PHP: Examines a limited subset of static markup, literal output, and statically resolvable local include/require references. PHP is never executed.
  • 🟨 JavaScript: Uses AST-based analysis for selected literal DOM/class patterns, including supported classList, querySelector, and class-assignment patterns. Runtime behavior, computed values, and unsupported syntax require manual review.

The presence of a recognizable class in PHP or JavaScript is evidence of a potential reference, not confirmation that the corresponding code executes.

6. 🧭 Traceable reports and source navigation

The Output Channel and sidebar provide file counts, detected CSS groups, similarity results, potential class references, refactoring suggestions, and notices explaining why certain conclusions remain inconclusive. Supported findings can provide navigation back to CSS declarations.

Supported languages and scope

Source Analyzed within the supported subset Not guaranteed
CSS (.css) Selectors, declarations, duplicate/similar rules, selected at-rule contexts Computed styles, full cascade equivalence, all CSS extensions
HTML (.html) Supported static class attributes Generated markup and DOM changes at runtime
PHP (.php) Selected static markup, literal strings/output, resolvable local includes Arbitrary conditions, loops, functions, server execution
JavaScript (.js) Selected literal and AST-based class-reference patterns Dynamic expression values, executed branches, actual DOM state

Not claimed as fully supported: JSX/TSX, React, Vue, Angular, server-side rendering, SCSS, LESS, Tailwind-specific analysis, or browser runtime coverage.

How it works

  1. Open one project folder in Visual Studio Code.
  2. Run CSS Analyzer: Run Analysis through the Command Palette or the extension's view action.
  3. The extension reads relevant files and parses supported static patterns.
  4. It gathers potential class references and analyzes CSS declarations.
  5. It checks whether unused CSS can be assessed reliably. If not, it reports Manual Review Required instead of guessing.
  6. Duplicate and similar CSS analysis can still produce findings independently of the unused-CSS eligibility decision.
  7. Review the report, open relevant CSS locations, and apply any edits manually after checking the website's behavior and appearance.

Installation

Install from a VSIX file

  1. Open a version of Visual Studio Code compatible with engines.vscode: ^1.116.0.
  2. Open Extensions (Ctrl + Shift + X).
  3. Select the ... menu and choose Install from VSIX....
  4. Select css-structure-analyzer-0.1.0.vsix.
  5. Confirm that CSS Structure Analyzer is listed as an installed extension.

You do not need a Marketplace listing to install a local .vsix package.

Build and run from source

Requirements: Node.js, npm, and a compatible Visual Studio Code installation.

git clone https://github.com/Akhyaru/css-structure-analyzer.git
cd css-structure-analyzer
npm install
npm run compile

Open the repository folder in VS Code, then use the Run Extension launch configuration (F5) to start the Extension Development Host.

Build the VSIX package

npx @vscode/vsce package

The packaging command runs the prepublish compile script. The resulting VSIX filename follows the version in package.json.

Usage

  1. Open the project with File → Open Folder....
  2. Press Ctrl + Shift + P.
  3. Run CSS Analyzer: Run Analysis.
  4. Open View → Output, then select the CSS Analyzer channel.
  5. Open the CSS Analyzer sidebar to inspect grouped findings and available source-navigation actions.
  6. Read any warnings, verify runtime behavior independently, and make refactoring changes manually.

Testing tip: Open one fixture directory as the workspace. Opening the entire test collection can mix unrelated sample findings.

Examples

Example A — Static HTML and CSS

style.css:

.card { padding: 16px; color: [#222](https://github.com/Akhyaru/css-structure-analyzer/issues/222); }
.box { color: [#222](https://github.com/Akhyaru/css-structure-analyzer/issues/222); padding: 16px; }
.unused-test { display: none; }

index.html:

<!doctype html>
<html lang="en">
  <head><link rel="stylesheet" href="style.css"></head>
  <body>
    <div class="card">Card</div>
    <div class="box">Box</div>
  </body>
</html>

Possible findings, provided the unused-CSS eligibility checks pass:

  • 🧹 .unused-test is an unused CSS candidate.
  • 🧩 .card and .box form an exact duplicate group, since they contain the same declarations.
  • 💡 The extension can suggest reviewing consolidation of the rules, but it does not edit them.

Example B — HTML, CSS, PHP, and JavaScript together

In a mixed-language project, the analyzer may recognize potential PHP and JavaScript class references while still declining to determine whether those classes are used at runtime.

Illustrative report excerpt (not a fixed output for every project):

Analysis Summary: Manual Review Required
PHP coverage: Supported subset
JavaScript coverage: Supported subset
Unused CSS: Not calculated
Duplicate CSS groups: 1
Refactoring recommendations: 1

This is intentional: duplicate/similar CSS analysis is separate from runtime-dependent unused-CSS confidence.

Understanding the results

Label What it means What to do
Completed Supported analysis completed for this scenario Review candidates before changing code
Manual Review Required Relevant behavior or source content cannot be resolved statically Inspect dynamic code, templates, and runtime usage
Unused CSS: Not calculated The evidence is insufficient for an unused-CSS assessment Do not delete CSS based only on missing static references
Duplicate CSS groups: N N exact-duplicate groups were identified Review context and cascade before merging
Similar CSS pairs: N N potentially similar rule pairs were identified Consider shared declarations carefully

Development and testing

The repository includes regression tests for CSS analysis, PHP parsing, JavaScript parsing, static coverage, and cross-language integration.

npm run compile
npm run lint
node --test out/regression/analysis.regression.js
node --test out/regression/php.regression.js
node --test out/regression/phpA5.regression.js
node --test out/regression/js.regression.js
node --test out/regression/js3.regression.js
node --test out/regression/j4.integration.regression.js
  • src/test/ contains test fixtures.
  • manual-tests/ contains sample workspaces for manual integration checks.
  • Passing regression tests is useful evidence, not a guarantee for every real-world project.

Project structure

css-structure-analyzer/
├── src/
│   ├── analyze/       # Unused, duplicate, similarity, eligibility, recommendations
│   ├── parser/        # CSS, HTML, PHP, JavaScript, and coverage analysis
│   ├── regression/    # Regression tests
│   ├── test/          # Test fixtures
│   ├── utils/         # Navigation helpers
│   ├── views/         # Results sidebar
│   └── extension.ts   # VS Code command and integration
├── manual-tests/      # Manual test scenarios
├── media/             # Extension assets
└── package.json

Limitations

  1. On-demand static analysis only. The extension does not run a browser, execute PHP/JavaScript, monitor class changes, or collect runtime coverage.
  2. Unused CSS findings are candidates. Class-name presence does not prove a full selector matches the DOM, while missing references do not prove the class is absent at runtime.
  3. PHP is a restricted static subset. Dynamic expressions, conditions, loops, functions, and unresolved includes can require manual review.
  4. JavaScript is a restricted static subset. AST recognition does not determine whether code paths execute or what the live DOM contains.
  5. Incomplete source prevents confident unused assessment. Unreadable files or unsupported markup can result in Not calculated.
  6. CSS declaration equality is not rendering equivalence. var(...), shorthand/longhand combinations, fallback declarations, and complex cascade behavior can produce different computed results.
  7. Refactoring still requires manual CSS expertise. Inspect specificity, source order, !important, @media, @supports, and @layer before editing.
  8. No automatic fixes. The extension does not delete, rewrite, or merge CSS on the user's behalf.
  9. No performance guarantee. Detecting unused or duplicate code does not, on its own, establish improvements to Core Web Vitals.

FAQ

Is unused CSS detected in real time?

No. Analysis starts when you request it (on demand).

Why might unused CSS be unavailable when JavaScript is present?

Class names may be added or removed at runtime. The JavaScript analyzer recognizes selected potential static references, not every possible DOM state, so it may require manual review.

Does the extension fully support PHP and JavaScript?

No. Only the documented static subsets are examined. Neither language is executed.

Can duplicate CSS still be detected when unused CSS is not calculated?

Yes. Duplicate and similarity checks are independent of the unused-CSS eligibility decision.

Will the extension automatically refactor my CSS?

No. All suggestions require developer review and manual implementation.

Are React, Vue, Angular, SCSS, LESS, and Tailwind supported?

Not as verified full analysis targets in this version. The documented scope covers CSS and selected static class references in plain HTML, PHP, and JavaScript.

Can I install it without publishing to the VS Code Marketplace?

Yes. Use Install from VSIX... to install a local .vsix package.

License and feedback

This extension was developed as an Informatics undergraduate project. Suggestions, bug reports, and additional test scenarios can be shared through the GitHub repository.

License status: No official license has been specified in this README. Do not assume MIT or another open-source license unless a valid LICENSE file is included.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft