Title: WP_Duotone::colord_parse_hsla_string
Published: August 8, 2023
Last modified: August 20, 2026

---

# WP_Duotone::colord_parse_hsla_string( string $input ): array|null

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Parses a valid HSL[A] CSS color function/string.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#description)󠁿

Direct port of colord’s parseHslaString function.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#parameters)󠁿

 `$input`stringrequired

The HSLA string to parse.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#return)󠁿

 array|null An array of RGBA values or null if the RGB string is invalid.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#source)󠁿

    ```php
    private static function colord_parse_hsla_string( $input ) {
    	// Functional syntax.
    	$is_match = preg_match(
    		'/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
    		$input,
    		$match
    	);

    	if ( ! $is_match ) {
    		// Whitespace syntax.
    		$is_match = preg_match(
    			'/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i',
    			$input,
    			$match
    		);
    	}

    	if ( ! $is_match ) {
    		return null;
    	}

    	/*
    	 * For some reason, preg_match doesn't include empty matches at the end
    	 * of the array, so we add them manually to make things easier later.
    	 */
    	for ( $i = 1; $i <= 6; $i++ ) {
    		if ( ! isset( $match[ $i ] ) ) {
    			$match[ $i ] = '';
    		}
    	}

    	$hsla = self::colord_clamp_hsla(
    		array(
    			'h' => self::colord_parse_hue( $match[1], $match[2] ),
    			's' => (float) $match[3],
    			'l' => (float) $match[4],
    			'a' => '' === $match[5] ? 1 : (float) $match[5] / ( $match[6] ? 100 : 1 ),
    		)
    	);

    	return self::colord_hsla_to_rgba( $hsla );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-duotone.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-duotone.php#L466)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-duotone.php#L466-L507)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Duotone::colord_clamp_hsla()](https://developer.wordpress.org/reference/classes/wp_duotone/colord_clamp_hsla/)`wp-includes/class-wp-duotone.php` |

Clamps an array of HSLA values.

  | 
| [WP_Duotone::colord_hsla_to_rgba()](https://developer.wordpress.org/reference/classes/wp_duotone/colord_hsla_to_rgba/)`wp-includes/class-wp-duotone.php` |

Converts an HSLA array to RGBA.

  | 
| [WP_Duotone::colord_parse_hue()](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hue/)`wp-includes/class-wp-duotone.php` |

Converts a hue value to degrees from 0 to 360 inclusive.

  |

| Used by | Description | 
| [WP_Duotone::colord_parse()](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse/)`wp-includes/class-wp-duotone.php` |

Tries to convert an incoming string into RGBA values.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_duotone/colord_parse_hsla_string/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_duotone%2Fcolord_parse_hsla_string%2F)
before being able to contribute a note or feedback.