You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/renbaoshuo/go-css-parser

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/renbaoshuo/go-css-parser

v0.0.9
Source
Go
Version published
Created
Source

Go CSS Parser

Installation

go get go.baoshuo.dev/cssparser

API

  • ParseStylesheet(content string, options ...ParserOption) (*Stylesheet, error)
    Parses a complete CSS stylesheet.
  • ParseDeclarations(content string, options ...ParserOption) ([]*Declaration, error)
    Parses CSS declarations, typically used for inline styles.

Here are the available options for the parser:

  • WithInline(bool)
    Whether to parse inline styles.
  • WithLooseParsing(bool)
    Whether to allow loose parsing, which is more permissive and allows for some errors in the CSS syntax.

Usage

package main

import "go.baoshuo.dev/cssparser"

func main() {
  // Parse CSS declarations (e.g., from style attribute)
  declarations, err := cssparser.ParseDeclarations(`
    color: red;
    font-size: 16px;
  `)

  // Parse CSS stylesheet (e.g., from a <style> tag)
  stylesheet, err := cssparser.ParseStylesheet(`
    .example {
      color: blue;
      font-size: 14px;
    }
  `)
}

Credits

  • https://github.com/tdewolff/parse
  • https://github.com/aymerick/douceur
  • https://github.com/csstree/csstree

Author

go-css-parser © Baoshuo, Released under the MIT License.

Personal Homepage · Blog · GitHub @renbaoshuo

FAQs

Package last updated on 21 Jul 2025

Did you know?

Socket

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.

Install

Related posts