You can use CSSPool for: Eliminating duplicate rules. Searching for rules. Adding or modifying rules and properties. require 'csspool' sac = CSS::SAC::Parser.new doc = sac.parse(DATA.read) doc.rules.each do |rule| puts rule.selector.to_css rule.properties.each do |property| p property end end __END__ h1 { background: red; }