npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hint/hint-meta-theme-color

v4.0.23

Published

hint for best practices related to the 'theme-color' meta tag

Downloads

287

Readme

Valid theme-color (meta-theme-color)

meta-theme-color hint checks if a single theme-color meta tag is specified in the <head> with a valid value supported by all user agents.

Why is this important?

The theme-color meta tag provides a way to suggest a color that browsers should use to customize the display of the page or of the surrounding user interface. For example, browsers might use the color for the page's title bar or use it as a color highlight in a tab bar or task switcher.

In the context of progressive web apps, for a more app-like feel, providing a theme color is essential.

Here is an example of browser UI when the theme-color meta tag is not specified and when it is:

Browser UI when the theme-color meta tag is not specified   Browser UI when the theme-color meta tag is specified

Note that:

  • While the specification defines that the theme color can be any valid CSS color:

    • Values such as hex with alpha are not supported everywhere theme-color is.

    • Browsers that supported rgba, hsla, or hex with alpha values will ignore the alpha value.

  • Always specify the theme color using the meta tag. Even though it can also be declared in the web app manifest file:

    • Browsers only acknowledge the value from the web app manifest file once the user has added the page to their home screen.

    • The theme-color meta tag overwrites the value specified in the web app manifest file so it allows for better individual page level customization.

What does the hint check?

The hint checks if a single theme-color meta tag is specified in the <head> and the value of its content attribute is a valid CSS color supported by all the targeted browsers.

Examples that trigger the hint

The theme-color meta tag is not specified:

<!doctype html>
<html lang="en">
    <head>
        <title>example</title>
        ...
    </head>
    <body>...</body>
</html>

The theme-color meta tag is wrongly specified as <space>theme-color:

<meta name=" theme-color" content="#f00">

The theme-color meta tag is specified with an invalid value:

<meta name="theme-color" content="invalid">
<meta name="theme-color" content="currentcolor">

The theme-color meta tag is specified with a value that is not supported by all the targeted browsers (e.g.: Samsung Internet v5 is targeted).

<meta name="theme-color" content="#f00a">
<meta name="theme-color" content="#ff0000aa">

The theme-color meta tag is not specified in the <head>:

<!doctype html>
<html lang="en">
    <head>
        <title>example</title>
        ...
    </head>
    <body>
        <meta name="theme-color" content="#f00">
        ...
    </body>
</html>

Multiple theme-color meta tags are specified:

<!doctype html>
<html lang="en">
    <head>
        <title>example</title>
        <meta name="theme-color" content="#f00">
        <meta name="theme-color" content="#f0f">
        ...
    </head>
    <body>...</body>
</html>

Examples that pass the hint

A single theme-color meta tag is specified in the <head> and the value of its content attribute is a valid CSS color supported by all the targeted browsers.

<!doctype html>
<html lang="en">
    <head>
        <title>example</title>
        <meta name="theme-color" content="#f00">
        ...
    </head>
    <body>...</body>
</html>

The content attribute value can be specified as:

  • a color name

    • <meta name="theme-color" content="red">
  • hex using 3 or 6 digits

    • <meta name="theme-color" content="#f00">
    • <meta name="theme-color" content="#ff0000">
  • hsl / hsla

    • <meta name="theme-color" content="hsl(0, 50%, 50%)">
    • <meta name="theme-color" content="hsla(0, 50%, 50%, 1)">
  • rgb / rgba

    • <meta name="theme-color" content="rgb(255, 0, 0)">
    • <meta name="theme-color" content="rgba(255, 0, 0, 1)">

And, depending on the targeted browsers:

  • hex using 4 or 8 digits

    • <meta name="theme-color" content="#f000">
    • <meta name="theme-color" content="#ff000000">

How to use this hint?

To use it you will have to install it via npm:

npm install @hint/hint-meta-theme-color --save-dev

Note: The recommended way of running webhint is as a devDependency of your project.

And then activate it via the .hintrc configuration file:

{
    "connector": {...},
    "formatters": [...],
    "hints": {
        "meta-theme-color": "error",
        ...
    },
    "parsers": [...],
    ...
}

Further Reading