Access text color

Hi,
How can I access the text color? I try to write code that uses this property.
Thx

Hi Shay,

The answer is no, but you can use the site text colors.
Wix Text Element has two properties to read and write it’s content - the text property and the html property.

The html property supports a subset of html that is using the Text Themes from the site. So in order to input text that uses the Text Theme of Large Heading, for instance, you can use the h4 HTML element.
e.g.

$w('#text').html = "<h4>I'm a site header</h4>"

will render on the site using the Large Heading text theme.

You can also change the text color directly using the CSS property color. For instance, if we want to have the words site header in green we can use

$w('#text').html = "<h4>I'm a <span style='color: green'>site header</span></h4>"

If this does not answer what you need, please let me know the exact use-case (what you are trying to achieve) and will try to answer for that.

Hi Yoav,
I’d like to know the color of text for 2 reasons:

  1. To calculate contrast between text color and background color.
  2. Dynamically change the color.
    Is it accessible ?

Shay, let me understand first the need,

Wix is built to design while in the editor, using our drag and drop interface and pixel perfect tools. Using the editor, you set the background color and text theme colors. So in fact, once you update text using the $w API, you know both colors (as you have selected them in the editor).

If you wanna change text color dynamically, you can do so using the style=‘color’ property as above.

At this time, we do not have the ability to read the background color or text theme colors. However, given a good use-case, we may add such interfaces. Can you elaborate why using themes and the color property is not sufficient? I think I am missing what you are trying to achieve.

It sounds like Shay is trying to bake some accessibility features into the site (such as high contrast, for example). Am I right, Shay?

Yes Uval you are totally right.
I understood that color feature of background, shape, strip etc. are not exposed yet - hope they will be in the future:)

It would’t hurt if you also submit a request in the “feature request” section. :slight_smile:
And… because everyone here is under NDA, I can also share with you that there’s a big set of accessibility features coming into the editor very soon, so stay tuned for that as well. I’m not sure it will cover your desire for runtime calculation of contrast, but there are many other accessibility pieces that will fall into place.