Skip to content
Projets

À propos

CSS Intellisense for HTML

Développement web et applicatif

Comment ces chiffres sont mesurés

What you can do

  • Completion for class and id attributes, with the CSS rule shown as documentation
  • Picks up stylesheets linked or written inline in the current file, local or remote
  • Global stylesheets and CSS frameworks via style_sheets
  • Hover, go to definition, and peek (open the CSS rule in a floating window)

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

☕ Neovim HTML & CSS Support

CSS IntelliSense for HTML

image

✨ Features

  • Completion for class and id attributes, with the CSS rule shown as documentation
  • Picks up stylesheets linked or written inline in the current file, local or remote
  • Global stylesheets and CSS frameworks via style_sheets
  • Hover, go to definition, and peek (open the CSS rule in a floating window)
  • Per-project config through .nvim.lua

Works with any completion engine that reads LSP results (nvim-cmp with cmp-nvim-lsp, blink.cmp's lsp source, built-in completion). The plugin runs a small in-process LSP called html-css-lsp.

⚡️ Requirements

  • Neovim 0.10+
  • curl (for remote stylesheets)
  • Treesitter parsers: html and css, plus tsx / javascript if you use JSX

📦 Installation

vim.pack

vim.pack.add({ "https://github.com/Jezda1337/nvim-html-css" })

require("html-css").setup({
  enable_on = { "html" }, -- file extensions
})

lazy.nvim

{
  "Jezda1337/nvim-html-css",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  main = "html-css",
  opts = {
    enable_on = { "html" }, -- file extensions
  },
}

Don't lazy-load it with ft or event: the file that triggers loading won't get completion until you reopen it.

enable_on takes file extensions, not filetypes. For example: "html", "vue", "svelte", "astro", "tsx", "jsx", "php" (includes Blade), "erb", "templ", "tmpl", "gohtml". Django templates are usually .html.

🎨 Where styles come from

  • Automatically: stylesheets linked or written inline in the file you're editing. These only apply to that file.
  • style_sheets: anything else, such as a global main.css or a framework your bundler includes. These apply to every enabled file.
style_sheets = {
  "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
  "./src/styles/main.css", -- relative to the folder you started nvim in
}

@imports inside local stylesheets are followed.

🔧 Per-project config

Put a .nvim.lua in the folder you start nvim from:

vim.g.html_css = {
  style_sheets = { "./src/styles/main.css" },
}

The first time, Neovim asks whether to trust the file (:trust to allow it). Values here override your global setup.

⌨️ Hover, definition and peek

The plugin doesn't map any keys itself, but some things work out of the box through Neovim's LSP defaults (0.10+):

  • Hover: K
  • Go to definition: <C-]> gd is not an LSP default in Neovim (it's Vim's built-in "go to local declaration"). To use gd, or to set your own hover key, use handlers:
handlers = {
  hover = { bind = "K" },
  definition = { bind = "gd" },
}

These keymaps only apply in enabled files. If the word under the cursor isn't a known class or id, they fall back to your other LSP servers' hover and definition.

Peek opens the CSS rule in an editable floating window. It has no default key, so map the :HtmlCssPeek command yourself:

vim.keymap.set("n", "<leader>cp", "<cmd>HtmlCssPeek<CR>", { desc = "Peek CSS" })

Close it with q or <Esc>. It won't close while it has unsaved changes.

⚙️ All options

require("html-css").setup({
  enable_on = { "html" },  -- file extensions
  style_sheets = {},       -- extra stylesheets (URLs or paths)
  handlers = {},           -- e.g. { hover = { bind = "K" }, definition = { bind = "gd" } }
                           -- hover also takes: wrap, border, position ("cursor" | "editor")
  peek = {
    enabled = true,        -- creates :HtmlCssPeek
    border = "rounded",
    position = "center",   -- "center" | "cursor"
    width = 0.5,           -- fraction of the editor
    height = 0.5,
    focus = true,          -- move the cursor into the float
    style = "minimal",
  },
  notify = false,          -- log fetches (debugging)
})

Run :checkhealth html-css if something doesn't work.

Explorer des projets similaires

Chargement…