{"record":{"id":"c0d0a76323d24142","repo":"Textualize/textual","slug":"invalid-percentage-value-token","errorCode":null,"errorMessage":"invalid percentage value '{token}'","messagePattern":"invalid percentage value '(.+?)'","errorType":"validation","errorClass":"StyleValueError","httpStatus":null,"severity":"error","filePath":"src/textual/css/_style_properties.py","lineNumber":1011,"sourceCode":"        Raises:\n            ColorParseError: When the color string is invalid.\n        \"\"\"\n        _rich_traceback_omit = True\n        if color is None:\n            if obj.clear_rule(self.name):\n                obj.refresh(children=True)\n        elif isinstance(color, Color):\n            if obj.set_rule(self.name, color):\n                obj.refresh(children=True)\n        elif isinstance(color, str):\n            alpha = 1.0\n            parsed_color = Color(255, 255, 255)\n            for token in color.split():\n                if token.endswith(\"%\"):\n                    try:\n                        alpha = percentage_string_to_float(token)\n                    except ValueError:\n                        raise StyleValueError(f\"invalid percentage value '{token}'\")\n                    continue\n                try:\n                    parsed_color = Color.parse(token)\n                except ColorParseError as error:\n                    raise StyleValueError(\n                        f\"Invalid color value '{token}'\",\n                        help_text=color_property_help_text(\n                            self.name, context=\"inline\", error=error, value=token\n                        ),\n                    )\n            parsed_color = parsed_color.multiply_alpha(alpha)\n\n            if obj.set_rule(self.name, parsed_color):\n                obj.refresh(children=True)\n        else:\n            raise StyleValueError(f\"Invalid color value {color}\")\n\n","sourceCodeStart":993,"sourceCodeEnd":1029,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/_style_properties.py#L993-L1029","documentation":"ColorProperty accepts color strings that may include a percentage alpha token like `rgb(255,0,0) 50%`. When the percentage token cannot be parsed as a percentage (percentage_string_to_float raises ValueError), this StyleValueError names the offending token. Only simple integer/float percentages are accepted.","triggerScenarios":"`styles.color = \"red 5O%\"` (letter O), `\"red 150 %%\"`, or `\"#ff0000 0.5%\"` where the percent component is malformed; also non-ASCII percent signs or whitespace inside the token.","commonSituations":"Typos in the percent sign, localized keyboards producing a full-width ％ character, or copy-pasted color strings from other formats.","solutions":["Fix the percentage token to a plain form like `50%`","If you meant opacity, ensure it is a number followed by a single ASCII % character"],"exampleFix":"# before\nstyles.color = \"red 5O%\"\n# after\nstyles.color = \"red 50%\"","handlingStrategy":"validation","validationCode":"import re\nif re.fullmatch(r\"\\d+(\\.\\d+)?%\", tok):\n    styles.color = f\"red {tok}\"","typeGuard":null,"tryCatchPattern":"try:\n    styles.color = value\nexcept StyleValueError as e:\n    log.warning(\"bad color: %s\", e)","preventionTips":["Use plain ASCII percent signs and simple numbers in alpha percentages"],"tags":["textual","css","color","percentage-parse"],"backgroundTag":"invalid-css-value","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}