 +          if (outputCssNames) {
 +            nsAutoString nameToSerialize;
 +            serializeName = NS_RGBToColorName(color, nameToSerialize);
-+            if (serializeName)
++            if (serializeName) {
 +              aResult.Append(nameToSerialize);
++            }
++            else {
++              if (!PL_strcmp(colorOutputType, "hex")) {
++                forceHexSerialization = true;
++              }
++              else
++                aResult.AppendLiteral("rgb(");
++            }
++          }
++          else {
++            if (!PL_strcmp(colorOutputType, "hex")) {
++              forceHexSerialization = true;
++            }
 +            else
 +              aResult.AppendLiteral("rgb(");
 +          }
-+          else
-+            aResult.AppendLiteral("rgb(");
          }
  
 -        NS_NAMED_LITERAL_STRING(comma, ", ");
 +        if (!serializeName) {
-+          NS_NAMED_LITERAL_STRING(comma, ", ");
++          if (forceHexSerialization) {
++            nscolor color = GetColorValue();
++            aResult.Append('#');
++            aResult.AppendPrintf("%02x", NS_GET_R(color));
++            aResult.AppendPrintf("%02x", NS_GET_G(color));
++            aResult.AppendPrintf("%02x", NS_GET_B(color));
++          }
++          else {
++            NS_NAMED_LITERAL_STRING(comma, ", ");
  
 -        aResult.AppendInt(NS_GET_R(color), 10);
 -        aResult.Append(comma);

           color == NS_RGBA(0, 0, 0, 0)) {
         // Use the strictest match for 'transparent' so we do correct
         // round-tripping of all other rgba() values.
@@ -1397,31 +1404,42 @@ nsCSSValue::AppendToString(nsCSSProperty
         uint8_t a = NS_GET_A(color);
         bool showAlpha =
           (aSerialization == eNormalized && a < 255) ||

   }
   else if (IsNumericColorUnit(unit)) {
+    bool outputCssNames = false;
+    nsXPIDLCString colorOutputType;
+    nsresult rv;
+    nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
+    if (NS_SUCCEEDED(rv) && prefBranch) {
+      prefBranch->GetBoolPref("bluegriffon.css.colors.names.enabled", &outputCssNames);
+      prefBranch->GetCharPref("bluegriffon.css.colors.type", getter_Copies(colorOutputType));
+    }
+    bool serializeName = false;
+    bool forceHexSerialization = false;
+
     if (aSerialization == eNormalized ||
         unit == eCSSUnit_RGBColor ||
