Exploring color-contrast() for the first time.

Category Image 091

I saw in the release notes for Safari Technical Preview 122 that it has support for a color-contrast() function in CSS. Safari is first out of the gate here. As far as I know, no other browser supports this yet and I have no idea when stable Safari will ship it, or if any other browser ever will. But! It’s a very good idea! Any native tool to get us to ship more accessible interfaces (of which color contrast is a part) is cool by me. So let’s attempt to get it to work.

Anybody can download Safari Technical Preview, so I did that.

I had to ask around about this, but just because this is a pre-release browser, it doesn’t mean all these features are active by default. Just as Chrome Canary has feature flags you have to turn on, so does Safari Technical Preview. So, I had to flip it on like this:

The release notes don’t have any information about how to actually use color-contrast(), but fortunately web searching turns up a spec (it’s part of Color Module 5), and MDN has a page for it with very basic syntax information.

This is how I understand it:

That example above is a little silly, because it will always return white — that has the most contrast with black. This function actually gets useful when one or more of those color values is dynamic, meaning very likely it is a CSS custom property.

The function returns a color, so the top use-case, I would guess, is going to be setting a color based on a dynamic background. So…

section {
  background: var(--bg);
  color: color-contrast(var(--bg), white, black);
}

Now we can toss any color at all at --bg and we’ll either get white or black text, depending on what has the most contrast:

That’s extremely cool, even in the most basic use case.

Here’s a demo from Dave where he’s not just setting the text color in the parent, but the color of links as well, and the links have a different set of colors to choose from. Play with the HSL sliders (in Safari Technology Preview, of course) to see it work.

Just picking two colors that have enough contrast is easy enough (although you’d be surprised how often it’s screwed up by even those of us with good intentions). But oh wow does it get complicated quick with different situations, let alone having a bunch of color variations, or god forbid, arbitrary combinations.

Here’s a video of me playing with Dave’s tester so you can see how the colors update at different places.


The post Exploring color-contrast() for the first time. appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.

How to Properly Setup Video SEO in WordPress (Step by Step)

Wp Plugins

Do you want to learn how to do video SEO in WordPress?

Video SEO is the process of optimizing your videos to rank higher in search engines. This can help you get more traffic from your video content back to your WordPress website.

In this article, we’ll show you how you can set up a video sitemap in WordPress to improve your video SEO, step by step.

How to do video SEO in WordPress

What is Video SEO?

Video SEO is the process of optimizing the videos on your site, so they’ll rank higher in the search results pages.

This is similar to general WordPress SEO best practices except it’s geared towards your video content.

There’s a lot you can do to optimize your videos before you embed them in your WordPress blog posts, like choosing the best video hosting.

However, once they’re live on your website, you need to make sure they’re going to bring you maximum traffic.

The best way to do this is by adding a video sitemap to WordPress.

A video sitemap is an XML sitemap that has information about the video content on your site.

This can help you generate rich snippets that appear in the Google video search results, and increase your blog traffic across the board.

WordPress video SEO search results page

By creating a video sitemap, Google and other search engines will index your posts with the embedded video content. That way, your video can rank in the search engines and bring more traffic to your posts.

Note: if you use a third-party video host like YouTube, then your YouTube videos and embedded videos can both rank in the search results together.

If you regularly add videos in your posts and pages, then this is a must have feature.

A WordPress video sitemap plugin will automatically detect when a video is embedded in your blog content, and add that to the sitemap, so search engines like Google can prioritize it.

How to Setup Video SEO Sitemap in WordPress with AIOSEO

The best way to add video sitemaps to WordPress is with the All in One SEO plugin. It’s the best SEO plugin for WordPress used by over 2 million sites.

Google makes formatting these video sitemaps hard, but with the AIOSEO plugin it only takes a couple of clicks.

First thing you need to do is install and activate the plugin. For more details, see our guide on how to install a plugin in WordPress.

Note, there is a free version of All in One SEO available. But you need the premium version to enable and create video sitemaps.

After the plugin is activated, you’ll have a new All in One SEO menu item in your WordPress dashboard.

Navigate to All in One SEO » Sitemaps.

On the home screen, make sure that sitemaps are enabled. Click the ‘Enable Sitemap’ slider to turn on sitemaps.

AIOSEO enable sitemap

After that, select the ‘Video Sitemap’ menu option at the top of the screen.

Next, click the ‘Activate Video Sitemap’ button to enable the video sitemap module.

Activate video sitemap module

Once you’ve done that, you can view your video sitemap by clicking the ‘Open Video Sitemap’ button.

The index page will list all of your available video sitemaps.

Open video sitemap

When you click on the sitemap link, it’ll show the list of available video content.

Here we can our example WordPress video sitemap contains a list of all blog posts that have an embedded video.

Video sitemap video list

You can further configure your video sitemap settings in the ‘Video Sitemap Settings’ box.

The default settings will be enough for most WordPress blogs, however, you can adjust these depending on your video content needs.

The most common change webmasters make is adjusting the ‘Post Types’ and ‘Taxonomies’ settings.

For example, if you only want the embedded videos from your blog posts to appear in your sitemap, then uncheck the ‘Pages’ and ‘Attachments’ boxes in the ‘Post Types’ box.

Customize video sitemap post types

Make sure you click ‘Save Changes’ if you’ve made any changes to the settings here.

You’ve now successfully added video sitemaps to WordPress, which will improve your video SEO and help you get more traffic from the search engines.

You may also want to see our comparison of the best email marketing services and our expert picks of the 24 must have WordPress plugins for business websites.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Properly Setup Video SEO in WordPress (Step by Step) appeared first on WPBeginner.